keepalived 的安装部署及使用详细完整版

news2024/11/27 14:51:47

架构

在这里插入图片描述

1.安装

yum install keepalived -y

systemctl enable keepalived
 
systemctl restart keepalived


systemctl status keepalived

2.部署配置样例

vim /etc/keepalived/keepalived.conf


global_defs {
    router_id PROXYSQL_HA
    script_user root
    enable_script_security
}
vrrp_script chk_proxysql_port {
    script "/etc/keepalived/check_proxysql.sh"
    interval 1
    weight -50
    fall 2
    rise 2
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    mcast_src_ip 192.124.107.129 
    unicast_peer {
        192.124.126.109 

    }
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1qaz2wsx
    }
    virtual_ipaddress {
        192.124.91.241/17 dev eth0 
    }
    track_script {
        chk_proxysql_port
    }
}
            

检查脚本

#!/bin/bash
/bin/netstat -na | grep -e '0.0.0.0:5432' &>/dev/null

全局定义块

这部分主要用来设置Keepalived的故障通知机制和Router ID标识

global_defs {
    router_id PROXYSQL_HA
    script_user root
    enable_script_security
}

VRRP实例定义模块

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    mcast_src_ip 192.124.107.129  #当前机器
    unicast_peer {
        192.124.126.109   #另一台机器

    }
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1qaz2wsx
    }
    virtual_ipaddress {
        192.124.91.241/17 dev eth0   # 设置虚拟ip,主节点自动添加
    }
    track_script {
        chk_proxysql_port
    }
}
  • 如果两节点的上联交换机禁用了组播,则只能采用vrrp单播通告的方式
mcast_src_ip 192.124.107.129  #当前机器
    unicast_peer {
        192.124.126.109   #另一台机器

    }
  • 定义实例名称为VI_1
  • state 表示该实例的角色状态,有MASTER和BACKUP两种主备状态。
  • interface 对外提供服务的网络接口eth0
  • virtual_router_id 虚拟路由ID标识,主备服务器配置中相同实例的ID必须一致,否则将出现脑裂问题。
  • priority表示实例优先级,数字越大,优先级越高。
  • advert_int为同步通知间隔。主备之间通信检查的时间间隔,默认为1秒。
  • authentication 权限认证配置。
  • virtual_ipaddress 虚拟IP地址;可以配置多个IP,每个IP占一行。注意,这里的IP就是在工作中需要和域名绑定的ip,即可配置的高可用服务监听的ip保持一致。

3.切换日志分析

日志查看方式

tail -22f /var/log/messages | grep Keepalived

节点 192.160.200.3开启后备升为主

