服務(wù)項目:網(wǎng)站建設(shè)、仿站、程序開發(fā)、APP開發(fā)設(shè)計、移動網(wǎng)站開發(fā)設(shè)計、企業(yè)網(wǎng)站設(shè)計、電子商務(wù)網(wǎng)站開發(fā)、網(wǎng)站維護(hù)、網(wǎng)站推廣、UX/UI 、HTML5、CSS3、JS / Jquery ...
四川???萍加邢薰?></a></div>
                    <div   id=四川浚??萍加邢薰? title=
四川???萍加邢薰?(開發(fā)設(shè)計官網(wǎng))TEL : 15308000360 / QQ : 38585404

您的位置:首頁 > 技術(shù)經(jīng)驗 > 服務(wù)器 > 正文

squid+nginx負(fù)載均衡實現(xiàn)單機(jī)跑多個squid
技術(shù)支持服務(wù)電話:15308000360 【7x24提供運(yùn)維服務(wù),解決各類系統(tǒng)/軟硬件疑難技術(shù)問題】

如今,在大訪問量的網(wǎng)站中,squid反向代理已經(jīng)成為一種常用的緩存技術(shù)。但是,眾所周知,squid本身不支持SMP,因此其原本是不支持在單臺服務(wù)器同一端口(例如要反向代理web必須指定80端口)下開多個進(jìn)程的。
 

而今多核多內(nèi)存服務(wù)器已成趨勢,如果單臺服務(wù)器只運(yùn)行一個squid反向代理跑web則顯得太浪費(fèi),而根據(jù)官方意見要想運(yùn)行多個squid實例,要么就指定不同的IP不同端口來實現(xiàn)。

 

而nginx是一個高性能的 HTTP 和反向代理服務(wù)器軟件,運(yùn)用nginx的負(fù)載均衡功能,我們就能很好的實現(xiàn)在同一臺服務(wù)器中跑多個squid的目的,充分發(fā)揮多核大內(nèi)存的作用。

 

具體步驟如下:
1.將N個squid安裝到不同目錄,并指定好多個用戶以及不同的監(jiān)聽端口,這樣便于監(jiān)控時查看,例如:
squid1:/opt/squid1 監(jiān)聽在127.0.0.1:8081
squid2:/opt/squid2 監(jiān)聽在127.0.0.1:8082
squid3:/opt/squid3 監(jiān)聽在127.0.0.1:8083

 

2.編譯并安裝,配置nginx
./configure
nginx配置文件nginx.conf:

user  www www;
worker_processes  10;

worker_rlimit_nofile 51200;

events {
        use epoll;
        worker_connections  51200;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
   tcp_nodelay  on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    upstream jianglb {
     server 127.0.0.1:8081;
     server 127.0.0.1:8082;
     server 127.0.0.1:8083;

    }

    #gzip  on;

    server {
        listen       192.168.1.3:80;
        server_name  www.mycodes.net mycodes.net ;
        access_log  logs/host.access.log  main;

        location / {
                proxy_pass        http://mycodes;
                proxy_redirect          off;
                proxy_set_header   Host             $host:80;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

        }
    }
}
這里有幾個配置的注意點:
1.如果需要同時代理加速多個域名,而這些域名是同時做負(fù)載均衡的話,不需要分開來指定,upstream只需要一個即可,proxy_pass那里的名稱能對應(yīng)起來即可;
2.proxy_set_header Host $host:80;這里最好加上端口80,因為我一開始沒加80,發(fā)現(xiàn)nginx轉(zhuǎn)發(fā)的時候squid會收到www.mycodes.net:8081這樣的頭信息,這明顯是不對的,一次加上80會比較好。



上一篇:linux大于2T的磁盤使用GPT分區(qū)方式
下一篇:linux 最常用命令集合

相關(guān)熱詞搜索:nginx squid 負(fù)載均衡