Mac上Tomcat6的安装
步骤
从官方下载Tomcat6的二进制包。
在/Library中创建相应的目录,并解压至该目录下。
cd /Library mkdir Tomcat chown username Tomcat chgrp admin Tomcat cd Tomcat unzip ~/Download/apache-tomcat-6.0.35.zip ln -sfvh apache-tomcat-6.0.35 Home
- 编辑配置文件
Home/conf/server.xml中配置端口:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
Home/conf/tomcat-user.xml中配置Tomcat管理员账户:
<role rolename="manager"/>
<user username="admin" password="password" roles="standard,manager,admin"/>
手动启动
cd Home/bin rm *.bat chmod 750 *.sh ./startup.sh # 启动
./shutdown.sh # 停止
可访问http://localhost:8080看是否成功启动。
将Tomcat作为服务启动
由于我目前不需要在自己电脑上作为服务开启,故这部分正确性未知。
- 创建脚本$TOMCAT_HOME/bin/tomcat-launchd.sh
#!/bin/sh # # Wrapper for running Tomcat under launchd # Required because launchd needs a non-daemonizing process function shutdown() { $CATALINA_HOME/bin/shutdown.sh /bin/rm $CATALINA_PID } function wait_for_death() { while /bin/kill -0 $1 2> /dev/null ; do sleep 2 done } export CATALINA_PID=$CATALINA_HOME/logs/tomcat.pid $CATALINA_HOME/bin/startup.sh trap shutdown QUIT ABRT KILL ALRM TERM TSTP sleep 2 wait_for_death `cat $CATALINA_PID`
- 创建文件/Library/LaunchDaemon/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>Label</key> <string>org.apache.tomcat</string> <false/> <key>OnDemand</key> <false/> <key>RunAtLoad</key> <true/> <key>ProgramArguments</key> <array> <string>/Library/Tomcat/Home/bin/tomcat-launchd.sh</string> </array> <key>EnvironmentVariables</key> <dict> <key>CATALINA_HOME</key> <string>/Library/Tomcat/Home</string> <key>JAVA_OPTS</key> <string>-Djava.awt.headless=true</string> </dict> <key>StandardErrorPath</key> <string>/Library/Tomcat/Home/logs/tomcat-launchd.stderr</string> <key>StandardOutPath</key> <string>/Library/Tomcat/Home/logs/tomcat-launchd.stdout</string> <key>UserName</key> <string>_appserver</string> </dict> </plist>
加载启动进程
sudo launchctl load /Library/LaunchDaemon/org.apache.tomcat.plist
其中load处可以用子命令unload,stop,start代替。由于在作为服务启动时是以_appserver用户运行的,所以要确保文件的访问权限。
参考:
- http://code.google.com/p/gbif-providertoolkit/wiki/TomcatInstallationMacOSX
- http://code.google.com/p/gbif-providertoolkit/wiki/PermissionSettings
blog comments powered by Disqus