linux負載平衡筆記

來源:互聯網
上載者:User

標籤:

1.linux lvs nat實現負載平衡

  添加兩塊網卡並開啟路由管道

echo 1 > /proc/sys/net/ipv4/ip_forward //開始路由管道

  安裝ipvsadm

yum install ipvsadm

  配置ipvsadm

iptables -F //清楚防火牆ipvsadm -C //清楚ipvsadm配置ipvsadm -At 8.8.8.8:80 -s rr //告訴ipvsadm 調度8.8.8.8的80連接埠,並且調度模式為輪詢(-s rr)//設定調度的真實伺服器ipvsadm -at 8.8.8.8:80 -r 192.168.1.10:80 -mipvsadm -at 8.8.8.8:80 -r 192.168.1.11:80 -m//在這裡假設外網IP為8.8.8.8,內網IP為192.168.1.2,內網兩台服WEB伺服器分別為192.168.1.10,192.168.1.11並且網關指向192.168.1.2

 

2.nginx反向 Proxy實現負載平衡

yum安裝nginx

//添加nginx的yum包rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpmyum install nginx

配置Proxy 伺服器

//修改/ect/nginx/nginx.conf    client_max_body_size 300m;    client_body_buffer_size 128k;    client_body_temp_path /dev/shm/client_body_temp;    proxy_read_timeout 600;    proxy_send_timeout 600;    proxy_buffer_size 16k;    proxy_buffers 4 32k;    proxy_busy_buffers_size 64k;    proxy_temp_file_write_size 64k;    proxy_temp_path /dev/shm/proxy_temp;    upstream cluster{        server 192.168.1.10:80 weight=8 max_fails=2 fail_timeout=30s;           server 192.168.1.11:80 weight=8 max_fails=2 fail_timeout=30s;       }//修改/ect/nginx/conf.d/defaut.conf    location / {        root   /usr/share/nginx/html;        index  index.html index.htm;        proxy_pass http://cluster/;        proxy_redirect off;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header Host $host;    }

 

linux負載平衡筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.