解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题

前言

    小编最近在做nginx+keepalived 达到高可用的实验,配置好keepalived后,启动失败,来记录下解决过程。

正文

错误日志

    keepalived 服务启动,查看服务状态,错误信息如下

# 启动keeperalived 服务
sudo service keepalived start
# 查看keepalived 服务状态
systemctl status keepalived.service

解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第1张图片
解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第2张图片

问题解决:

    1、根据提示 输入“ systemctl status keepalived.service” 和“journalctl -xe”查看详情
在这里插入图片描述
    2、输入“journalctl -xe”

    可以看到详细信息“Jan 13 14:00:23 VM_110_5_centos Keepalived[22474]: Unable to find configuration file /etc/keepalived/keepalived.conf (glob returned 3)” ,
    也就是说找不到配置文件了,因为这是keepalive.conf的默认位置,而实际的配置文件位置已经是“/usr/local/etc/keepalived/keepalived.conf”,所以,这里的位置要修改下。
    说明

  • Keepalived默认的配置文件路径在/etc/keepalived/keepalived.conf
  • Keepalived默认的日志文件保存在/var/log/messages

    3、找到修改文件路径的地方
    接下来就是去看 哪里写着 “/etc/keepalived/keepalived.conf”这个东西了,
解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第3张图片
    去 keepalived.service 中可以看到一个路径“/usr/local/etc/sysconfig/keepalived”,顺藤摸瓜,到这个目录下去看看

vim /usr/local/etc/sysconfig/keepalived 

解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第4张图片

    看到 其中写着“ KEEPALIVED_OPTIONS=-D”
    这个就是修改文件路径的关键。
    经过查看资料可以找到更为详细的解释:

/usr/local/keepalived/sbin/keepalived --vrrp -P [Only run with VRRP subsystem.] 
/usr/local/keepalived/sbin/keepalived --check -C [Only run with Health-checker subsystem.] 
/usr/local/keepalived/sbin/keepalived --dont-release-vrrp -V [Dont remove VRRP VIPs & VROUTEs on daemon stop. ]
/usr/local/keepalived/sbin/keepalived --dont-release-ipvs -I [Dont remove IPVS topology on daemon stop. ]
/usr/local/keepalived/sbin/keepalived --dont-fork -n [Dont fork the daemon process. ]
/usr/local/keepalived/sbin/keepalived --use-file -f [Use the specified configuration file. Default is /etc/keepalived/keepalived.conf. ]
/usr/local/keepalived/sbin/keepalived --dump-conf -d [Dump the configuration data. ]
/usr/local/keepalived/sbin/keepalived --log-console -l [Log message to local console. ]
/usr/local/keepalived/sbin/keepalived --log-detail -D [Detailed log messages. ]
/usr/local/keepalived/sbin/keepalived --log-facility -S 0-7 [Set syslog facility to LOG_LOCAL[0-7]. (default=LOG_DAEMON) ]
/usr/local/keepalived/sbin/keepalived --help -h [Display this short inlined help screen. ]
/usr/local/keepalived/sbin/keepalived --version -v [Display the version number ]
/usr/local/keepalived/sbin/keepalived --pid -p [pidfile ]
/usr/local/keepalived/sbin/keepalived --checkers_pid -c [checkers pidfile ]
/usr/local/keepalived/sbin/keepalived --vrrp_pid -r [vrrp pidfile]

    “-D” 就是输出日志的选项,而-f 就是修改默认配置文件路径的。
    4、修改配置文件的默认路径

# 注意到要修改日志文件的默认路径就需要“-S“
-f /usr/local/etc/keepalived/keepalived.conf -D -S 0

解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第5张图片

补充: keepalived.service 中有一个$KEEPALIVED_OPTIONS ,跟这里的KEEPALIVED_OPTIONS 就对上了,所以在输出日志中可以看到“/usr/local/keepalived/keepalived-2.0.10/bin/keepalived -D”的输出
    5、再次尝试启动keepalived服务,发现启动成功
    当出现红框所示内容时,表示启动成功!
    另外:细心的读者应该会发现我红框圈出的部分将keepalived.service 中ExecStart 指向keepalived的启动地址也换了,这个改动可以忽略,维持原来的默认值就好!
    另外 :“systemctl daemon-reload”这一步操作经测试也可以忽略,跳过即可!
解决Keepalived启动“Fail to start LVS and VRRP Avaliability Monitor” 问题_第6张图片

配置systemctl 和 keepalived 服务相关命令

# 重新加载
systemctl daemon-reload  
# 设置开机自动启动
systemctl enable keepalived.service  
# 取消开机自动启动
systemctl disable keepalived.service 
# 启动
systemctl start keepalived.service 
# 停止
systemctl stop keepalived.service

参考连接

https://blog.csdn.net/zhaihaifei/article/details/53841466
https://blog.csdn.net/u013256816/article/details/49356689

疑问

     Mac 系统上可以安装、编译keepalived 源码吗? 我用源码安装的方式还没有成功。。。

总结

    以上就是和keeplived 逐渐熟悉的过程,感谢阅读!

你可能感兴趣的:(【架构】,【linux】)