标签:
系统环境:CentOS release 6.5 (Final)
ip地址:192.168.1.203
系统环境:CentOS release 6.5 (Final)
外网ip:192.168.1.201
jdk版本:java version "1.7.0_25"
tomcat版本:Apache Tomcat/7.0.68
系统环境:CentOS release 6.5 (Final)
外网ip:192.168.1.202
jdk版本:java version "1.7.0_25"
tomcat版本:Apache Tomcat/7.0.68
# tar zxvf server-jre-7u25-linux-x64.tar.gz -C /usr/local
# mv /usr/local/jdk1.7.0_25 /usr/local/jdk1.7
# vim /etc/profile.d/java.sh 加入如下内容:
export JAVA_HOME=/usr/local/jdk1.7
export JRE_HOME=/usr/local/jdk1.7/jre
export CLASSPATH=.:$JAVA_HOME/lib:/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
重新加载配置文件
# source /etc/profile.d/java.sh
检查jdk环境安装是否正确:
# java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
# tar zxvf apache-tomcat-7.0.68.tar.gz -C /usr/local/
# mv /usr/local/apache-tomcat-7.0.68 /usr/local/tomcat
tomcat应用程序“部署”
部署是指webapp及其所依赖类库等装载进tomcat实例上,以便接受用户请求,部署方式有:
静态部署:在tomcat启动之前进行的webapp部署;
动态部署:在打断tomcat运行的前提下,通过tomcat manager或其他的命令行工具进行的部署
ajp(apache jserv protocal):二进制协议,使用httpd反向代理用户请求至tomcat时,在httpd和tomcat之间使用;如果使用nginx反代那只能是用http协议。
编辑tomcat启动脚本,设置开机自启动:
#!/bin/sh
# Tomcat init script for Linux.
# chkconfig: 2345 96 14
JAVA_HOME=/usr/local/jdk1.7
CATALINA_HOME=/usr/local/tomcat
export JAVA_HOME CATALINA_HOME
case $1 in
start)
exec $CATALINA_HOME/bin/catalina.sh start ;;
stop)
exec $CATALINA_HOME/bin/catalina.sh stop ;;
restart)
$CATALINA_HOME/bin/catalina.sh stop
sleep 2
exec $CATALINA_HOME/bin/catalina.sh start ;;
*)
echo "Usage:`basename $0` {start|stop|restart}"
exit
;;
esac
# chkconfig --add tomcat
# chkconfig --level 2345 tomcat on
apache2.2版本后已经自带mod_proxy,同时也支持mod_jk模式,但需要重新编译该模块
查看是否有apxs
# rpm -ql httpd-devel | grep apxs
如果没有安装httpd-devel
mod下载地址:http://tomcat.apache.org/download-connectors.cgi
下载该文件:tomcat-connectors-1.2.41-src.tar
# tar zxvf tomcat-connectors-1.2.41-src.tar.gz
# cd /usr/local/src/tomcat-connectors-1.2.41-src/native/
# ./configure --with-apxs=/usr/sbin/apxs
# make && make install
查看/usr/lib64/httpd/modules/目录下是否有mod_jk模块
# ls /usr/lib64/httpd/modules/
# vim /etc/httpd/conf.d/mod_jk.conf加入如下内容
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel notice
JkMount /* lbcA
#JkMount /status/ statA
# vim /etc/httpd/conf.d/workers.properties
worker.list=lbcA,TomcatA,TomcatB
worker.TomcatA.type=ajp13
worker.TomcatA.host=192.168.1.201
worker.TomcatA.port=8009
worker.TomcatA.lbfactor=1
worker.TomcatB.type=ajp13
worker.TomcatB.host=192.168.1.202
worker.TomcatB.port=8009
worker.TomcatB.lbfactor=1
worker.lbcA.type=lb
worker.lbcA.sticky_session=0
worker.lbcA.balance_workers=TomcatA,TomcatB
# vim /usr/local/tomcat/conf/server.xml
<Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatA">
<Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatB">
重启后搭建成功。
标签:
原文地址:http://www.cnblogs.com/fansik/p/5406827.html