zoukankan      html  css  js  c++  java
  • LVS-Keepalived高可用集群(DR)

    LVS-DR+Keepalived高可用集群

    -------client------------------主LVS--------------------从LVS---------------------WEB1----------------------WEB2----------
    2.2.2.250 2.2.2.10 2.2.2.20 2.2.2.30 2.2.2.40
    lo:0:2.2.2.2 lo:0:2.2.2.2


    一、配置LVS服务器(主-从两台)
    1、配置IP
    [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
    [root@localhost ~]# service network restart
    2、调整响应参数(主-从配置一样)
    [root@localhost ~]# vim /etc/sysctl.conf
    添加:
    net.ipv4.conf.all.send_redirects = 0
    net.ipv4.conf.default.send_redirects = 0
    net.ipv4.conf.eth0.send_redirects = 0
    [root@localhost ~]# sysctl -p
    3、安装并配置ipvsadm(主-从配置一样)
    [root@localhost ~]# rpm -ihv /mnt/Packages/ipvsadm-1.26-2.el6.x86_64.rpm
    [root@localhost ~]# service ipvsadm start
    [root@localhost ~]# chkconfig --add ipvsadm
    [root@localhost ~]# chkconfig ipvsadm on

    二、配置Keepalived服务器
    4、安装keepalived软件(主-从配置一样)
    [root@localhost ~]# yum -y install kernel-devel openssl-devel popt-devel
    [root@localhost ~]# tar -zxvf keepalived-1.2.13.tar.gz -C /usr/src/
    [root@localhost ~]# cd /usr/src/keepalived-1.2.13/
    [root@localhost keepalived-1.2.13]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64
    [root@localhost keepalived-1.2.13]# make && make install
    [root@localhost ~]# /etc/init.d/keepalived start
    [root@localhost ~]# netstat -anp | grep keepalived
    [root@localhost ~]# chkconfig --add keepalived
    [root@localhost ~]# chkconfig keepalived on
    4.1、主服务器配置
    [root@localhost ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
    [root@localhost ~]# vim /etc/keepalived/keepalived.conf
    修改:
    global_defs {
    router_id LVS_DEVEL_R1
    }
    vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 1
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    2.2.2.2
    }
    }
    virtual_server 2.2.2.2 80 {
    delay_loop 15 //健康检查的时间
    lb_algo rr //定义调度算法
    lb_kind DR //定义负载均衡群集的模式
    protocol TCP
    real_server 2.2.2.30 80 {
    weight 1 //定义权重值
    TCP_CHECK {
    connect_port 80 //检查目标端口
    connect_timeout 3 //链接超时时间
    nb_get_retry 3 //重试次数
    delay_before_retry 4 //重试间隔时间
    }
    }
    real_server 2.2.2.40 80 {
    weight 1
    TCP_CHECK {
    connect_port 80
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 4
    }
    }
    }
    [root@localhost ~]# service keepalived restart
    [root@localhost ~]# ip add show dev eth0

    4.2、从服务器配置
    [root@localhost ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
    [root@localhost ~]# vim /etc/keepalived/keepalived.conf
    修改:
    global_defs {
    router_id LVS_DEVEL_R2
    }
    vrrp_instance VI_1 {
    state BACKUP
    priority 99
    ......
    ---其他参数与主服务器保持一致----
    }
    [root@localhost ~]# service keepalived restart
    [root@localhost ~]# ip add show dev eth0

    三、配置WEB节点服务器
    1、配置IP地址
    1)设置IP
    [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
    2)设置VIP
    [root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
    [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
    修改:
    DEVICE=lo:0
    IPADDR=2.2.2.2
    NETMASK=255.255.255.255
    ONBOOT=yes
    [root@localhost ~]# /etc/init.d/network restart

    3)添加路由
    [root@localhost ~]# route add -host 2.2.2.2 dev lo:0
    [root@localhost ~]# echo "route add -host 2.2.2.2 dev lo:0" >> /etc/rc.local
    2、调整响应参数
    [root@localhost ~]# vim /etc/sysctl.conf
    添加:
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.all.arp_announce = 2
    net.ipv4.conf.default.arp_ignore = 1
    net.ipv4.conf.default.arp_announce = 2
    net.ipv4.conf.lo.arp_ignore = 1
    net.ipv4.conf.lo.arp_announce = 2
    [root@localhost ~]# sysctl -p

    3、配置http服务
    WEB-1:
    [root@localhost ~]# echo "welcome to 2.2.2.30 web server" > /var/www/html/index.html
    WEB-2:
    [root@localhost ~]# echo "welcome to 2.2.2.40 web server" > /var/www/html/index.html
    [root@localhost ~]# service httpd restart
    [root@localhost ~]# chkconfig --add httpd
    [root@localhost ~]# chkconfig httpd on


    三、验证:
    一)使用ping命令
    客户端:ping -t 2.2.2.2
    断开主LVS的网卡,查看客户端的ping情况。
    重启主LVS的网卡,查看客户端的ping情况。
    二)客户端
    1、访问:
    http://2.2.2.2/
    在主LVS上查看:[root@localhost ~]# ipvsadm -Lnc
    2、断开主LVS的网卡
    客户端访问:http://2.2.2.2/
    在主-从LVS上查看:
    [root@localhost ~]# ipvsadm -Lnc
    在主-从LVS上查看:
    [root@localhost ~]# ip addr show dev eth0
    3、重启主LVS的网卡
    客户端访问:http://2.2.2.2/
    在主-从LVS上查看:
    [root@localhost ~]# ipvsadm -Lnc
    在主-从LVS上查看:
    [root@localhost ~]# ip addr show dev eth0

  • 相关阅读:
    预编译命令 #if DEBUG
    conda常用命令
    tensorflow 安装指南
    LocNET和池化理解
    同时安装cuda8和cuda9
    np.transpose
    python中List的slice用法
    书单
    训练工程
    linux 查看进程
  • 原文地址:https://www.cnblogs.com/luoyan01/p/9734172.html
Copyright © 2011-2022 走看看