keepalived双实例配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived双实例配置相关的知识,希望对你有一定的参考价值。

一、keepalived双实例

       keepalived在master/backup工作模式下,会有一个主机处于闲置,所以keepalived可以使用vrrp的特性配置双master模式,使资源最大化。

    1、承接上文配置 --->  keepalived基础配置

    2、双主配置

第一个节点:

[[email protected] keepalived]# grep -Ev ‘#|^$‘ keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   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
    }
}

第二个节点:

[[email protected] keepalived]# !egrep
egrep -v ‘#|^$‘ keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   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
    }
}


配置结果

[[email protected] keepalived]# service keepalived restart; ssh node1 ‘service keepalived restart‘
[[email protected] keepalived]# ip addr | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
    
[[email protected] keepalived]# ip addr | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> 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、测试

调度
[[email protected] keepalived]# service keepalived stop
停止 keepalived:                                          [确定]
[[email protected] keepalived]# ip add | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0
[[email protected] keepalived]# ip add | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
    
抢回
[[email protected] keepalived]# service keepalived start
正在启动 keepalived:                                      [确定]
[[email protected] keepalived]# ip add | grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> 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


本文出自 “linux启航” 博客,请务必保留此出处http://jiayimeng.blog.51cto.com/10604001/1896830

以上是关于keepalived双实例配置的主要内容,如果未能解决你的问题,请参考以下文章

Keepalived 双实例双主模式配置

【keepalived】keepalived vrrp 双实例

Keepalived 高可用集群

Keepalived

Nginx+keepalived双主配置(双机双主热备)

Keepalived+Nginx双机主备配置实践