MySQL高可用性之Keepalived+MySQL(双主热备)
时间:2021-07-01 10:21:17
帮助过:11人阅读
环境描述:
OS:CentOS6.5_X64
MASTER:192.168.196.133
BACKUP:192.168.196.134
VIP:192.168.196.135操作系统时间一致更改:
# date -s "20170707 01:51:42"
# hwclock --systohc
1按照之前的文章,搭建双主备机
2安装keepalived
[root@backup ~]# yum install -y pcre-devel openssl-devel popt-devel #安装依赖包[root@master ~]# wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
[root@master ~]# tar zxvf keepalived-1.2.7.tar.gz
[root@master ~]# cd keepalived-1.2.7
[root@master ~]#./configure --prefix=/usr/local/keepalived
[root@master ~]#make && make install
3将keepalived配置成系统服务
[root@master ~]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@master ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@master ~]# mkdir /etc/keepalived/
[root@master ~]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@master ~]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
4修改配置文件
[root@master ~]# vi /etc/keepalived/keepalived.conf [root@master ~]# vi /usr/local/keepalived/mysql.sh #!/bin/bash pkill keepalived
[root@master ~]# chmod +x /usr/local/keepalived/mysql.sh [root@master ~]# /etc/init.d/keepalived start#backup服务器只修改priority为90、nopreempt不设置、real_server设置本地IP。5授权两台Mysql服务器允许root远程登录,用于在其他服务器登陆测试!mysql>grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘root‘;mysql>flush privileges
6、测试高可用性 1、通过Mysql客户端通过VIP连接,看是否连接成功。 2、停止master这台mysql服务,是否能正常切换过去,可通过ip addr命令来查看VIP在哪台服务器上。 3、可通过查看/var/log/messges日志,看出主备切换过程 4、master服务器故障恢复后,是否主动抢占资源,成为活动服务器。MySQL高可用性之Keepalived+MySQL(双主热备)
标签:address master flush 动态 实现 clock ddr ace chmod