当前位置:网站首页>keepalived实现mysql的高可用
keepalived实现mysql的高可用
2022-07-25 11:23:00 【托塔天王李】
keeplived实现mysql高可用
前提条件
两台server都安装了mariadb
server1: 10.243.68.158
server2: 10.243.68.159
virtual ip:10.243.68.160
安装keepalived
下载keepalived的rpm包:keepalived-1.3.5-8.el7_6.x86_64.rpm
安装keeepalived
[[email protected] ~]# ll
total 356
-rw-r--r--. 1 root root 210 Feb 25 03:33 chk_rtm.sh
-rw-r--r--. 1 root root 336976 Feb 25 03:33 keepalived-1.3.5-8.el7_6.x86_64.rpm
-rw-r--r--. 1 root root 690 Feb 25 03:33 keepalived.conf
-rw-r--r--. 1 root root 1113 Feb 25 03:33 my.cnf
-rw-r--r--. 1 root root 10249 Feb 25 03:33 zabbix_agentd.conf
[[email protected] ~]# rpm -ivh keepalived-1.3.5-8.el7_6.x86_64.rpm
warning: keepalived-1.3.5-8.el7_6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:keepalived-1.3.5-8.el7_6 ################################# [100%]
[[email protected] ~]#
配置keepalived
配置10.243.68.158 server的配置修改文件 /etc/keepalived/keepalived.conf 如下:
[[email protected] ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server root
smtp_connect_timeout 30
router_id RTM #负载均衡标识,在局域网内应该是唯一的。
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_rtm {
script "/etc/keepalived/chk_rtm.sh"
interval 3
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface enp0s3 #网卡
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_rtm
}
virtual_ipaddress {
10.243.68.160
}
}
配置10.243.68.159 server的配置修改文件 /etc/keepalived/keepalived.conf 如下:
[[email protected] ~]# cat /etc/keepalived/keepalived.conf
global_defs { ###全局配置
notification_email { ###keepalived故障时发送邮件的目的地址
[email protected]
}
notification_email_from [email protected] ###keepalived故障时发送邮件的源地址
smtp_server root ###邮件smtp地址
smtp_connect_timeout 30 ###连接smtp超时时间
router_id RTM
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_rtm { ### 执行的检查mysql的脚本,如果mysql挂了,该server的优先级降20
script "/etc/keepalived/chk_rtm.sh"
interval 3
weight -20
}
vrrp_instance VI_1 { ##实例配置,VI_1为实例名称,可修改
state BACKUP ###状态,可以是MASTER或BACKUP
interface enp0s3 ###节点IP的网卡,用来发VRRP包。
virtual_router_id 51 ##实例的ID
priority 100 ###优先级,越大优先级越高
advert_int 1 ###心跳间隔,一秒收不到心跳 备节点则接管
authentication { ###服务之间密码认证
auth_type PASS
auth_pass 1111
}
track_script { ##配置脚本检查mysql服务的正常
chk_rtm
}
virtual_ipaddress { ##vip绑定,绑定到interface 设置的网卡
10.243.68.160
}
}
增加脚本文件chk_rtm.sh可执行的权限:
[[email protected] keepalived]# pwd
/etc/keepalived
[[email protected] keepalived]# ll
total 8
-rw-r--r--. 1 root root 218 Feb 21 20:25 chk_rtm.sh
-rw-r--r--. 1 root root 728 Feb 21 19:08 keepalived.conf
[[email protected] keepalived]# chmod +x chk_rtm.sh
[[email protected] keepalived]# ll
total 8
-rwxr-xr-x. 1 root root 218 Feb 21 20:25 chk_rtm.sh
-rw-r--r--. 1 root root 728 Feb 21 19:08 keepalived.conf
检查脚本
#!/bin/bash
MYSQL_PROCESS_EXISTED=$(systemctl status mysql | grep "active (running)" | wc -l)
if [ "${MYSQL_PROCESS_EXISTED}" == "1" ];then
exit 0
else
exit 1
fi
重启keepalived
[[email protected] keepalived]#systemctl enable keepalived
测试
1. 在两个server的终端执行ip a 查看server是否有虚拟ip:10.243.68.160
[[email protected] keepalived]#ip a
2. 在有虚拟ip的server的终端上停掉mysql服务,查看虚拟ip是否存在于另一台server
边栏推荐
- JS 面试题:手写节流(throttle)函数
- 容错机制记录
- RestTemplate与Ribbon简单使用
- Solutions to the failure of winddowns planning task execution bat to execute PHP files
- 'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution
- OSPF综合实验
- Mirror Grid
- Innovation and breakthrough! AsiaInfo technology helped a province of China Mobile complete the independent and controllable transformation of its core accounting database
- 基于TCP/IP在同一局域网下的数据传输
- R语言ggpubr包ggarrange函数将多幅图像组合起来、annotate_figure函数为组合图像添加注释、注解、标注信息、fig.lab参数添加图像标签、fig.lab.face参数指定样式
猜你喜欢

Knowledge maps are used to recommend system problems (mvin, Ctrl, ckan, Kred, gaeat)
![[multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22](/img/02/5f24b4af44f2f9933ce0f031d69a19.png)
[multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22

【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)

【GCN-RS】MCL: Mixed-Centric Loss for Collaborative Filtering (WWW‘22)

浅谈低代码技术在物流管理中的应用与创新
![[untitled]](/img/83/9b9a0de33d48f7d041acac8cfe5d6a.png)
[untitled]
![[multimodal] hit: hierarchical transformer with momentum contract for video text retrieval iccv 2021](/img/48/d5ec2b80cd949b359bcb0bcf08f4eb.png)
[multimodal] hit: hierarchical transformer with momentum contract for video text retrieval iccv 2021

'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution

记录一次线上死锁的定位分析

Hystrix使用
随机推荐
Atomic 原子类
Zero shot image retrieval (zero sample cross modal retrieval)
OSPF comprehensive experiment
Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor
Pycharm connects to the remote server SSH -u reports an error: no such file or directory
苹果供应链十年浮沉:洋班主任和它的中国学生们
Ups and downs of Apple's supply chain in the past decade: foreign head teachers and their Chinese students
Mirror Grid
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(设置min.segment.length参数为Inf不添加标签线段)
Introduction to redis
30 sets of Chinese style ppt/ creative ppt templates
图神经网络用于推荐系统问题(IMP-GCN,LR-GCN)
Transformer variants (routing transformer, linformer, big bird)
Transformer变体(Sparse Transformer,Longformer,Switch Transformer)
The JSP specification requires that an attribute name is preceded by whitespace
【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
R语言使用wilcox.test函数执行wilcox符号秩检验获取总体中位数(median)的置信区间(默认输出结果包括95%置信水平的置信区间)
R语言使用ggpubr包的ggarrange函数将多幅图像组合起来、使用ggexport函数将可视化图像保存为jpeg格式(width参数指定宽度、height参数指定高度、res参数指定分辨率)
Zuul网关使用
LeetCode 50. Pow(x,n)