Keepalived基础知识详细完整总结(6)

server1:第一台节点的keepalived.conf配置. 其中VIP:192.168.20.187
[root@keepalived-node01 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
  notification_email {
    kevin@bobo.com
  }
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id innodb_cluster    #局域网中需要共享该vip的服务器,该配置要一致
  vrrp_skip_check_adv_addr
  vrrp_garp_interval 0
  vrrp_gna_interval 0
}
 
vrrp_instance VI_1 {
    state MASTER      #状态为master,表明 keepalived 启动后会抢占IP,  但,下面的优先级值201要高于 从库的优先级 101
    interface eth0      #viP 绑定的网卡
    virtual_router_id 191  #这个组队标志,同一个vrrp 下的 值一致,主从一致
    priority 201        # 主库为201,高于从库101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.20.187  #这是VIP 值
    }
}
 
vrrp_instance VI_2 {
    state BACKUP    #状态为 BACKUP,表明 keepalived 启动后不抢占IP
    interface eth0  #VIP 绑定的接口
    virtual_router_id 193  #组队标识,同一个vrrp 下的值一致
    priority 101      #设置优先级小于另一个节点的priority 上值。
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 3333
    }
    virtual_ipaddress {
        192.168.20.189
    }
}
 
 
启动keepalived
[root@keepalived-node01 ~]# /etc/init.d/keepalived start
[root@keepalived-node01 ~]# ps -ef|grep keepalived 
root    13746    1  0 16:31 ?        00:00:00 /usr/sbin/keepalived -D
root    13747 13746  0 16:31 ?        00:00:00 /usr/sbin/keepalived -D
root    13748 13746  0 16:31 ?        00:00:00 /usr/sbin/keepalived -D
root    14089 13983  0 16:36 pts/1    00:00:00 grep --color=auto keepalived
 
启动keepalived服务后,查看ip
[root@keepalived-node01 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 2e:ab:68:68:ee:90 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.191/24 brd 192.168.20.255 scope global noprefixroute eth0
      valid_lft forever preferred_lft forever
    inet 192.168.20.187/32 scope global eth0
      valid_lft forever preferred_lft forever
    inet6 fe80::2cab:68ff:fe68:ee90/64 scope link
      valid_lft forever preferred_lft forever
 
 
 
==========================================================================================
server2:第二台节点的keepalived.conf配置. 其中VIP:192.168.20.188
 
[root@keepalived-node02 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
  notification_email {
    kevin@bobo.com
  }
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id innodb_cluster    #局域网中需要共享该vip的服务器,该配置要一致
  vrrp_skip_check_adv_addr
  vrrp_garp_interval 0
  vrrp_gna_interval 0
}
 
vrrp_instance VI_1 {
    state MASTER      #状态为master,表明 keepalived 启动后会抢占IP,  但,下面的优先级值201要高于 从库的优先级 101
    interface eth0      #viP 绑定的网卡
    virtual_router_id 192    #这个组队标志,同一个vrrp 下的 值一致,主从一致
    priority 201          # 主库为201,高于从库101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.20.188  #这是VIP 值
    }
}
 
vrrp_instance VI_2 {
    state BACKUP      #状态为 BACKUP,表明 keepalived 启动后不抢占IP
    interface eth0      #VIP 绑定的接口
    virtual_router_id 191  #组队标识,同一个vrrp 下的值一致
    priority 101      #设置优先级小于另一个节点的priority 上值。
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.20.187
       
    }
}
 
 
启动keepalived
[root@keepalived-node02 ~]# /etc/init.d/keepalived start
[root@keepalived-node02 ~]# ps -ef|grep keepalived
root    13327    1  0 16:32 ?        00:00:00 /usr/sbin/keepalived -D
root    13328 13327  0 16:32 ?        00:00:00 /usr/sbin/keepalived -D
root    13329 13327  0 16:32 ?        00:00:00 /usr/sbin/keepalived -D
root    13570 13529  0 16:39 pts/1    00:00:00 grep --color=auto keepalived
 
 
启动keepalived服务后查看ip
[root@keepalived-node02 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 76:6d:74:97:03:15 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.192/24 brd 192.168.20.255 scope global noprefixroute eth0
      valid_lft forever preferred_lft forever
    inet 192.168.20.188/32 scope global eth0
      valid_lft forever preferred_lft forever
    inet6 fe80::746d:74ff:fe97:315/64 scope link
      valid_lft forever preferred_lft forever
 
 
==========================================================================================
server3:第三台节点的keepalived.conf配置. 其中VIP:192.168.20.189
 
[root@keepalived-node03 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
  notification_email {
    kevin@bobo.com
  }
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id innodb_cluster      #和server1 一致全局唯一
  vrrp_skip_check_adv_addr   
#  vrrp_strict
  vrrp_garp_interval 0
  vrrp_gna_interval 0
}
 
vrrp_instance VI_1 {
    state BACKUP            #主是master,从就是backup
    interface eth0
    virtual_router_id 192        # 组队标识,同一个vrrp 下一致
    priority 101              #优先级也变小
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.20.188 
    }
}
 
vrrp_instance VI_2 {
    state MASTER          #主变成MASTER
    interface eth0          #绑定网卡
    virtual_router_id 193      #组队标志,同一个vip 下一致
    priority 201            #优先级提升
    advert_int 1           
    authentication {
        auth_type PASS
        auth_pass 3333
    }
    virtual_ipaddress {
        192.168.20.189
    }
}
 
 
启动keepalived
[root@keepalived-node03 ~]# /etc/init.d/keepalived start
[root@keepalived-node03 ~]# ps -ef|grep keepalived
root    13134    1  0 16:33 ?        00:00:00 /usr/sbin/keepalived -D
root    13135 13134  0 16:33 ?        00:00:00 /usr/sbin/keepalived -D
root    13136 13134  0 16:33 ?        00:00:00 /usr/sbin/keepalived -D
root    13526 13460  0 16:41 pts/1    00:00:00 grep --color=auto keepalived
 
启动keepalived服务后查看ip
[root@keepalived-node03 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 22:ee:46:41:f0:e6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.193/24 brd 192.168.20.255 scope global noprefixroute eth0
      valid_lft forever preferred_lft forever
    inet 192.168.20.189/32 scope global eth0
      valid_lft forever preferred_lft forever
    inet6 fe80::20ee:46ff:fe41:f0e6/64 scope link
      valid_lft forever preferred_lft forever
 
 
温馨提示:
如上,keepalived.conf配置后,重启keepalived服务,重启成功并且vip地址已经有了,但是死活ping不通vip地址!!
这是因为keepalived.conf文件中的vrrp_strict参数引起的,将该参数注释掉就可以了!!!
 
vrrp_strict  表示严格执行VRRP协议规范,此模式不支持节点单播

VIP地址ping不通,需要注释vrrp_strict参数配置即可!

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1fd103c63a934da4ffd273a8a8abede7.html