由于mysql没有提供高可用性方案,如果一台数据库down就会影响到业务,为了实现高可用性可以使用hearbeat,这里我使用MMM来提高mysql的高可用性,以提高业务的不中断.
环境:
服务器类型 IP VIP
node1 10.10.1.65 10.10.1.77
node2 10.10.1.58 10.10.1.78
mon 10.10.1.161 10.10.1.79
配置过程:
1.首先要实现node1和node2的双向同步,这个本人博客已经有相关的文章,在这里就不进行说明了
2.安装和配置MMM
3台服务器都要安装MMM安装包,由于要使用到perl模块,所以要进行如下模块的安装
Algorithm::Diff
Proc::Daemon
Time::HiRes
DBI
DBD::mysql
Proc::Daemon
Time::HiRes
DBI
DBD::mysql
以上模块你可以通过cpan进行安装,也可以去cpan.org网站上去下载相应的安装包,我已经安装好了
MMM下载地址如下:http://code.google.com/p/mysql-master-master/downloads/list,现在
最新的安装是
mysql-master-master-1.2.6.tar.gz.
#tar zxvf mysql-master-master-1.2.6.tar.gz
#cd mysql-master-master-1.2.6
#./install.pl
在nod1上的配置:
#cp usr/local/mmm/etc/examples/mmm_agent.conf.example mmm_agent.conf
#vi usr/local/mmm/etc/examples/mmm_agent.conf
//这个配置文件的内容很少,直接清空
添加如下的内容
#
|
#mysql -u root -p123456
GRANT ALL PRIVILEGES on *.* to 'rep_agent'@'%' identified by 'RepAgent';
GRANT ALL PRIVILEGES on *.* to 'rep_monitor'@'%' identified by
'RepMonitor';
'RepMonitor';
在node2上的配置:
#cp usr/local/mmm/etc/examples/mmm_agent.conf.example mmm_agent.conf
#vi usr/local/mmm/etc/examples/mmm_agent.conf
//这个配置文件的内容很少,直接清空
添加如下的内容
#
|
#mysql -u root -p123456
GRANT ALL PRIVILEGES on *.* to 'rep_agent'@'%' identified by 'RepAgent';
GRANT ALL PRIVILEGES on *.* to 'rep_monitor'@'%' identified by
'RepMonitor';
'RepMonitor';
在mon上的配置:
# Master-Master Manager config (monitor)
|
进行启动以及测试:
在node1和node2上启动mmmd_agent
#mmmd_agent
#netstat -tlnp
tcp 0 0 0.0.0.0:9989 0.0.0.0:* LISTEN 14301/perl
出现9989端口就表示启动正常
出现9989端口就表示启动正常
在mon上启动mmm_mon
#mmmd_mon
MySQL Multi-Master Replication Manager
Version: 1.2.6
Reading config file: 'mmm_mon.conf'
$VAR1 = {};
MySQL Multi-Master Replication Manager
Version: 1.2.6
Reading config file: 'mmm_mon.conf'
$VAR1 = {};
在管理节点上(mon)启动db节点:
#mmm_control set_online db1
MySQL Multi-Master Replication Manager
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
#mmm_control set_online db2
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
#mmm_control set_online db2
MySQL Multi-Master Replication Manager
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db2' changed to ONLINE. Now you can wait some time and check its new roles!
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db2' changed to ONLINE. Now you can wait some time and check its new roles!
查看下节点状态:
#mmm_control show
MySQL Multi-Master Replication Manager
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
===============================
Cluster failover method: AUTO
===============================
Servers status:
db1(10.10.1.65): master/ONLINE. Roles: reader(10.10.1.78;), writer(10.10.1.79;)
db2(10.10.1.58): master/ONLINE. Roles: reader(10.10.1.77;)
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
===============================
Cluster failover method: AUTO
===============================
Servers status:
db1(10.10.1.65): master/ONLINE. Roles: reader(10.10.1.78;), writer(10.10.1.79;)
db2(10.10.1.58): master/ONLINE. Roles: reader(10.10.1.77;)
看到这个就说明配置没有问题,现在我们来进行切换测试,看切换是否正常,我现在把node1的mysql停止掉然后在看下节点的状态
#mmm_control show
[root@localhost etc]# mmm_control show
MySQL Multi-Master Replication Manager
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
===============================
Cluster failover method: AUTO
===============================
Servers status:
db1(10.10.1.65): master/HARD_OFFLINE. Roles: None
db2(10.10.1.58): master/ONLINE. Roles: reader(10.10.1.77;), reader(10.10.1.78;), writer(10.10.1.79;)
MySQL Multi-Master Replication Manager
Version: 1.2.6
Config file: mmm_mon.conf
Daemon is running!
===============================
Cluster failover method: AUTO
===============================
Servers status:
db1(10.10.1.65): master/HARD_OFFLINE. Roles: None
db2(10.10.1.58): master/ONLINE. Roles: reader(10.10.1.77;), reader(10.10.1.78;), writer(10.10.1.79;)
可以看到读写操作都转到了node2机器上了,看来切换没有问题,测试了下,切换需要大概3秒的时间,还算是可以接受的了.