linux负载均衡笔记

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 -m
ipvsadm -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反向代理实现负载均衡

yum安装nginx

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

yum install nginx

配置代理服务器

//修改/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;
    }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。