openstack私有云布署实践【3 keepalive配置(VRRP虚IP)】

时间:2021-11-12 14:15:10
这里只用到keepalived 或者pacemaker两种方法,可二选一来配置,官方提供的是pacemaker,但我们实际测试环境和生产环境上使的是keepalive
 
 
首先在4台controller上安装包(kxcontroller1 \ kxcontroller2 \ controller1 \ controller2 )
yum -y install gcc openssl-devel popt-devel keepalived pcre-devel
 
配置 keepalived(防止局域网内不与keepalived组冲突的,可更改默认router_id LVS_DEVEL与 virtual_router_id 51  的值)
 
 
我以办公网测试环境的2台controller的配置为例,科兴网的配置类同,只是IP不一样而已
 
 /etc/keepalived/keepalived.conf-- 配置说明
 
内容:
! Configuration file for keepalived
global_defs {
   notification_email {
#用来接收的邮件
               noc-xxx@qq.com
        }
#用来发送提醒的邮件
   notification_email_from noc-xxx@qq.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVE
}
 
vrrp_instance VI_1 {
#均采用BACKUP 防止相互抢占
    state BACKUP
#监听的网卡名
    interface eth0或bond0
    virtual_router_id 52
#本机IP
    mcast_src_ip 10.40.42.1
#权重  -- 主的权重要大于备的
    priority 49
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass chtopnet
    }
    virtual_ipaddress {
#分配VIP
        10.40.42.10
    }
}
 
配置样例
[root@controller1 ~]# vi  /etc/keepalived/keepalived.conf
! Configuration file for keepalived
global_defs {
   notification_email {
               noc-xxx@qq.com
        }
   notification_email_from noc-xxx@qq.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEi
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eno1
    virtual_router_id 52
    mcast_src_ip 10.40.42.1
    priority 40
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass chtopnet
    }
#分配VIP
    virtual_ipaddress {
        10.40.42.10
    }
}
 
 
[root@controller2 ~]# cat  /etc/keepalived/keepalived.conf
! Configuration file for keepalived
global_defs {
   notification_email {
               noc-xxx@qq.com
        }
   notification_email_from noc-xxx@qq.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEi
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eno1
    virtual_router_id 52
    mcast_src_ip 10.40.42.2
    priority 50
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass chtopnet
    }
    virtual_ipaddress {
        10.40.42.10
    }
}
 
 
启动keepalived服务
service keepalived start
chkconfig keepalived on
 
如果配置,由于controller2的权重比controller1大,同时开启服务器,controller2会获取VIP,但因为我配置禁止抢占VIP的配置,所以你的服务是先后启动的话,VIP会先分到第1台启动的controller上,只有主动切换后VIP才会重新选举
 
切换测试VIP,
使用ip addr 命令查看当前的VIP使用在哪一台机器,一边长PING这个VIP,一边关闭交换机的端口,再实时使用ip addr 这条linux命令查看是否切换
PS:如果发现你的VIP在2台controller上都同时看到的话,应该及时查看/var/log/message日志,一般是由于没有关闭防火墙或者selinux而导致的。