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

架构

在这里插入图片描述

1.安装

yum install keepalived -ysystemctl enable keepalivedsystemctl restart keepalivedsystemctl status keepalived

2.部署配置样例

vim /etc/keepalived/keepalived.conf


global_defs {router_id PROXYSQL_HAscript_user rootenable_script_security
}
vrrp_script chk_proxysql_port {script "/etc/keepalived/check_proxysql.sh"interval 1weight -50fall 2rise 2
}
vrrp_instance VI_1 {state MASTERinterface eth0mcast_src_ip 192.124.107.129 unicast_peer {192.124.126.109 }virtual_router_id 50priority 100advert_int 1authentication {auth_type PASSauth_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_HAscript_user rootenable_script_security
}

VRRP实例定义模块

vrrp_instance VI_1 {state MASTERinterface eth0mcast_src_ip 192.124.107.129  #当前机器unicast_peer {192.124.126.109   #另一台机器}virtual_router_id 50priority 100advert_int 1authentication {auth_type PASSauth_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.rhkb.cn/news/191580.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

卫星通信和800MHz双管齐下,中国电信对中国移动发起新挑战

依靠国内某科技企业的宣传,卫星通信大热,中国电信也由此成为受益者,日前中国电信又大举招标25万座800MHz 5G基站,显示出中国电信积极以技术优势挑战中国移动。 一、中国电信急起直追 自从4G时代以来,中国电信就在国内通…

怎么用Postman脚本中发送请求

Postman的Collection(集合)/Folder(集合的子文件夹)/Request(请求)都有Pre-request script和Tests两个脚本区域, 分别可以在发送请求前和请求后使用脚本(基于Javascript实现各种操作) 在遇到有依赖的接口时,比如需要登录或者需要从前一个接口的结果中获取参数时,我们往往需要在…

使用Docker本地安装部署Drawio绘图工具并实现公网访问

目录 前言 1. 使用Docker本地部署Drawio 2. 安装cpolar内网穿透工具 3. 配置Draw.io公网访问地址 4. 公网远程访问Draw.io 前言 提到流程图,大家第一时间可能会想到Visio,不可否认,VIsio确实是功能强大,但是软件为收费&…

ChatGPT-4:OpenAI的革命性升级

在人工智能领域,OpenAI这家公司凭借其创新性的技术,成为了备受瞩目的领导者。他们最近发布的ChatGPT-4,以其卓越的语言处理能力和先进的模型架构,引领了语言模型领域的革命性升级。 ChatGPT-4的模型容量相较于前一版本有了显著的提…

Jmeter之Bean shell使用详解

一、什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法; BeanShell是一种松散类型的脚本语言(这点和JS类似); BeanShell是用Java写成的,一个小型的、免费的、可以下载的、嵌入式的Java源代码解释器,具有对象脚本语言特性,非常精…

stable diffusion为什么能用于文本到图像的生成

推荐基于稳定扩散(stable diffusion) AI 模型开发的自动纹理工具: DreamTexture.js自动纹理化开发包 - NSDT 稳定扩散获得如此多关注的原因 如果你还没有看过它:稳定扩散是一个文本到图像的生成模型,你可以输入一个文本提示,比如…

Project IDX简介——这是一项改进全栈、多平台应用程序开发的试验

如今,将应用程序从零开发到生产环境(尤其是在移动、网络和桌面平台上运行良好的应用程序)感觉就像构建一台 Rube Goldberg 机器。您必须在无尽的复杂性海洋中航行,将各种技术堆栈粘合在一起,以引导、编译、测试、部署和…

Elasticsearch7 入门 进阶

1、全文检索 1.1、数据分类 按数据分类的话,主要可以分为以下三类: 结构化数据:固定格式、有限长度,比如mysql存的数据非结构化数据:不定长、无固定格式,比如邮件、Word文档、日志等半结构化数据&#xf…

许战海方法论新成果《全球产业技术品牌竞争战略》研究报告正式发布

在全球化趋势下,产业技术正在加速迭代、产业结构也在持续优化。企业要想从愈发激烈的市场竞争中脱颖而出,需要更强大的竞争力。 在全球产业研究项目中,许战海咨询深入剖析了潍柴动力、利乐、奥迪、霍尼韦尔等一众在产业竞争中脱颖而出的企业…

高速高精运动控制,富唯智能AI边缘控制器助力自动化行业变革

随着工业大数据时代的到来,传统控制与决策方式无法满足现代数字化工厂对工业大数据分析与决策的需求,AI边缘控制器赋能现代化智慧工厂,实现工业智造与行业变革。 富唯智能AI边缘控制器,基于x86架构的IPC形态产品,通过…

C#中数组、ArrayList与List对象的区别及使用场景

在C#编程中,数组、ArrayList和List对象是常用的数据结构和容器。它们在存储和管理数据方面都有各自的特点和用途。本文将深入探讨这三者的区别,并通过实际的代码示例来说明它们的使用场景和优缺点。 目录 1.数组特点使用场景 2.ArrayList特点使用场景 3.…

Java数据结构

Java 数据结构 数据结构主要包括以下几种接口和类: 枚举(Enumeration) 接口定义了一种从数据结构中取回连续元素的方式。 nextElement 的方法,该方法用来得到一个包含多元素的数据结构的下一个元素。 位集合(BitSet…

提高软件测试覆盖率的5个重点

软件测试覆盖率是软件测试中的一个重要指标,它有利于保障软件质量、提高软件可靠性和可维护性。软件测试覆盖率能够发现并修复代码缺陷,确保代码的正确性,提高软件的稳定性,降低成本和风险。 因此进一步提高软件测试覆盖率对于软件…

【RPC】前传

前传 本地程序用的go语言,想把main.go程序当中一些计算工作放到服务器上进行,而只需要把结果给我即可。由于平台上暂时不能运行Go代码,所以写的是python文件。 1、主要是使用ssh依赖进行连接,但是大概率是需要手动添加的&#xf…

Netty入门指南之NIO 粘包与半包

作者简介:☕️大家好,我是Aomsir,一个爱折腾的开发者! 个人主页:Aomsir_Spring5应用专栏,Netty应用专栏,RPC应用专栏-CSDN博客 当前专栏:Netty应用专栏_Aomsir的博客-CSDN博客 文章目录 参考文献前言问题产…

线性代数-Python-05:矩阵的逆+LU分解

文章目录 1 矩阵的逆1.1 求解矩阵的逆 2 初等矩阵2.1 初等矩阵和可逆性 3 矩阵的LU分解3.1 LU分解的实现 1 矩阵的逆 1.1 求解矩阵的逆 def inv(A):if A.row_num() ! A.col_num():return Nonen A.row_num()"""矩阵A单位矩阵"""ls LinearSyste…

相机以及其它传感器传感器

深度相机点云质量对比 比较点云质量时需要注意的点: 1.对特殊材质、颜色的检测效果:透明塑料、金属、毛玻璃、高反光物体(镜子、水坑)、吸光物体(黑色物体)。 2.特殊环境:雨、雪、雾、明暗交替位…

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

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

Revit 平面的圆弧,空间的椭圆弧

大家对Revit的空间曲线那么理解,如何用代码创建空间的椭圆弧,,上看是圆弧,正面看是椭圆? 直接放代码: Document doc = commandData.Application.ActiveUIDocument.Document; Autodesk.Revit.DB.XYZ center = new Autodesk.Revit.DB.XYZ(0, 0, 0); …

%与floormod方法区别

%求余数 计算步骤: 10 / -3 -3.333333........... %是向0方向取整,因此-3.3333.......取整数-3 10 % -3 10-(-3*-3) 1 floormod方法 计算步骤:floormod(10,-3) floormod是向负无穷方向取整,因此-3…