Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux集群 > 负载均衡 > » 正文

HA+LVS+负载均衡

来源: zhanhai 分享至:

公司发展的需求,先在本地做测试,把测试步骤贴出来。

------------------------------------------------

环境说明:

VirtualBOX 
ubuntu-real1  192.168.1.201

ubuntu-real2  192.168.1.202

Centos        192.168.1.202

VIP           192.168.1.200

-----------------------------------------------------

# 安装Ubuntu 10 Server  Centos 

# 克隆Ubuntu     ubuntu-real1   ---ubuntu-real2

# 克隆完后 会出现网络无法启动

sudo mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.old

Reboot

#设置静态IP

vim /etc/network/interfaces
auto eth0
iface eth0 inet static    
address 192.168.1.201
netmask 255.255.255.0
gateway 192.168.1.1

/etc/init.d/networking restart

#结束个用户 

pkill -9 -t pts/0

# 更换源  (不一定需要操作

apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE8C
echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
apt-get update

# 源安装 

apt-get install  ipvsadm  keepalived 

cd /etc/keepalived

vim  keepalived.conf

---------------Master配置----------------

global_defs {
   notification_email {
     zhanhai@foxmail.com
   }
   notification_email_from zhanhai123@foxmail.com    
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER    # keepalived2 机器为 BAUCK
    interface eth0   
    virtual_router_id 50   #VRID标示
    priority 102        # 优先级
    advert_int 1        #检测间隔
    authentication {
        auth_type PASS
        auth_pass 1987
    }
    virtual_ipaddress {
       192.168.1.200
    }
}
virtual_server 192.168.1.200 80 {
    delay_loop 10   #每10秒检测次RealServer
    lb_algo rr      #轮训 rr|wrr|lc|lblc|sh|dh
    lb_kind DR      ##lvs使用Direct Route NAT|DR|TUN
    persistence_timeout 50   # 默认50秒钟都访问同一台机器(会话保持)
    protocol TCP
   
  real_server 192.168.1.201 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }
    real_server 192.168.1.202 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }

    real_server 192.168.1.203 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }

}
-----------------------------------------------------

/etc/init.d/keepalived start 

# 查看状态

ip a

---------------BACKUP配置----------------

global_defs {
   notification_email {
     zhanhai@foxmail.com
   }
   notification_email_from zhanhai123@foxmail.com    
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP     # BACKUP
    interface eth0   
    virtual_router_id 50   #VRID标示
    priority 101        # 优先级
    advert_int 1        #检测间隔
    authentication {
        auth_type PASS
        auth_pass 1987
    }
    virtual_ipaddress {
       192.168.1.200
    }
}
virtual_server 192.168.1.200 80 {
    delay_loop 10   #每10秒检测次RealServer
    lb_algo rr      #轮训 rr|wrr|lc|lblc|sh|dh
    lb_kind DR      ##lvs使用Direct Route NAT|DR|TUN
    persistence_timeout 50   # 默认50秒钟都访问同一台机器(会话保持)
    protocol TCP
   
  real_server 192.168.1.201 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }
    real_server 192.168.1.202 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }

    real_server 192.168.1.203 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }

}
-----------------------------------------------------

 ifconfig eth0 down  /ifconfig eth0 up  

查看ip a


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史