阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7 上配置LVS + Keepalived + ipvsadm

197次阅读
没有评论

共计 4822 个字符,预计需要花费 13 分钟才能阅读完成。

CentOS 7 上配置 LVS + Keepalived + ipvsadm

一、部署环境
keepalived:10.10.10.30(CentOS 7)
lvs1:10.10.10.140(CentOS 6.4)
lvs2:10.10.10.150(CentOS 6.4)

二、在 lvs1:10.10.10.140 上配置
[root@LVS1 ~]# yum install -y httpd
[root@LVS1 ~]# /etc/init.d/httpd start
[root@LVS1 ~]# cd /var/www/html/
[root@LVS1 html]# echo “ok” > keep.html
[root@LVS1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:15:B7:DC
TYPE=Ethernet
UUID=93f4695a-8641-4360-9fce-5e3af0e32fc9
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.140
NETMASK=255.255.255.0
GATEWAY=10.10.10.30
[root@LVS1 ~]#/etc/init.d/network restart
[root@LVS1 ~]#/sbin/ifconfig eth0:0 10.10.10.140 broadcast 10.10.10.255 netmask 255.255.255.255 up

三、在 lvs2:10.10.10.150 上配置
[root@LVS2 ~]# yum install -y httpd
[root@LVS2 ~]# /etc/init.d/httpd start
[root@LVS2 ~]# cd /var/www/html/
[root@LVS2 html]# echo “ok” > keep.html
[root@LVS2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:0D:33:AC
TYPE=Ethernet
UUID=e04f57dc-ef9d-4563-bfa4-9c8c1e8fc870
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.10.10.150
NETMASK=255.255.255.0
GATEWAY=10.10.10.30
[root@LVS2 ~]#/etc/init.d/network restart
[root@LVS2 ~]#/sbin/ifconfig eth0:0 10.10.10.140 broadcast 10.10.10.255 netmask 255.255.255.255 up

四、在 keepalived:10.10.10.30 上配置
[root@KEEP ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno33554984
HWADDR=00:0C:29:DC:FE:1B
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
#IPV6_PEERDNS=yes
#IPV6_PEERROUTES=yes
#IPV6_FAILURE_FATAL=no
NAME=eno33554984
#UUID=56cae8b8-235f-471d-9051-2508ee149e48
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=10.10.10.30
NETMASK=255.255.255.0
[root@KEEP ~]# /etc/init.d/network restart

[root@KEEP ~]# cd /data/keepalived/
[root@KEEP keepalived]# tar zxvf keepalived-1.2.12.tar.gz
[root@KEEP keepalived]# cd keepalived-1.2.12/
[root@KEEP keepalived-1.2.12]# ./configure –prefix=/usr/local/keepalived
[root@KEEP keepalived-1.2.12]# make
[root@KEEP keepalived-1.2.12]# make install
[root@KEEP keepalived-1.2.2]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/
[root@KEEP keepalived-1.2.2]# ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@KEEP keepalived-1.2.2]# ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@KEEP keepalived-1.2.2]# ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@KEEP keepalived-1.2.12]# cd

##keepalived 健康检查 HTTP_GET
[root@KEEP ~]# /usr/local/keepalived/bin/genhash -s 10.10.10.140 -p 80 -u /keep.html
MD5SUM = eff5bc1ef8ec9d03e640fc4370f5eacd

[root@KEEP ~]# /usr/local/keepalived/bin/genhash -s 10.10.10.150 -p 80 -u /keep.html
MD5SUM = eff5bc1ef8ec9d03e640fc4370f5eacd

[root@KEEP ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eno33554984
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.10.10.250
    }
}

virtual_server 10.10.10.250 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 10.10.10.140 80 {
        weight 1
        HTTP_GET {
            url {
              path /keep.html
              digest eff5bc1ef8ec9d03e640fc4370f5eacd
            }
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }

    real_server 10.10.10.150 80 {
        weight 1
        HTTP_GET {
            url {
              path /keep.html
              digest eff5bc1ef8ec9d03e640fc4370f5eacd
            }
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
}
[root@KEEP ~]# /etc/init.d/keepalived restart

五、在 keepalived:10.10.10.30 上用 ipvsadm 命令测试
[root@KEEP ~]# yum install -y ipvsadm
[root@KEEP ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
TCP  10.10.10.250:80 wrr persistent 50
  -> 10.10.10.140:80              Route  1      0          0       
  -> 10.10.10.150:80              Route  1      0          0       

在 10.10.10.140 执行
[root@LVS1 html]# echo  “” > keep.html
[root@KEEP ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
TCP  10.10.10.250:80 wrr persistent 50
  -> 10.10.10.150:80              Route  1      0          0   

再在 10.10.10.140 执行
[root@LVS1 html]# echo  “ok” > keep.html
[root@KEEP ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
TCP  10.10.10.250:80 wrr persistent 50
  -> 10.10.10.140:80              Route  1      0          0       
  -> 10.10.10.150:80              Route  1      0          0 

Linux 服务器 LB 群集之 LVS-NAT http://www.linuxidc.com/Linux/2013-05/84774.htm

Linux 下群集服务之 LB 集群 -LVS-NAT 模式 http://www.linuxidc.com/Linux/2012-05/59839.htm

LVS-NAT+ipvsadm 实现 RHEL 5.7 上的服务集群 http://www.linuxidc.com/Linux/2012-04/58936.htm

Linux 虚拟服务器 LVS-NAT 和 LVS-DR 模型的实现 http://www.linuxidc.com/Linux/2011-09/42934.htm

搭建 LVS 负载均衡测试环境 http://www.linuxidc.com/Linux/2014-09/106636.htm

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计4822字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中