由於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!
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秒的時間,還算是可以接受的了.