centos7下apache2.4反向代理

apache安裝目錄在/data/apache24,這裏就不介紹apache的安裝了。php

1、反向代理配置算法

在/data/apache24/conf/extra下建立htttpd-proxy.conf文件apache

#開啓反代理的必須模塊
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so

#關閉正向代理
ProxyRequests Off
#設置集羣組,mycluster名稱能夠隨意取
<Proxy "balancer://mycluster">
    BalancerMember http://192.168.1.222:8080
    BalancerMember http://192.168.1.233:8080
</Proxy>
#使用集羣組,mycluster名稱需與上面配置相同
ProxyPass "/demo" "balancer://mycluster/"
ProxyPassReverse "/demo" "balancer://mycluster/"

修改/data/apache24/conf/httpd.conf中添加服務器

Include conf/extra/htttpd-proxy.conf

這樣重啓apache後,當咱們訪問網站/demo時,會反向代理到222和233上的8080端口。負載均衡

 

2、apache負載均衡管理界面網站

<Location "/balancer-manager">
    SetHandler balancer-manager
    order Deny,Allow
    Deny from all
    Allow from localhost
</Location>

訪問網站/balancer-manager時,就能夠看到apache自帶的一個負載均衡管理界面。代理

 

3、虛擬主機上配置反向代理blog

<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/test"
    ServerName www.test.com
    ErrorLog "logs/www.test.com-error_log"
    CustomLog "logs/www.test.com-access_log" common
    #當咱們訪問www.test.com時,都會代理到mycluster集羣中。
    ProxyPass "/" "balancer://mycluster/"
    ProxyPassReverse "/" "balancer://mycluster/"
</VirtualHost>

 

4、負載比例分配requests

loadfactor取值範圍爲1-100io

ProxyRequests Off
<Proxy "balancer://mycluster">
    BalancerMember http://192.168.1.222:8080 loadfactor=6
    BalancerMember http://192.168.1.233:8080 loadfactor=4
    BalancerMember http://192.168.1.244:8080 loadfactor=2
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"

  

5、負載分配算法

lbmethod取值有:
lbmethod=byrequests 按照請求次數均衡(默認)
lbmethod=bytraffic 按照流量均衡
lbmethod=bybusyness 按照繁忙程度均衡(老是分配給活躍請求數最少的服務器)

ProxyRequests Off
<Proxy "balancer://mycluster">
    BalancerMember http://192.168.1.222:8080 loadfactor=6
    BalancerMember http://192.168.1.233:8080 loadfactor=4
    BalancerMember http://192.168.1.244:8080 loadfactor=2
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"
ProxySet lbmethod=bytraffic

 

5、熱備份

請求老是流向222,一旦222掛掉, apache會檢測到錯誤並把請求分流給233。apache會每隔幾分鐘檢測一下222的情況,若是222恢復,就繼續使用222。

ProxyRequests Off
<Proxy balancer://mycluster>
    BalancerMember http://192.168.1.222:8080
    BalancerMember http://192.168.1.233:8080 status=+H
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"
相關文章
相關標籤/搜索