服務器:linux
http服務器:192.168.29.128c++
tomcat1:192.168.29.129apache
tomcat2:192.168.29.130vim
準備軟件:tomcat
jdk-7u79-linux-x64.gz
apache-tomcat-7.0.42.tar.gz
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.bz2
httpd-2.4.20.tar.gz
pcre-8.37.tar.gz服務器
1.安裝jdk,tomcat(此處教程繁多,再也不廢話)session
2.編譯httpd(編譯環境:gcc,gcc-c++)jvm
apr:tcp
# tar xf apr-1.5.2.tar.bz2spa
# cd apr-1.5.2
#./configure --prefix=/usr/local/apr
# make && make install
apr-util:
# tar xf apr-util-1.5.4.tar.bz2
# cd apr-util-1.5.4
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
--with-apr=/usr/local/apr/ :指明apr安裝位置;
# make && make install
pcre:
# tar xf pcre-8.37.tar.gz
# cd pcre
#./configure --prefix=/usr/local/ pcre-8.37
# make && make install
httpd:
# tar xf httpd-2.4.16.tar.bz2
# cd httpd-2.4.16
# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
# make && make install
3.配置apache2.4
#cd /usr/local/apache2
①#vim conf/httpd.conf文件,
編輯:ServerName 192.168.28.128:80
加載如下模塊。
#---------------------start------------------------
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule speling_module modules/mod_speling.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
取消 Include conf/extra/httpd-vhosts.conf的註釋標記#。
文件末尾加上
<proxy balancer://cluster>
BalancerMember ajp://192.168.29.130:8009 loadfactor=1 route=jvm1
BalancerMember ajp://192.168.29.129:8009 loadfactor=1 route=jvm2
</proxy>
② #vim conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin test@qq.com
ServerName 192.168.29.130
ServerAlias 192.168.29.130
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
ErrorLog "logs/lbtest-error.log"
CustomLog "logs/lbtest-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin test@qq.com
ServerName 192.168.29.129
ServerAlias 192.168.29.129
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
ErrorLog "logs/lbtest-error.log"
CustomLog "logs/lbtest-access.log" common
</VirtualHost>
4.修改tomcat 配置文件
#cd apache-tomcat-7.0.42
#vim conf/server.xml
tomcat1:192.168.29.129
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm2" >
打開註釋:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
一樣編輯另外一臺服務器配置
tomcat2:192.168.29.130
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1" >
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
5.啓動tomcat
啓動httpd
#cd /usr/local/apache2/bin
#./apachectl start
訪問http://192.168.29.128/項目路徑
大功告成。。。。