如何在Mac OS X上启动时启动Apache Tomcat?

我观察到在OS X上没有安装tomcat的完整指南,包括将它设置为在启动时启动。

以下是快速指南:

但是我错过了如何使它作为真正的服务/守护进程运行的部分:在系统启动时,可以select使其重新启动,如果它崩溃。

这用于在端口8080上将tomcat安装为守护进程 ,但也可以通过使用防火墙redirect来启用端口80。 它在Mac OS 10.6上进行了testing,但也应该可以使用10.5。

编辑/opt/local/share/java/tomcat6/conf/server.xml并在<Connector .../>内部添加proxyport="80" URIEncoding="UTF-8"

要将端口 80 转发到8080,请运行以下命令并添加/bin/catalina.sh

 sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in 

为Java机器分配足够的内存 ,否则以后可能会遇到麻烦。 在/opt/local/share/java/tomcat6/conf/local.env里面

 export JAVA_JVM_VERSION=CurrentJDK export JAVA_OPTS="-Xmx3000M -Xms3000M -Djava.awt.headless=true -Duser.timezone=UTC" 

在我的例子中,我分配了〜3Gb或RAM,但是你可以适应这个,不pipe怎样,如果你在tomcat里运行hudson ,那么不要less于1GB。

作为服务运行

运行nano /Library/LaunchDaemons/org.apache.tomcat.plist并粘贴下面的代码:

 <?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>Label</key> <string>org.apache.tomcat</string> <key>ProgramArguments</key> <array> <string>/opt/local/share/java/tomcat6/bin/catalina.sh</string> <string>run</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> 

检查launchd是否检测到新的守护进程,如果不重新启动:(

 launchctl list|grep tomcat 

手动启动tomcat。

 launchctl start org.apache.tomcat 

如果状态不是- ,那么您有问题,应该调查它: launchctl log level debug并检查/var/log/system.log

您需要将tomcat注册为需要在启动时执行的项目。 在Mac OS上,这是由launchd( http://developer.apple.com/macosx/launchd.html )处理的。 我不知道launchd是否支持自动重新启动,否则你应该看看supervisord( http://supervisord.org/ )。

对于启动Snow Leopard,我在/ Library / LaunchDaemons中创build了一个plist文件/ plist文件将如下所示(下面修改为匹配您的目录)。 您可以通过发出“launchctl load org.macports.tomcat6.plist”或“launchctl unload org.macports.tomcat6.plist”来启动/停止testing服务。 一旦你有它的工作重新启动,以certificate自动启动。


 sh-3.2# more org.macports.tomcat6.plist <?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>Label</key><string>org.macports.tomcat6</string> <key>ProgramArguments</key> <array> <string>/opt/local/bin/daemondo</string> <string>--label=tomcat6</string> <string>--start-cmd</string> <string>/opt/local/bin/tomcatctl</string> <string>start</string> <string>;</string> <string>--pid=fileclean</string> <string>--pidfile</string> <string>/opt/local/share/java/tomcat6/logs/tomcat6.pid</string> </array> <key>Debug</key><false/> <key>Disabled</key><false/> <key>OnDemand</key><false/> <key>RunAtLoad></key><true/> </dict> </plist>