环境描述:OS:CentOS6.5_X64MASTER:192.168.0.202BACKUP:192.168.0.203VIP:192.168.0.2041、配置两台Mysql主主同步[root@master~]#yuminstallmysql-servermy
环境描述:
OS:CentOS6.5_X64
MASTER:192.168.0.202
BACKUP:192.168.0.203
VIP:192.168.0.204
1、配置两台Mysql主主同步
[root@master ~]# yum install mysql-server mysql -y [root@master ~]# service mysqld start [root@master ~]# mysqladmin -u root password 123.com [root@master ~]# vi /etc/my.cnf #开启二进制日志,设置id [mysqld] log-bin=mysql-bin server-id=1 #backup这台设置2 [root@master ~]# service mysqld restart#先查看下log bin日志和pos值位置
master配置如下:
[root@ master ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.203', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; #对端状态显示的值 mysql> start slave; #启动同步backup配置如下:
[root@backup ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.202', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; mysql> start slave;2、配置keepalived实现热备
[root@backup ~]# yum install -y pcre-devel openssl-devel popt-devel #安装依赖包
[root@master ~]# wget [root@master ~]# tar zxvf keepalived-1.2.7.tar.gz [root@master ~]# cd keepalived-1.2.7 [root@master ~]#./configure --prefix=/usr/local/keepalived make && make install#将keepalived配置成系统服务
#授权两台Mysql服务器允许root远程登录:
mysql> grant all on *.* to'root'@'192.168.0.%' identified by '123.com';
mysql> flush privileges;
3、测试高可用性
1、通过Mysql客户端通过VIP连接,看是否连接成功。
2、停止master这台mysql服务,是否能正常切换过去,可通过ip addr命令来查看VIP在哪台服务器上。
3、可通过查看/var/log/messges日志,,看出主备切换过程
4、master服务器故障恢复后,是否主动抢占资源,成为活动服务器。
本文出自 ““企鹅”那点事儿” 博客,请务必保留此出处