作者:FunBSD 最后更新:2005年1月26日 |
這篇文章是基于Linux寫的,F(xiàn)reeBSD上可以用ports安裝。
Tomcat從5.5開(kāi)始支持JDK1.5,并且內(nèi)置Eclipse JDT Java編譯,不需要JDK,只需JRE即可運(yùn)行。
當(dāng)然也可使用JDK或其他支持Apache Ant的Java編譯器。
如果使用JDK1.4,則需要安裝jakarta-tomcat-version-compat.tar.gz兼容包。
網(wǎng)址:http://jakarta.apache.org/tomcat/
下載:http://jakarta.apache.org/site/binindex.cgi
安裝:
groupadd tomcat -g 8009 useradd tomcat -u 8009 -g tomcat cd /home/pkg wget http://apache.justdn.org/jakarta/tomcat-5/v5.5.4/bin/jakarta-tomcat-5.5.4.tar.gz wget http://apache.freelamp.com/jakarta/tomcat-5/v5.5.4/bin/jakarta-tomcat-5.5.4-admin.tar.gz wget http://apache.justdn.org/jakarta/tomcat-5/v5.5.4/bin/jakarta-tomcat-5.5.4-compat.tar.gz cd /usr/local tar zxf /home/pkg/jakarta-tomcat-5.5.4.tar.gz tar zxf /home/pkg/jakarta-tomcat-5.5.4-admin.tar.gz tar zxf /home/pkg/jakarta-tomcat-5.5.4-compat.tar.gz mv jakarta-tomcat-5.5.4 tomcat cd tomcat/bin tar xfz jsvc.tar.gz cd jsvc-src sh support/buildconf.sh sh configure make cp jsvc .. |
添加虛擬主機(jī)(/usr/local/tomcat/conf/server.xml):
<GlobalNamingResources> <Service name="Catalina"> |
設(shè)置索引頁(yè)(/usr/local/tomcat/conf/web.xml):
<servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> |
設(shè)置用戶(/usr/local/tomcat/user/tomcat-users.xml):
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <tomcat-users> <role rolename="admin"/> <role rolename="manager"/> <user username="admin" password="adminpwd" roles="admin,manager"/> </tomcat-users> |
添加啟動(dòng)腳本(/etc/init.d/tomcat):
#!/bin/sh # chkconfig: 345 85 15 # description: Tomcat Start and Stop Utility JAVA_HOME=/usr/local/java CATALINA_HOME=/usr/local/tomcat TOMCAT_USER=tomcat TMP_DIR=/var/tmp OUTFILE=/var/log/tomcat/stdout.log ERRFILE=/var/log/tomcat/stderr.log JAVA_OPTS="-Xms256m -Xmx512m" CATALINA_OPTS= CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $CATALINA_HOME/bin/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar case "$1" in start) $CATALINA_HOME/bin/jsvc \ -Djava.endorsed.dirs=$CATALINA_HOME/common/endorsed \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Djava.io.tmpdir=$TMP_DIR \ -outfile $OUTFILE \ -errfile $ERRFILE \ $JAVA_OPTS \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap \ #-verbose \ #-debug \ ;; stop) PID=`cat /var/run/jsvc.pid` kill $PID ;; *) echo "Usage: $0 {start|stop}" exit 1;; esac |
設(shè)置相應(yīng)的目錄和權(quán)限:
mkdir -p /var/log/tomcat /home/funbsd/java chown -R tomcat:tomcat /usr/local/tomcat/user /usr/local/tomcat/work /home/funbsd/java chmod -R 755 /usr/local/tomcat/conf /etc/init.d/tomcat chkconfig --add tomcat |
啟動(dòng)服務(wù):
/etc/init.d/tomcat start |
測(cè)試:
http://java.funbsd.net:8080 |
JK2可以使Tomcat作為Apache的一個(gè)模塊來(lái)使用:
cd /home/pkg wget http://apache.justdn.org/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz tar zxf jakarta-tomcat-connectors-jk2-src-current.tar.gz cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2 ./configure --with-apxs2=/usr/local/apache/bin/apxs make cd ../build/jk2/apache2 /usr/local/apache/bin/apxs -n jk2 -i mod_jk2.so |
配置Apache(/usr/local/apache/conf/httpd.conf):
LoadModule jk2_module modules/mod_jk2.so DirectoryIndex index.jsp index.html index.html.var <VirtualHost *:80> ServerName java.funbsd.net ServerAdmin webmaster@funbsd.net DocumentRoot /home/funbsd/java </VirtualHost> |
配置JK2映射(/usr/local/apache/conf/workers2.properties):
#設(shè)置共享內(nèi)存 [shm] #定義worker #[status:status] [channel.socket:localhost:8009] [ajp13:localhost:8009] #定義uri映射 #[uri:/jkstatus/*] [uri:/*] #[uri:/servlets/*] |
重啟Apache:
/usr/local/apache/bin/apachectl restart |
測(cè)試:
http://java.funbsd.net |
GLIBC2.2/Linux2.4應(yīng)定義以下環(huán)境變量:
export LD_ASSUME_KERNEL=2.2.5 |
Redhat Linux 9.0應(yīng)定義環(huán)境變量:
export LD_ASSUME_KERNEL=2.4.1 |
聯(lián)系客服