美文网首页Kubernetes 安装
CentOS 安装 Keepalive 实现节点高可用

CentOS 安装 Keepalive 实现节点高可用

作者: Danielme | 来源:发表于2019-07-14 20:50 被阅读0次

    假设现在需要在2台 Centos 服务器(192.168.1.101,192.168.1.102)上安装Keepalive,实现高可用(VIP 192.168.1.201)。

    1. 安装 keepalived
      yum install -y keepalived
      
    2. 修改主节点 keepalived 配置
      cat <<EOF > /etc/keepalived/keepalived.conf    
      global_defs {
         router_id MASTER01           #实例ID,唯一
      }
      vrrp_instance VI_1 {
          state MASTER                #设置主备状态
          interface enp0s3            #绑定网卡
          virtual_router_id 129       #分组ID(0-255),主备必须相同
          priority 100                #优先级,主节点值更高
          advert_int 1                #VRRP Multicast广播周期秒数
          authentication {            #认证方式
              auth_type PASS
              auth_pass 123456
          }
          virtual_ipaddress {         #VIP设置
              192.168.1.244
          }
      }
      EOF
      
    3. 修改备节点 keepalived 配置
      cat <<EOF > /etc/keepalived/keepalived.conf    
      global_defs {
         router_id MASTER02           #实例ID,唯一
      }
      vrrp_instance VI_1 {
          state BACKUP                #设置主备状态
          interface enp0s3            #绑定网卡
          virtual_router_id 129       #分组ID(0-255),主备必须相同
          priority 98                 #优先级,备节点值更低
          advert_int 1                #VRRP Multicast广播周期秒数
          authentication {            #认证方式
              auth_type PASS
              auth_pass 123456
          }
          virtual_ipaddress {         #VIP设置
              192.168.1.244
          }
      }
      EOF
      
    4. 注册 keepalived 服务
      systemctl enable keepalived
      systemctl restart keepalived
      
    5. 使用ping VIP方式测试,期间可以重启主节点,可以看到ping不会报错,在不到1毫秒内完成切换
      ping 192.168.1.244
      PING 192.168.1.244 (192.168.1.244) 56(84) bytes of data.
      64 bytes from 192.168.1.244: icmp_seq=13 ttl=64 time=0.061 ms
      64 bytes from 192.168.1.244: icmp_seq=14 ttl=64 time=0.063 ms
      64 bytes from 192.168.1.244: icmp_seq=15 ttl=64 time=0.061 ms
      64 bytes from 192.168.1.244: icmp_seq=16 ttl=64 time=0.070 ms
      64 bytes from 192.168.1.244: icmp_seq=17 ttl=64 time=0.130 ms
      64 bytes from 192.168.1.244: icmp_seq=18 ttl=64 time=0.115 ms
      64 bytes from 192.168.1.244: icmp_seq=19 ttl=64 time=0.065 ms
      64 bytes from 192.168.1.244: icmp_seq=20 ttl=64 time=0.110 ms
      64 bytes from 192.168.1.244: icmp_seq=21 ttl=64 time=0.057 ms
      64 bytes from 192.168.1.244: icmp_seq=22 ttl=64 time=0.089 ms
      

    相关文章

      网友评论

        本文标题:CentOS 安装 Keepalive 实现节点高可用

        本文链接:https://www.haomeiwen.com/subject/jyfikctx.html