Nov 14 14:47:52 192-168-3-193 Keepalived[225718]: Starting VRRP child process, pid=225719
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Registering Kernel netlink reflector
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Registering Kernel netlink command channel
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Opening file '/etc/keepalived/keepalived.conf'.
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Assigned address 192.160.200.3 for interface eth0
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Assigned address fe80::f8a0:e0ff:fee8:b800 for interface eth0
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: Registering gratuitous ARP shared channel
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) removing VIPs.
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Entering BACKUP STATE (init)
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: VRRP sockpool: [ifindex(2), family(IPv4), proto(112), unicast(1), fd(11,12)]
Nov 14 14:47:52 192-168-3-193 Keepalived_vrrp[225719]: VRRP_Script(chk_proxysql_port) succeeded
Nov 14 14:51:04 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Backup received priority 0 advertisement
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Receive advertisement timeout
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Entering MASTER STATE
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) setting VIPs.
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.160.100.3
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:05 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:06 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Master received advert from 192.160.220.118 with same priority 100 but higher IP address than ours
Nov 14 14:51:06 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Entering BACKUP STATE
Nov 14 14:51:06 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) removing VIPs.
Nov 14 14:51:51 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) received lower priority (50) advert from 192.160.220.118 - discarding
Nov 14 14:51:52 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) received lower priority (50) advert from 192.160.220.118 - discarding
Nov 14 14:51:53 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) received lower priority (50) advert from 192.160.220.118 - discarding
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Receive advertisement timeout
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Entering MASTER STATE
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) setting VIPs.
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.160.100.3
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:54 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: (VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:51:59 192-168-3-193 Keepalived_vrrp[225719]: Sending gratuitous ARP on eth0 for 192.160.100.3


节点 192.160.220.118开启后主降为备

关掉服务触发

Nov 14 14:47:51 192-160-220-118 Keepalived[20622]: Starting Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
Nov 14 14:47:51 192-160-220-118 Keepalived[20622]: Opening file '/etc/keepalived/keepalived.conf'.
Nov 14 14:47:51 192-160-220-118 Keepalived[20623]: Starting Healthcheck child process, pid=20624
Nov 14 14:47:51 192-160-220-118 Keepalived[20623]: Starting VRRP child process, pid=20625
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: Registering Kernel netlink reflector
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: Registering Kernel netlink command channel
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: Registering gratuitous ARP shared channel
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: Opening file '/etc/keepalived/keepalived.conf'.
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) removing protocol VIPs.
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: Using LinkWatch kernel netlink reflector...
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Nov 14 14:47:51 192-160-220-118 Keepalived_healthcheckers[20624]: Opening file '/etc/keepalived/keepalived.conf'.
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Script(chk_proxysql_port) succeeded
Nov 14 14:47:51 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Transition to MASTER STATE
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Entering MASTER STATE
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) setting protocol VIPs.
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.160.100.3
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:52 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:47:57 192-160-220-118 Keepalived_vrrp[20625]: Sending gratuitous ARP on eth0 for 192.160.100.3
Nov 14 14:48:34 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:35 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:35 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Script(chk_proxysql_port) failed
Nov 14 14:48:36 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Changing effective priority from 100 to 50
Nov 14 14:48:36 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:37 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:38 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:39 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:39 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 50
Nov 14 14:48:39 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) Entering BACKUP STATE
Nov 14 14:48:39 192-160-220-118 Keepalived_vrrp[20625]: VRRP_Instance(VI_1) removing protocol VIPs.
Nov 14 14:48:40 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:41 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:42 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:43 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:44 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1
Nov 14 14:48:45 192-160-220-118 Keepalived_vrrp[20625]: /etc/keepalived/check_proxysql.sh exited with status 1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1207659.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

js案例:跟随鼠标移动的大虫子

目录 效果预览图 整体思路 完整代码 效果预览图 整体思路 rang 函数用于生成指定范围内的随机整数。 通过循环,创建了50个div元素,每个div都有一个不同的数字和随机的背景颜色。 给每个div元素添加了名为 "ball" 的类名。 通过 documen…

为什么说葡萄酒越复杂,越有可能陈年?

大家都觉得老酒更好,对吧?一瓶酒在黑暗的洞穴里放得越久,瓶子慢慢积灰,我们喝的时候就越好喝,对吗?其实是不对的!葡萄酒陈酿的根本原因是为了让它的味道更好,或者更确切地说让风味发…

一文懂得电源模块过温保护测试方法 ate测试软件助力测试

过温保护测试是电源模块保护功能测试项目之一,也是电源模块测试的重要测试指标,以保证电源模块过温保护功能正常,确保电源模块不受损坏。用ate测试软件测试电源模块过温保护,不仅可以保证测试结果的准确性,还可以多维度…

SAP 70策略测试简介

在前面的文章中我们已经测试了10、11、20、40、50、52、60、62策略的测试,接下来我们需要对70策略进行测试,很多的项目中也都会用到70策略。 70策略是一种比较常见的、基于按库存且主要用于半成品或者原材料的计划策略。 我们还是按照之前的惯例,先看下70策略的后台配置 我…

书单 | 11月程序员新书播报

11月最新上架计算机书籍 1、人工智能(第3版) 美国经典人工智能教材第3版,人工智能的百科全书,新增深度学习及人工智能编程等内容,理论阐释结合动手实践,附赠PPT课件、配套视频及代码文件。 1.人工智能经典…

Linux线程池

文章目录: 线程池了解线程池模拟实现 线程池了解 线程池是一种常见的线程使用模式。线程过多会带来调度开销,进而影响缓存局部性和整体性能。而线程池维护着多个线程,等待着监督管理者分配可并发执行的任务,以避免在处理短时间任…

Python爬虫过程中DNS解析错误解决策略

在Python爬虫开发中,经常会遇到DNS解析错误,这是一个常见且也令人头疼的问题。DNS解析错误可能会导致爬虫失败,但幸运的是,我们可以采取一些策略来处理这些错误,确保爬虫能够正常运行。本文将介绍什么是DNS解析错误&am…

JLMR Micro Super Resolution Algorithm国产微超分算法DEMO

