Apache使用mod_jk/mod_proxy模組實現代理、負載均衡的配置

yuanyuan_186發表於2016-05-01


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

<Proxy *>

Order allow,deny

Allow from all

</Proxy>

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

<Proxy balancer://nba>

BalancerMember http://192.168.1.121:8080 loadfactor=1

BalancerMember http://192.168.1.123:8080 loadfactor=1

ProxySet lbmethod=bytraffic

</Proxy>

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" %>

<html>

<head><title>Tomcat1</title></head>

<body>

<h1><font color="red">Tomcat1 </font></h1>

<table align="centre" border="1">

<tr>

<td>Session ID</td>

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

<td><%= session.getId() %></td>

</tr>

<tr>

<td>Created on</td>

<td><%= session.getCreationTime() %></td>

</tr>

</table>

</body>

</html>

 

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

解決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

http://www.51ou.com/browse/linuxjq/39473.html

相關文章