文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

keepalived 1.3.5的常见配置是什么以及常见问题的解决方法

2023-06-05 14:21

关注

keepalived 1.3.5的常见配置是什么以及常见问题的解决方法,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

1. keepalived配置及说明

1.1 安装

 [root@mysql01 keepalived] tar -zxvf keepalived-1.3.5.tar.gz

 [root@mysql01 keepalived] cd keepalived-1.3.5/

 [root@mysql01 keepalived] ./configure --help|grep prefix

 [root@mysql01 keepalived] ./configure --prefix=/usr/local/keepalived

 [root@mysql01 keepalived] make && make install

 [root@mysql01 keepalived] cd /usr/local/keepalived

 [root@mysql02 keepalived]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

 [root@mysql01 keepalived]# cp etc/sysconfig/keepalived /etc/sysconfig/

如果是Linux 6还需要拷贝下面文件:

 [root@mysql01 keepalived] cp /tmp/keepalived-1.3.2/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/

1.2 修改keepalived日志输出

vi /usr/lib/systemd/system/keepalived.service

# 确认下面两个变量指向正确的可执行keepalived

EnvironmentFile

ExecStart

vi /etc/sysconfig/keepalived

修改keepalived日志输出设备为0号设备,并修改系统日志程序0号输出设备输出文件,以及添加dump配置文件数据。

vi /etc/keepalived/keepalived.conf

KEEPALIVED_OPTIONS="-D -d -S 0"

# 修改keepalived使用0号日志输出设备,并单独输出日志到指定文件。

vi /etc/rsyslog.conf

local0.*                /usr/local/keepalived/log/keepalived.log

1.3 修改keepalived配置文件

# 编辑keepalived配置文件,配置vip以及服务监测,通知脚本等模块。

vi /etc/keepalived/keepalived.conf

vrrp_script check_run {

    script "/etc/keepalived/scripts/keepalived_check_mysql.sh"

    interval 30

    weight 0

}

vrrp_instance VI_1 {

    state BACKUP

    nopreempt

    interface team0           # 网卡,根据实际情况填写

    virtual_router_id 88        # 主备机器id必须相同,不同vrrp_instance需要不同。

    priority 101

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.204.88     # 虚拟IP

    }

    track_script {

        check_run

    }

         notify_master /etc/keepalived/scripts/notify_master.sh

  }

1.4 keepalived.conf说明

l  Notify  scripts

that  are  run when a vrrp instance or vrrp group

changes state, or a virtual server quorum changes between up and down.

# global script_user and script_group to MASTER transition

notify_master /path/to_master.sh [username [groupname]]

l  vrrp tracking scripts

that will cause vrrp instances to go down  it

they exit a non-zero exist status, or if a weight is specified will add

or subtract the weight to/from the priority of that vrrp instance.

l  nopreempt

A higher priority VRRP instance will normally preempt a lower priority instance

when it comes online.  "nopreempt" stops the higher priority machine taking

over the master role, and allows the lower priority machine to remain as

master.

NOTE: For this to work, the initial state must not be MASTER.

1.5 启动keepalived

启用keepalived服务,启动keepalived服务:

systemctl enable keepalived

systemctl start keepalived

2. 问题

2.1 not a regular non-executable file

l  现象

[root@mysql01 ~]# systemctl status keepalived.service
May  7 17:12:51 mysql01 Keepalived[5467]: Configuration file '/etc/keepalived/keepalived.conf' is not a regular non-executable file

l  原因

/etc/keepalived/keepalived.conf文件权限不是664。

l  解决

修改/etc/keepalived/keepalived.conf权限为664即可。

2.2 Cannot find an IP address to use for interface

l  现象

[root@mysql01 ~]# systemctl status keepalived.service
May 07 17:41:14 mysql01 Keepalived_vrrp[9448]: (VI_1): Cannot find an IP address to use for interface enp0s9

l  原因

/etc/keepalived/keepalived.conf配置文件中interface模块,网卡上没有IP地址,

l  解决

可以通过添加临时IP来解决,或者在keepalived版本2.0.5之后添加dynamic_interfaces

[root@mysql01 ~]# ifconfig eth2 172.16.20.101/16 up
eth2配置IP,因为如果接口没有IP,keepalived将以FAULT状态启动,keepalived 2.0.5以上版本,只需将dynamic_interfaces添加到global_defs即可

