CentOS 6.3利用Apache来做集群实现负载均衡
进入apache的解压目录,就是你从网上下载下来的压缩文件,然后解压产生的目录。
#cd apache的解压目录/modules/proxy
# /usr/local/apache2/bin/apxs -c -i mod_proxy.c proxy_util.c
注意:上面如果不加proxy_util.c的话,LoadModule proxy_module modules/mod_proxy.so会报错的,提示你找不到mod_proxy.so文件
# /usr/local/apache2/bin/apxs -c -i mod_proxy_balancer.c
# /usr/local/apache2/bin/apxs -c -i mod_proxy_http.c
出现下面的东西说明装好了。
———————————————————————-
Libraries have been installed in:
/usr/local/apache2/modules
#要安装的模块装好了
# ls ./modules/
httpd.exp mod_fastcgi.so mod_proxy.so mod_rewrite.so
libphp5.so mod_fcgid.so mod_proxy_balancer.so
mod_cache.so mod_mem_cache.so mod_proxy_http.so
三,配置httpd.conf,测试负载均衡
1,根据请求数(默认),平均分配
#vi /usr/local/apache2/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
ProxyRequests Off
ProxyPass /mycluster !
ProxyPass / balancer://mycluster/ stickysession=BALANCEID
ProxyPassReverse / http://192.168.7.201/
ProxyPassReverse / http://192.168.7.202/
<Proxy balancer://mycluster>
BalancerMember http://192.168.7.201 route=http1 loadfactor=7
BalancerMember http://192.168.7.202 route=http2 loadfactor=3
ProxySet lbmethod=byrequests
</Proxy>
<Location /mycluster>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>