mysql主从复制配置过程(MySQL双主复制双机热备)
mysql主从复制配置过程(MySQL双主复制双机热备)blog.csdn.net/weixin_46902396/article/details/1166567361.配置时间同步master1 上操作安装教程三、验证1、 验证 LVS 负载均衡是否正常2、 验证 Keepalived 双机热备是否正常3、 验证 MySQL 数据库可用性注意:未安装 MySQL 数据库的可以先安装
目录一、 部署 MySQL 双主复制
1、 配置时间同步
2、 配置双主复制
二、部署 LVS Keepalived 实现 MySQL 双主复制高可用
1、 配置主调度器
2、 配置备调度器
3、 编写 LVS 启动脚本
三、验证
1、 验证 LVS 负载均衡是否正常
2、 验证 Keepalived 双机热备是否正常
3、 验证 MySQL 数据库可用性
注意:未安装 MySQL 数据库的可以先安装
安装教程
blog.csdn.net/weixin_46902396/article/details/116656736
1.配置时间同步
master1 上操作
master 2上操作
2.配置双主复制1)master1 上操作
2)master2 上操作
3)建立双主复制
master1 上操作
master2 上操作
二、部署 LVS Keepalived 实现 MySQL 双主复制高可用1.配置主调度器[root@keep1 ~]# yum -y install keepalived ipvsadm
[root@keep1 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
router_id 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.188
}
}
virtual_server 192.168.1.188 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.1.1 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.2 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@keep1 ~]# systemctl start keepalived
[root@keep2 ~]# ip a
[root@keep2 ~]# yum -y install keepalived ipvsadm
[root@keep2 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
router_id 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.188
}
}
virtual_server 192.168.1.188 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.1.1 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.2 3306 {
weight 1
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@keep2 ~]# systemctl start keepalived
查看LVS 集群状态
3.编写 LVS 启动脚本在master1 master2 上操作
[root@master1 ~]# vim /etc/init.d/realserver
#!/bin/bash
VIP=192.168.1.188
. /etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo down
/sbin/ifconfig lo up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
/sbin/sysctl -p >/dev/null 2>&1
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
echo "LVS-DR real server starts successfully.\n"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $VIP >/dev/null 2>&1
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "LVS-DR real server stopped.\n"
;;
status)
isLoOn=/sbin/ifconfig lo:0 | grep "$VIP"
isRoOn=/bin/netstat -rn | grep "$VIP"
if [ "$isLoON" == "" -a "$isRoOn" == "" ]; then
echo "LVS-DR real server has run yet."
else
echo "LVS-DR real server is running."
fi
exit 3
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
[root@master1 ~]# chmod x /etc/init.d/realserver
[root@master1 ~]# /etc/init.d/realserver start # 启动脚本
[root@master1 ~]# echo "/etc/init.d/realserver" >> /etc/rc.d/rc.local # 配置开启自启动
[root@master1 ~]# ifconfig lo:0
在任意一台 master 添加一个测试用户
1.验证 LVS 负载均衡是否正常2.验证 Keepalived 双机热备是否正常
- 关闭 LVS 主调度器,查看客户机是否能够正常访问数据库。