How to configure Apache and Tomcat to realize the load balancing?
1. Apache: add following to the end of httpd.conf
apache address: 10.12.22.53
ProxyRequests Off
ProxyPass / balancer://abc/ nofailover=On
<Proxy balancer://abc/>
BalancerMember ajp://10.12.22.91:8009 loadfactor=1 route=jvm91
BalancerMember ajp://10.12.22.100:8039 loadfactor=1 route=jvm100
</Proxy>
There are two tomcat servers, 10.12.22.91 and 10.12.22.100 and ajp ports 8009 and 8039 respective.
2. Tomcat server.xml
10.12.22.91
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm91">
10.12.22.100
<Connector port="8039" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm100">
Notice, AJP port and jvmRoute need be matched along with the httpd.conf.
3. http://10.12.22.53/gridserver
sometimes it cannot success for firewall, you can close the firewall, or open the ajp port at iptables.
you can see the status via "serivce iptables status"
you can add&remove the port via "vim /etc/consys/iptables"
for add ajp port 8009 via adding the line
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT
and if you want to reject the port via deleting the line
1. Apache: add following to the end of httpd.conf
apache address: 10.12.22.53
ProxyRequests Off
ProxyPass / balancer://abc/ nofailover=On
<Proxy balancer://abc/>
BalancerMember ajp://10.12.22.91:8009 loadfactor=1 route=jvm91
BalancerMember ajp://10.12.22.100:8039 loadfactor=1 route=jvm100
</Proxy>
There are two tomcat servers, 10.12.22.91 and 10.12.22.100 and ajp ports 8009 and 8039 respective.
2. Tomcat server.xml
10.12.22.91
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm91">
10.12.22.100
<Connector port="8039" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm100">
Notice, AJP port and jvmRoute need be matched along with the httpd.conf.
3. http://10.12.22.53/gridserver
sometimes it cannot success for firewall, you can close the firewall, or open the ajp port at iptables.
you can see the status via "serivce iptables status"
you can add&remove the port via "vim /etc/consys/iptables"
for add ajp port 8009 via adding the line
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT
and if you want to reject the port via deleting the line
本文介绍如何通过配置Apache和Tomcat实现负载均衡。主要包括:在Apache的httpd.conf中添加代理设置;配置两个Tomcat服务器的server.xml文件;以及解决防火墙问题确保AJP端口畅通。

被折叠的 条评论
为什么被折叠?



