k8s(3):k8s安装(二)安装keepalived

keepalived组件主要用于master之间的高可用,本次将在master-1和master-2之间安装keepalived,实现高可用,其中虚拟IP地址为172.31.7.49.

1. 进行heekalived组件的安装。

#master-1和master-1节点配置
[root@master-1 ~]# yum install -y keepalived

2. 进行keepalived组件配置

'''
master:
健康检查脚本的用户为root
优先级为100
vip为172.31.7.49
网卡为eth0
启用认证,认证密码为111111
backup:
健康检查脚本的用户为root
优先级为90
vip为172.31.7.49
网卡为eth0
启用认证,认证密码为111111

'''
#master节点配置
[root@master-1 ~]# cat >/etc/keepalived/keepalived.conf <<EOL
global_defs {
   router_id KUB_LVS
   script_user root
   enable_script_security
}
vrrp_script CheckMaster {
    script "curl -k https://172.31.7.49:6443"
    interval 3
    timeout 9
    fall 2
    rise 2
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 61
    priority 100
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 111111
    }
    virtual_ipaddress {
        172.31.7.49 dev eth0
    }
    track_script {
        CheckMaster
    }
}
EOL


#backup节点配置
[root@master-2 ~]# cat >/etc/keepalived/keepalived.conf <<EOL
global_defs {
   router_id KUB_LVS
   script_user root
   enable_script_security
}
vrrp_script CheckMaster {
    script "curl -k https://172.31.7.49:6443"
    interval 3
    timeout 9
    fall 2
    rise 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 61
    priority 90
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 111111
    }
    virtual_ipaddress {
        172.31.7.49 dev eth0
    }
    track_script {
        CheckMaster
    }
}
EOL

3. 重启服务并查看状态

[root@master-1 ~]# systemctl enable keepalived && systemctl restart keepalived

#主节点状态
[root@master-1 ~]# service keepalived status
Redirecting to /bin/systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-05-08 17:32:54 CST; 15s ago
  Process: 1764 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1765 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─1765 /usr/sbin/keepalived -D
           ├─1766 /usr/sbin/keepalived -D
           └─1767 /usr/sbin/keepalived -D

May 08 17:33:00 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:00 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:00 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:00 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:33:01 master-1 Keepalived_vrrp[1767]: Sending gratuitous ARP on eth0 for 172.31.7.49

#备节点状态
[root@master-2 ~]# service keepalived status
Redirecting to /bin/systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-05-08 17:32:48 CST; 13s ago
  Process: 1523 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1524 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─1524 /usr/sbin/keepalived -D
           ├─1525 /usr/sbin/keepalived -D
           └─1526 /usr/sbin/keepalived -D

May 08 17:32:55 master-2 Keepalived_vrrp[1526]: VRRP_Instance(VI_1) setting protocol VIPs.
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: Sending gratuitous ARP on eth0 for 172.31.7.49
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 90
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: VRRP_Instance(VI_1) Entering BACKUP STATE
May 08 17:32:55 master-2 Keepalived_vrrp[1526]: VRRP_Instance(VI_1) removing protocol VIPs.

 

posted on 2021-05-08 17:40  torotoise512  阅读(423)  评论(0)    收藏  举报