一、简介 目前,做超分算法基本还是以AI训练为主,但是AI基本上都是基于既定场景的训练。而传统的算法基本上都是利用上下文的纹理预测、插值等方案,在图像放大过程中会出现模糊,或马赛克等现象。 我们基于加权概率模型&#xff0c…

后端接口性能优化分析-1

👏作者简介:大家好,我是爱吃芝士的土豆倪,24届校招生Java选手,很高兴认识大家📕系列专栏:Spring源码、JUC源码🔥如果感觉博主的文章还不错的话,请👍三连支持&…

SQLite3 数据库学习(一):数据库和 SQLite 基础

参考引用 SQL 必知必会SQLite 权威指南(第二版)关系型数据库概述 1. 数据库基础 1.1 什么是数据库 数据库(database):保存有组织的数据的容器(通常是一个文件或一组文件) 可以将其想象为一个文…

谷歌提出AGI的6大原则,和5大能力等级

随着ChatGPT等大模型的出现,AGI概念正在从哲学层面快速转向实际应用落地,并且ChatGPT已经展示出了初级AGI的功能(如AutoGPT),有不少专家认为,AGI时代可能在10年内到来。 因此,需要一个明确的技术框架来讨论和衡量不同…

图片转excel的三种方案(电脑、手机)

图片怎么转换成excel文件呢?用金鸣表格文字识别是最便捷、最佳的解决方案。也许有些同学会问,那我用手工也可以解决呀,干吗要用软件?这么想就不对了,手工做不但要做表格线,还要手工打字,非常麻烦,而且容易出错,特别是对于数字多的图片,更是要命,现在有金鸣识别就不用那么麻烦…

python读取excel,进行数据处理

一、准备python编译器 二、下载 pyexcel 库 pip install pyexcel-xls三、进行编码读取数据 import pyexcel# 读取Excel文件 成本中心字典 data pyexcel.get_array(file_name成本中心.xls)def hand():#打印数据#print(data)url f"INSERT INTO dst_base.sys_dict(p_…

efcore反向共工程,单元测试

1.安装efcore需要的nuget <PackageReference Include"Microsoft.EntityFrameworkCore" Version"6.0.24" /> <PackageReference Include"Microsoft.EntityFrameworkCore.SqlServer" Version"6.0.24" /> <PackageRefere…

评论:AlexNet和CaffeNet有何区别?

一、说明 在这个故事中&#xff0c;我们回顾了AlexNet和CaffeNet。AlexNet 是2012 年ILSVRC&#xff08;ImageNet 大规模视觉识别竞赛&#xff09;的获胜者&#xff0c;这是一项图像分类竞赛。而CaffeNet是AlexNet的单GPU版&#xff0c;因此&#xff0c;我们平时在普通电脑的Al…

Fortinet 聚焦核心业务增长领域,巩固网安市场领导地位,持续推动行业创新

近日&#xff0c;专注于推动网络与安全融合的全球网络安全领导者 Fortinet&#xff08;NASDAQ&#xff1a;FTNT&#xff09;发布第三季度财报。同期&#xff0c;Fortinet做出重大战略宣布&#xff0c;未来将重点聚焦高速增长的差异化市场。Fortinet 将紧紧围绕安全组网、Univer…

中馥集团双11当日发货销售额突破1000万!

昨日&#xff0c;中馥集团双十一当日发货销售额突破1000万&#xff0c;再创新高&#xff01;双十一大促期间&#xff0c;中馥集团全体上下通力合作&#xff0c;每场直播商品经层层筛选、严格评选的“名品”&#xff0c;既有优质精品文化酒&#xff0c;也有市场火爆的高端酱酒&a…

【java学习—十四】Class类(2)

文章目录 1. Class类2. Class类的常用方法3. 实例化Class类对象&#xff08;四种方法&#xff09; 1. Class类 在 Object 类中定义了以下的方法&#xff0c;此方法将被所有子类继承&#xff1a; public final Class getClass() 以上的方法返回值的类型是一个 Class 类&#xf…

vue2中使用Markdown编辑器

这里写自定义目录标题 欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题&#xff0c;有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants 创建一个自定义列表如何创建一个…

Linux必备基础命令,JAVA程序员必备

目录 一、了解基本的左侧栏什么意思​编辑 二、ls&#xff0c;ll&#xff08;list&#xff0c;查找目录内容) 三、cd(change directory&#xff0c;切换目录) 小技巧&#xff0c;我们在查找东西的时候&#xff0c;可以使用tab进行智能补全。 四、touch&#xff08;建立文件…