到http://tomcat.apache.org下載tomcat版,例如apache-tomcat-7.0.42.tar.gz
将apache-tomcat-7.0.42.tar.gz 解压缩到目标目录
执行
1 |
chmod a+x apache-tomcat-7.0.42/bin/*.sh |
设置管理用户密码:
编辑 apache-tomcat-7.0.42/conf/tomcat-users.xml , 加入
1 2 |
<role rolename="manager-gui"/> <user username="User" password="password" roles="manager-gui"/> |
設定好後執行 apache-tomcat-7.0.42/bin/startup.sh , 再使用browser連到http://localhost:8080, 如果可以看到以下画面, Tomcat Server的安裝算是初步完成
設定Launchd主要讓Mac OS X server啟動時, 也順便啟動Tomcat Server, Launchd有點類似Windows的NT Service使用Launchd來啟動Tomcat Server
1.到 apache-tomcat-7.0.42/bin/目錄下新增一個檔案 launchd_wrapper.sh, 內容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/bin/bash function shutdown() { date echo "Shutting down Tomcat" $CATALINA_HOME/bin/catalina.sh stop } date echo "Starting Tomcat Server" export CATALINA_PID=/tmp/$$ # Uncomment to increase Tomcat's maximum heap allocation # export JAVA_OPTS=-Xmx512M $JAVA_OPTS export JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=256m" export CATALINA_OPTS="-DHUDSON_HOME=/Users/admin/hudson" . $CATALINA_HOME/bin/catalina.sh start # Allow any signal which would kill a process to stop Tomcat trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP |
请注意 ,launchd_wrapper.sh要使用
1 |
chmod a+x launchd_wrapper.sh |
使其具有执行权限
2. 加入tomcat for Launchd 文件, 到/Library/LaunchDaemons目录使用
1 |
sudo touch tomcat.plist |
新增tomcat.plist
3. 使用
1 |
sudo vi tomcat.plist |
, 编辑tomcat.plist, 文件內容如下, 要注意的是/Users/admin为安装目录, 请改成你的目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Disabled</key> <false/><key>EnvironmentVariables</key><dict><key>CATALINA_HOME</key> <string>/Users/admin/Library/apache-tomcat-7.0.42</string> <key>JAVA_HOME</key> <string>/Library/Java/Home</string> </dict> <key>Label</key> <string>com.apache.tomcat</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/Users/admin/Library/apache-tomcat-7.0.42/bin/launchd_wrapper.sh</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>Tomcat</string> <key>StandardErrorPath</key> <string>/Users/admin/apache-tomcat-7.0.42/logs/launchd.stderr</string> <key>StandardOutPath</key> <string>/Users/admin/apache-tomcat-7.0.42/logs/launchd.stdout</string> <key>UserName</key> <string>root</string> </dict> </plist> |
4.手动测试Launchd
1 |
sudo launchctl load -w /Library/LauhchDaemons/tomcat.plist |
停止指令
1 |
sudo launchctl unload -w /Library/LaunchDaemons/tomcat.plist |
测试OK后, 下次重新开机Tomcat Server就会自己执行了.