负载均衡:
第一步:首先下载安装apache,我选择的是Apache2.2.19.
第二步:修改apache安装目录下的conf/httpd.conf,打开如下配置(默认注释掉了)
打开vhost配置的自配置文件:
第三步:注释掉Vhost配置文件里面原来的,增加<VirtualHost *:80>
ServerAdmin [email protected]-host2.example.com DocumentRoot "D:/apache2.2/httpd-2.2-x64/htdocs" ServerName dummy-host2.example.com ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common ProxyRequests Off ProxyPreserveHost on ProxyPass / balancer://tomcat-Hello222/ ProxyPassReverse / balancer://tomcat-Hello222/ <Proxy balancer://tomcat-Hello222/> # 热备份 #BalancerMember http://192.168.0.101:8080 #BalancerMember http://192.168.0.110:8080 status=+H # loadfactor=1 route=tomcat8_local smax=5 max=20 ttl=120 retry=300 timeout=15 这个为配置的参数,最大链接,超时,等等 BalancerMember http://192.168.0.101:8080 loadfactor=1 route=tomcat8_local smax=5 max=20 ttl=120 retry=300 timeout=15 BalancerMember http://192.168.0.100:8080 loadfactor=1 route=tomcat8_local smax=5 max=20 ttl=120 retry=300 timeout=15 ProxySet lbmethod=bybusyness </Proxy> </VirtualHost>
热备份:
如上图去掉给BalancerMember配置的参数等,给备份服务器加上status=+H
注意:以上代码为本人实现,如需照抄请修改 ProxyPass处的Hello222为你自己的工程名。
时间: 2024-11-13 16:09:56