千家信息网

keepalived Mysql双主热备配置的示例分析

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,这篇文章主要介绍keepalived Mysql双主热备配置的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!基于keepalived双主热备:一.环境:OS:CentO
千家信息网最后更新 2025年01月20日keepalived Mysql双主热备配置的示例分析

这篇文章主要介绍keepalived Mysql双主热备配置的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

基于keepalived双主热备:
一.环境:
OS:CentOS 6.5 X64
DB Version:Percona Mysql 5.7.15-9-log
路径:/app/mysql57
数据文件路径:/data/mysql57/data
DB1:192.168.213.4
DB2:192.168.213.5


二.安装keepalived包(两台主机都需操作)
1.下载keepalived包
cd /usr/local/tools
wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz


2.安装所需包
yum -y install openssl-devel


3.安装keepalived
mkdir -pv /app/keepalived
cd /usr/local/tools
tar xf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/app/keepalived/
make
make install


4.配置keepalived
cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /app/keepalived/sbin/keepalived /usr/sbin/


db01 keepalived配置
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state MASTER
interface eth0 !虚拟IP对应接口,也就是业务接口对应的网卡编号
virtual_router_id 51
priority 105 !权重
advert_int 1
nopreempt !自己上线后不抢占当前 master 的位置,即使其权重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !启用头部定义的检查MySQL状态的脚本
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.5 3306 ! real_server 挂掉后临时使用 sorry_server 顶上
real_server 192.168.213.4 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}




db02 keepalived配置
[root@ORADB-213-5 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
state BACKUP
interface eth0 !虚拟IP对应接口,也就是业务接口对应的网卡编号
virtual_router_id 51
priority 100 !权重
advert_int 1
nopreempt !自己上线后不抢占当前 master 的位置,即使其权重比自己低
virtual_ipaddress {
192.168.213.100 !VIP
}
track_script {
chk_mysql !启用头部定义的检查MySQL状态的脚本
}
}
virtual_server 192.168.213.100 3306 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 60
protocol TCP sorry_server 192.168.213.4 3306 ! real_server 挂掉后临时使用 sorry_server 顶上
real_server 192.168.213.5 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
}
}
}


5.两台DB启动keepalived
/etc/init.d/keepalived start


查看VIP
[root@ORA11G-213-4 keepalived-1.2.23]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c7:d5:27 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.4/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fec7:d527/64 scope link
valid_lft forever preferred_lft forever

测试
[root@ORA11G-213-4 keepalived-1.2.23]# mysql -unetdata -pnetdata -h 192.168.213.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2881
Server version: 5.7.15-9-log Source distribution


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


netdata@192.168.213.100 23:41: [(none)]> system ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:C7:D5:27
inet addr:192.168.213.4 Bcast:192.168.213.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec7:d527/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:156643 errors:0 dropped:0 overruns:0 frame:0
TX packets:191173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39459924 (37.6 MiB) TX bytes:31911844 (30.4 MiB)


lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:17378 errors:0 dropped:0 overruns:0 frame:0
TX packets:17378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1002566 (979.0 KiB) TX bytes:1002566 (979.0 KiB)

停止掉db01
[root@ORA11G-213-4 keepalived-1.2.23]# /etc/init.d/mysql57 stop
Shutting down MySQL (Percona Server)............. SUCCESS!


查看db02
[root@ORADB-213-5 ~]# ip addr
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:54:39 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.5/24 brd 192.168.213.255 scope global eth0
inet 192.168.213.100/32 scope global eth0
inet6 fe80::20c:29ff:fe63:5439/64 scope link
valid_lft forever preferred_lft forever

以上是"keepalived Mysql双主热备配置的示例分析"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

配置 接口 权重 示例 分析 业务 也就是 位置 内容 头部 状态 篇文章 网卡 脚本 路径 检查 主机 价值 兴趣 小伙 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 web使用数据库查询 姜堰区多功能网络技术大概费用 求生之路rpg服务器人物源码 rainbow数据库 北京市网络安全继续教育平台 oracle数据库详细介绍 服务器查杀 软件开发阶段主要任务 计算机网络技术试卷分析 软件开发所需基本能力 无锡零距离网络技术有限公司 网络安全威胁共享平台 政府网络安全工资 数据库删除操作异常是什么 合肥正规网络技术咨询哪家好 剑灵道具属性在本地还是服务器 网络安全预防诈骗小品五人 mysql远程备份数据库 树莓派搭建服务器 北京师范大学研究生管理服务器 酒泉市网络安全和信息化委员会 软件开发合同协议样本 报考计算机网络技术专业的理由 金蝶财务软件开发平台 查找两张表的相同数据库 北京晓通网络技术有限公司 华三服务器做镜像什么意思 绵阳软件开发工资多少 查询很慢数据库性能问题 计算机里面的数据库是什么
0