Centos7安装Keepalived踩坑

场景:

在Centos7环境下安装keepalived无法启动

问题描述:

安装完keepalived后启动后无法连接
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.137.233' (113)

原因分析:

/etc/keepalived/keepalived.conf配置文件中的虚拟网卡配置问题

首先查看本机ip,用ifconfig命令
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.230  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::1555:31ae:b741:3131  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::3ec1:2fb5:84ca:5ad6  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::f2cb:aef4:bd5a:e867  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:e2:b7:11  txqueuelen 1000  (Ethernet)
        RX packets 7365  bytes 666715 (651.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16057  bytes 28224877 (26.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 371  bytes 73714 (71.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 371  bytes 73714 (71.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

虚拟机网卡名是:enp0s3


解决方案:

将interface 对应的网卡替换成enp0s3即可,virtual_ipaddress中虚拟网卡名也要替换。

vrrp_instance VI_1 {
    state MASTER
    interface enp0s3
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
         192.168.137.200/24 dev enp0s3 label enp0s3:3:
    }
}

你可能感兴趣的:(keepalived)