[乐意黎原创]使用Apache httpd反向代理Tomcat及实现均衡负载

电脑环境:  windows 7, 64.

软件版本:  Apache http 2.2, tomcat-8.0.15, JDK jdk1.8.0,


1. Apache httpd-2.2 目录 E:\PHPCMS\Apache2.2

1.1 打开E:\PHPCMS\Apache2.2\conf\httpd.conf去掉以下文本前的注释符(#)以便让Apache在启动时自动加载代理(proxy)模块

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule slotmem_module modules/mod_slotmem.so

LoadModule manager_module modules/mod_manager.so

LoadModule proxy_cluster_module modules/mod_proxy_cluster.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

 

1.2 在下列节点中增加index.jsp , 目的是能看到首页(conf/httpd.conf文件)

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php default.php index.html index.htm index.jsp default.jsp
</IfModule>

#开启虚拟站点配置
#去掉Include/ conf/extra/httpd-vhosts.conf前面的注释(conf/httpd.conf文件)
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

 1.3 配置反向代理 tomcat.

   说明 Tomcat 的webapps 路径: E:\WebServer\apache-tomcat-8.0.15\webapps.  经过webapps.war 释放,有 aerchi-dev目录,  如下图


    

 
在E:\PHPCMS\Apache2.2\conf\extra\httpd-vhosts.conf,配置虚拟站点,在下面加上

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    #OK 2019-05-08
#    <Proxy balancer://cluster>
#        BalancerMember http://192.168.128.99:8080 route=server1
#        ProxySet stickysession=ROUTEID
#    </Proxy>
#    ProxyPass /aerchi-dev/luxiren balancer://cluster/aerchi-dev/luxiren 


    <Proxy balancer://cluster>
        BalancerMember http://192.168.128.99:8080 route=server1
        ProxySet maxattempts=30
        ProxySet nofailover=On
        ProxySet timeout=600
        ProxySet stickysession=StickyCookie
        ProxySet lbmethod=byrequests
        ProxySet stickysession=ROUTEID
    </Proxy>

    ProxyPreserveHost On

    ProxyPass /aerchi-dev/luxiren  balancer://cluster/aerchi-dev/luxiren stickysession=JSESSIONID|jsessionid nofailover=Off
    ProxyPassReverse /aerchi-dev/luxiren balancer://cluster/aerchi-dev/luxiren 


    #Please add vt proxy if use sub context
    #vt
    ProxyPass /aerchi-dev/vt balancer://cluster/aerchi-dev/vt stickysession=JSESSIONID|jsessionid nofailover=Off
    ProxyPassReverse /cumbria-dev/vt balancer://cluster/aerchi-dev/vt

    ErrorLog "logs/luxiren -error.log"
    CustomLog "logs/luxiren -access.log" common
</VirtualHost>

2. Tomcat 配置,在 Tomcat E:\WebServer\apache-tomcat-8.0.15\conf\server.xml 里进行如下修改:
Tomcat目录: E:\WebServer\apache-tomcat-8.0.15

<!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server1">

 

Tomcat 运行 Server

关闭: shutdown.bat
启动: startup.bat

参考:  http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html


乐意黎

2019-05-08

发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览