鸦鸦 发表于 2018-12-29 13:45:49

keepalived双实例配置

  一、keepalived双实例
  keepalived在master/backup工作模式下,会有一个主机处于闲置,所以keepalived可以使用vrrp的特性配置双master模式,使资源最大化。
      1、承接上文配置 --->keepalived基础配置
      2、双主配置
  第一个节点:
# grep -Ev '#|^$' keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
root@localhost
   }
   notification_email_from kaadmin@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id Nginx
}
vrrp_script chk_maintance {
    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
    interval 1
    weight -2
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 51ea2a78
    }
    virtual_ipaddress {
      192.168.0.80/24 label eth0:0
    }
    track_script {
chk_maintance
    }
}
vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52               #id必须修改
    priority 90
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass abcdefg            #认证字符串必须修改为不一致
    }
    virtual_ipaddress {
      192.168.0.90/24 label eth0:1
    }
    track_script {
chk_maintance
    }
}  第二个节点:
# !egrep
egrep -v '#|^$' keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
root@localhost
   }
   notification_email_from kaadmin@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node1
}
vrrp_script chk_maintance {
    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
    interval 1
    weight -2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 51ea2a78
    }
    virtual_ipaddress {
      192.168.0.80/24 label eth0:0
    }
    track_script {
chk_maintance
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass abcdefg
    }
    virtual_ipaddress {
      192.168.0.90/24 label eth0:1
    }
    track_script {
chk_maintance
    }
}  

  配置结果

# service keepalived restart; ssh node1 'service keepalived restart'
# ip addr | grep eth0
2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.80/24 scope global secondary eth0:0
# ip addr | grep eth0
2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.40/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.90/24 scope global secondary eth0:1  

  3、测试
调度
# service keepalived stop
停止 keepalived:                                          [确定]
# ip add | grep eth0
2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0
# ip add | grep eth0
2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.40/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.90/24 scope global secondary eth0:1
    inet 192.168.0.80/24 scope global secondary eth0:0
抢回
# service keepalived start
正在启动 keepalived:                                    [确定]
# ip add | grep eth0
2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.80/24 scope global secondary eth0:0  




页: [1]
查看完整版本: keepalived双实例配置