vim /etc/httpd/conf.d/httpd-jk.conf
------------------------------------------------------>
# Load the mod_jk
LoadModule jk_module modules/mod_jk.so //加载mod_jk.so模块
JkWorkersFile /etc/httpd/conf.d/workers.properties //此模块自己要用到的配置文件
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkMount /* lb1 //访问根下的所有内容都发到集群lb1中来
JkMount /status/ stat1
4.配置mod_jk模块的配置文件workers.properties:
vim /etc/httpd/conf.d/workers.properties
-------------------------------------------------------->
worker.list = lb1,stat1
worker.TomcatA.type = ajp13 //httpd连接tomcat所用的模式
worker.TomcatA.host = 192.168.19.66
worker.TomcatA.port = 8009
worker.TomcatA.lbfactor = 1 //权重
worker.TomcatB.type = ajp13
worker.TomcatB.host = 192.168.19.74
worker.TomcatB.port = 8009
worker.TomcatB.lbfactor = 1
worker.lb1.type = lb //调度方式
worker.lb1.sticky_session = 0 //是否使用session绑定
worker.lb1.balance_workers = TomcatA, TomcatB
worker.stat1.type = status
5.启动测试:
service httpd start
用浏览器打开,我们不断刷新,可以看到实验效果。
四、利用mod_proxy模块对tomcat进行负载均衡
1.仍然在19.66上编辑即可,使用http协议:
cd /etc/httpd/conf.d/
mv httpd-jk.conf httpd-jk.conf.bak
vim httpd-proxy.conf
-------------------------------------------------------------->
<Proxy balancer://lb1>
BalancerMember :8080 loadfactor=1 route=TomcatA
BalancerMember :8080 loadfactor=1 route=TomcatB
ProxySet lbmethod=byrequests //基于权重将统计请求个数进行调度
</Proxy>
ProxyPass / balancer://lb1/
ProxyPassReverse / balancer://lb1/
<--------------------------------------------------------------
service httpd restart
2.使用ajp协议:
cd /etc/httpd/conf.d/
mv httpd-jk.conf httpd-jk.conf.bak
vim httpd-proxy.conf
-------------------------------------------------------------->
<Proxy balancer://lb1>
BalancerMember ajp://192.168.19.66:8009 loadfactor=1 route=TomcatA
BalancerMember ajp://192.168.19.74:8009 loadfactor=1 route=TomcatB
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://lb1/
ProxyPassReverse / balancer://lb1/
<--------------------------------------------------------------
service httpd restart
以上两种办法都可以实现负载均衡,刷新页面仍然可以看到效果,这里就不在给出图片了。至此,实验全部结束,谢谢!
更多Tomcat相关教程见以下内容:
RedHat Linux 5.5安装JDK+Tomcat并部署Java项目
Linux下使用Xshell查看Tomcat实时日志中文乱码解决方案