为了响应公司需求,打造出更安全的mysql集群,能够实现mysql故障后切换,研究了几天终于有了成果,一起分享一下。
首先介绍一下这套集群方案实现的功能
1、mysql服务器故障后自动转移,修好后自动切回
2、mysql服务故障自动转移,修好后自动切回
3、可以实现在几秒钟内转移
以下内容均是实验环境,请根据实际情况修改响应参数
生产环境MySQL主主同步主键冲突处理 http://www.linuxidc.com/Linux/2013-07/86890.htm
MySQL + KeepAlived + LVS 单点写入主主同步高可用架构实验 http://www.linuxidc.com/Linux/2013-05/84002.htm
MySQL 主主同步配置 http://www.linuxidc.com/Linux/2013-05/83815.htm
CentOS 6.3下MySQL主从复制笔记 http://www.linuxidc.com/Linux/2013-06/85983.htm
Linux下的MySQL主主复制 http://www.linuxidc.com/Linux/2013-10/91683.htm
实验环境:
mysql1 ip:10.1.1.20
mysql2 ip:10.1.1.21
mysql vip:10.1.1.25
三台机器均安装centos 6.5 32位(虚拟机环境)
实验开始!!!
一、安装mysql,并打造主主同步。
相信主从同步大家都会做,一样的道理,主主同步就是两台机器互为主的关系,在任何一台机器上写入都会同步。
安装mysql的过程不解释,yum就好啦
配置主主同步
1.配置 /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=binlog #开启binlog功能
log-bin-index=binlog.index
sync_binlog=0
server_id = 1 #两台机器不能重复,一个1 一个2 就好
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2.分别在两台机器上配置同步账号
10.1.1.20机器上:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection> Server version: 5.0.77-log Sourcedistribution
Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> GRANT replication slave ON . TO'ab'@'%'> Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
10.1.1.21机器上:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection> Server version: 5.0.77-log Sourcedistribution
Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
Your MySQL connection> Server version: 5.1.66-log Source distribution
Copyright (c) 2000, 2012, 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.
mysql>