先配置mod_jk的代理功能,
[[email protected] ~]# yum install -y httpd-devel
[[email protected] ~]# rpm -ql httpd-devel
/usr/sbin/apxs
apxs是httpd安装外部模块必备的
[[email protected] ~]# yum groupinstall"Development Tools" "Server Platform Development" -y //所需要的包组。
编译安装需要的环境。
[[email protected] ~]# tar xftomcat-connectors-1.2.40-src.tar.gz
[[email protected] ~]# ls
a install.log oracle
apache-tomcat-7.0.56.tar.gz install.log.syslog root20141030092112523.zip
apache-tomcat-8.0.20.tar.gz jdk-8u31-linux-i586.rpm tomcat-connectors-1.2.40-src
b lamp tomcat-connectors-1.2.40-src.tar.gz
[[email protected] ~]# cd tomcat-connectors-1.2.40-src
[[email protected] tomcat-connectors-1.2.40-src]# ls
conf docs HOWTO-RELEASE.txt jkstatus LICENSE native NOTICE README.txt support tools xdocs
[[email protected] tomcat-connectors-1.2.40-src]# cdnative/
[[email protected] native]# ls
aclocal.m4 apache-2.0 BUILDING.txt configure docs Makefile.am netscape scripts TODO.txt
apache-1.3 buildconf.sh common configure.ac iis Makefile.in README.txt STATUS.txt
[[email protected] native]# ./configure--with-apxs=/usr/sbin/apxs
[[email protected] native]# make && makeinstall
。
。
。
----------------------------------------------------------------------
chmod 755/usr/lib64/httpd/modules/mod_jk.so
Please be sure to arrange/etc/httpd/conf/httpd.conf...
make[1]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native/apache-2.0‘
make[1]: Entering directory`/root/tomcat-connectors-1.2.40-src/native‘
make[2]: Entering directory`/root/tomcat-connectors-1.2.40-src/native‘
make[2]: Nothing to be done for`install-exec-am‘.
make[2]: Nothing to be done for`install-data-am‘.
make[2]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native‘
make[1]: Leaving directory`/root/tomcat-connectors-1.2.40-src/native‘
[[email protected] ~]# cd /etc/httpd
[[email protected] httpd]# ls
conf conf.d logs modules run
[[email protected] httpd]# cd conf.d/
[[email protected] conf.d]# ls
php.conf README welcome.conf
[[email protected] conf.d]# vim mod_jk.conf
# Load the mod_jk
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /* TomcatA
JkMount /status/ statA
~
[[email protected] conf.d]# vim/etc/httpd/conf.d/workers.properties
worker.list = TomcatA,statA
worker.TomcatA.port=8009
worker.TomcatA.host=192.168.1.116
worker.TomcatA.type=ajp13
worker.TomcatA.lbfactor=1
worker.statA.type = status
[[email protected] conf.d]# httpd -t
Syntax OK
[[email protected] conf.d]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] conf.d]#
至此,一个基于mod_jk模块与后端名为TomcatA的worker通信的配置已经完成,重启httpd服务即可生效。
还有状态信息
要实现负载均衡,至少需要两个tomcat还在本机上操作,配置另一个版本的tomcat,配置完成之后访问http://192.168.1.116:9080
mod_jk可直接支持负载均衡,需要启用一个特殊型的worker:lb。
[[email protected] conf.d]# vim mod_jk.conf
#Load the mod_jk
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /* lbcluster1
JkMount /status/ statA
~
[[email protected] conf.d]# vim workers.properties
worker.list = lbcluster1,statA
worker.TomcatA.port=8009
worker.TomcatA.host=192.168.1.116
worker.TomcatA.type=ajp13
worker.TomcatA.lbfactor=1
worker.TomcatB.port=9009
worker.TomcatB.host=192.168.1.116
worker.TomcatB.type=ajp13
worker.TomcatB.lbfactor=1
worker.lbcluster1.type = lb
sorker.lbcluster1.sticky_session = 0
worker.lbcluster1.balance_workers =TomcatA, TomcatB
worker.statA.type = status
~
[[email protected] conf.d]# httpd -t
Syntax OK
[[email protected] bin]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] bin]#
到此mod_jk实现负载均衡就配置好了,测试如下。
访问http://192.168.1.116
再次刷新