Apache使用mod_jk/mod_proxy模块实现代理、负载均衡的配置

转载自:https://blog.csdn.net/yuanyuan_186/article/details/51290518

192.168.1.123/192.168.1.121为后端tomcat,mysql在192.168.1.121上,192.168.1.123没有mysql

192.168.1.122上只安装apache

————————————

配置apache反向代理tomcat时的mod_proxy.conf内容

vim /usr/local/apache/conf/extra/mod_proxy.conf

 

ProxyVia on

ProxyRequests Off

ProxyPreserveHost Off

Order allow,deny

Allow from all

ProxyPass / ajp://192.168.1.123:8009/(或者)

ProxyPassReverse / ajp://192.168.1.123:8009/

 

————————————

配置apache负载均衡时的mod_proxy.conf内容

vim /usr/local/apache/conf/extra/mod_proxy.conf

 

ProxyVia Off

ProxyRequests Off

ProxyPreserveHost Off

BalancerMember http://192.168.1.121:8080 loadfactor=1

BalancerMember http://192.168.1.123:8080 loadfactor=1

ProxySet lbmethod=bytraffic

ProxyPass / balancer://nba/ stickysession=JSESSIONID

ProxyPassReverse / balancer://nba/

 

————————————

配置Apache使用mod_jk模块实现代理

配置apache反向代理tomcat时的mod_jk.conf内容

 

JkWorkersFile /tomcat/conf/workers.properties

JkLogFile /var/log/mod_jk.log

JkLogLevel info

JkMount /* tomcat1

 

 

另:配置apache反向代理tomcat时的workers.properties内容

 

worker.list=tomcat1

worker.tomcat1.port=8009

worker.tomcat1.host=192.168.1.121

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor=1

 

————————————

配置Apache使用mod_jk模块实现负载均衡

配置apache负载均衡tomcat时的mod_jk.conf内容

JkWorkersFile /tomcat/conf/workers.properties

JkLogFile /var/log/mod_jk.log

JkLogLevel info

JkMount /* controller

 

另:配置apache负载均衡tomcat时的workers.properties内容

 

worker.list=controller

#========tomcat1========

worker.tomcat1.port=8009

worker.tomcat1.host=192.168.1.121

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor=1

#========tomcat2========

worker.tomcat2.port=8009

worker.tomcat2.host=192.168.1.123

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor=1

#========controller=======

worker.controller.type=lb

worker.controller.balance_workers=tomcat1,tomcat2

worker.controller.sticky_session=1

 

————————————

测试jsp内容

 

<%@ page language="java" %>

Tomcat1

Tomcat1

<% session.setAttribute("abc","abc"); %>

Session ID <%= session.getId() %>
Created on <%= session.getCreationTime() %>

 

————————————

解决ProxySet: unknown lbmethod lbmethod=bytraffic; balancer://nba

 

httpd.conf里有下面2个选项

LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

 

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

 

————

常用命令:

ps aux|grep java

netstat -an|grep 80

killall -9 httpd

 

cd /usr/local/apache/bin/

./startup.sh;tail -f /tomcat/logs/catalina.out

 

vim /usr/local/apache/conf/httpd.conf

/etc/init.d/iptables stop

你可能感兴趣的:(Apache使用mod_jk/mod_proxy模块实现代理、负载均衡的配置)