1,解压jdk到/usr/local/jdk下
2, 解压apache-tomcat到/usr/local/tomcat下
3 ,设置环境变量(方法有好几种,只写我用的那种)
将以下三行输入到tomcat目录下startup.sh和shutdown.sh上方
export JAVA_HOME="/usr/local/jdk"
export JRE_HOME="/usr/local/jdk"
export CATALINA_HOME="/usr/local/tomcat"
4,启动并验证
/usr/local/tomcat/bin/startup.sh
curl http://localhost:8080/index.jsp
5,apache与tomcat配合: proxy_ajp
在apache配置文件下找proxy_ajp.conf文件,将内容改为:
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
ProxyPass / http://192.168.109.4:8080/
ProxyPass /tomcat/ http://192.168.109.4:8080/
ProxyPass /examples/ http://192.168.109.4:8080/jsp-examples/
6,设定tomcat与apache共同目录
将 <Context path="" docBase="/var/www" debug="0"/> 加到以下三句的下一行:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
然后重启apache和tomcat
7,设定tomcat的文件访问权限
[root@xxw conf]# cat tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="tomcat"/>
<role rolename="admin"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="admin" password="admin" roles="admin,manager"/>
<user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>
8,写一个启动脚本tomcat,放在/etc/init.d目录下,并赋予+x权限
#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop the Tomcat daemon.
TOMCAT_HOME=/usr/local/tomcat
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
# necessary environment variables export
CATALINA_HOME=$TOMCAT_HOME
export JAVA_HOME=/usr/java/jdk1.6.0_11
# source function library.
. /etc/rc.d/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
# check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
# check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then echo "Tomcat not valilable..."
exit
fi
start(){
echo -n "Starting Tomcat: "
daemon $TOMCAT_START
echo
touch /var/lock/subsys/tomcat
}
stop(){
echo -n $"Shutting down Tomcat: "
daemon $TOMCAT_STOP
rm -f /var/lock/subsys/tomcat.pid echo
}
restart(){
stop
start
}
status(){
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n "tomcat ( pid "
ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
}
case "$1" in
start)
start ;;
stop)
stop ;;
restart)
stop
sleep 3
start ;;
status)
status ;;
*)
echo "Usage: tomcatd {start|stop|restart|status}"
exit 1
esac
exit 0
9,排错:503
从外面来看,是服务器无法接受响应了,其实是后台tomcat没响应。可以看看它是否启动,或者apache转发IP和端口是否正确。
能否实现动静分开,使apache提供静态内容,让tomcat专门解析jsp,亟待研究。
本文出自 “西瓜皮” 博客,谢绝转载!