2.3 NetworkManager导致keepalived无法启动

l  现象

[root@mysql01 ~]# tail -f /var/log/messages

May  7 11:07:15 mysql01 Keepalived[8755]: daemon is already running

May  7 11:07:15 mysql01 systemd: PID file /usr/local/var/run/keepalived.pid not readable (yet?) after start.

May  7 11:08:45 mysql01 systemd: keepalived.service start operation timed out. Terminating.

May  7 11:08:45 mysql01 systemd: Failed to start LVS and VRRP High Availability Monitor.

May  7 11:08:45 mysql01 systemd: Unit keepalived.service entered failed state.

May  7 11:08:45 mysql01 systemd: keepalived.service failed.

l  原因

NetworkManager自动管理网络,keepalived使用虚拟IP无法绑定到指定接口,日志中报错又无法定位原因,提前关闭NetworkManager,手工设置网卡ip地址即可。

l  解决

[root@mysql01 ~]# systemctl disable NetworkManager

[root@mysql01 ~]# systemctl stop NetworkManager

2.4 VRRP_Instance(VI_1) Now in FAULT state

l  现象

[mysql@mysql01 65mysql]$ sudo systemctl status keepalived

May 07 19:06:08 mysql01 Keepalived_vrrp[16144]: VRRP_Instance(VI_1) Entering BACKUP STATE

May 07 19:06:08 mysql01 Keepalived_vrrp[16144]: VRRP sockpool: [ifindex(4), proto(112), unicast(0), fd(10,11)]

May 07 19:06:12 mysql01 Keepalived_vrrp[16144]: VRRP_Instance(VI_1) Now in FAULT state

l  原因

/etc/keepalived/keepalived.conf配置文件vrrp_script模块脚本未检查,返回总是非0错误值,导致keepalived状态一直无法完成初始化,无法绑定vip。

l  解决

修正脚本错误,重启keepalived。

2.5 failed because a timeout was exceeded

●现象

[mysql@mysql02 keepalived]$ sudo systemctl status keepalived

keepalived.service - LVS and VRRP High Availability Monitor

   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)

   Active: failed (Result: timeout) since Thu 2020-05-07 20:44:08 CST; 14min ago

  Process: 31073 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

    Tasks: 6

   CGroup: /system.slice/keepalived.service

           ├─ 2687 /usr/local/keepalived/sbin/keepalived -D -d -S 0

           ├─ 2688 /bin/bash /etc/keepalived/scripts/keepalived_check_mysql.sh

           ├─ 2815 sleep 2

           ├─25921 /usr/local/keepalived/sbin/keepalived -D -d -S 0

           ├─25922 /usr/local/keepalived/sbin/keepalived -D -d -S 0

           └─25923 /usr/local/keepalived/sbin/keepalived -D -d -S 0

May 07 20:42:38 mysql02 systemd[1]: Starting LVS and VRRP High Availability Monitor...

May 07 20:42:38 mysql02 systemd[1]: PID file /var/run/keepalived.pid not readable (yet?) after start.

May 07 20:44:08 mysql02 systemd[1]: keepalived.service start operation timed out. Terminating.

May 07 20:44:08 mysql02 systemd[1]: Failed to start LVS and VRRP High Availability Monitor.

May 07 20:44:08 mysql02 systemd[1]: Unit keepalived.service entered failed state.

May 07 20:44:08 mysql02 systemd[1]: keepalived.service failed.

[mysql@mysql02 keepalived]$ sudo systemctl start keepalived

Job for keepalived.service failed because a timeout was exceeded. See "systemctl status keepalived.service" and "journalctl -xe" for details.

l  原因

原来keepalived程序运行不正常,无法继续,systemctl restart keepalived已经无法正确重启keepalived。

l  解决

[mysql@mysql02 ~]$ ps -ef|grep keepalived

kill掉所有keepalived进程,重启keepalived

[mysql@mysql02 ~]$ sudo systemctl restart keepalived.service

[mysql@mysql02 ~]$ sudo systemctl status keepalived.service

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网行业资讯频道,感谢您对编程网的支持。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     801人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     348人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     311人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     432人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     220人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