標籤:starting tar 密碼 hat prope 代理 efault mod 伺服器
8.12.3.2 mysql-mmm 架構圖
Mysql mmm 特點
優點:高可用性,擴充性好,出現故障自動切換,對於主主同步,在同一時間只提供一台資料庫寫操作,保證的資料的一致性。
缺點:Monitor節點是單點,可以結合Keepalived實現高可用,對主機的數量有要求,需要實現讀寫分離,對程式來說是個挑戰。
8.12.3.3 mysql-mmm 安裝
需要在所有server上都安裝mysql-mmm
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install -y mysql-mmm*
8.12.3.4 mysql-mmm 配置
- 配置mmm代理和監控帳號的許可權
現在環境已經配置好,我沒有忽略 mysql 庫和 user 表,所以只要在任意一台主庫上執行下面的操作,其他庫就都有這倆帳號了。
這裡我在master1上進行的操作
mysql> grant replication client on . to ‘mmm_monitor‘@‘192.168.0.%‘ identified by ‘oldboy123‘;
mysql> grant super, replication client, process on . to ‘mmm_agent‘@‘192.168.0.%‘ identified by ‘oldboy123‘;
所有伺服器均需配置/etc/mysql-mmm/mmm_common.conf
active_master_role writer
<host default>
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user rep #同步處理的使用者
replication_password oldboy123 #同步密碼
agent_user mmm_agent # mmm_agent使用者
agent_password oldboy123 # mmm_agent使用者的密碼
</host>
<host db1>
ip 192.168.0.60 # db1 master-1的物理ip
mode master
peer db2
</host>
<host db2>
ip 192.168.0.61 # db2 master-2的物理ip
mode master
peer db1
</host>
<host db3>
ip 192.168.0.62 # db3 slave的物理ip
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.0.20 #寫入的虛擬IP地址 VIP
mode exclusive
</role>
<role reader>
hosts db1, db2, db3
ips 192.168.0.21, 192.168.0.22, 192.168.0.23 #虛擬讀取IP地址
mode balanced
</role>
所有伺服器均需配置/etc/mysql-mmm/mmm_agent.conf
vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
The ‘this‘ variable refers to this server. Proper operation requires
that ‘this‘ server (db1 by default), as well as all other servers, have the
proper IP addresses set in mmm_common.conf.
this db1 #分別修改為原生主機名稱,即db1、db2、db3和db4
- monitor主機配置/etc/mysql-mmm/mmm_mon.conf
[[email protected] tools]# cat /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
<monitor>
ip 127.0.0.1
pid_path /var/run/mysql-mmm/mmm_mond.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 192.168.0.60,192.168.0.61,192.168.0.62 #監控的IP
auto_set_online 30 #切換浮動IP的時間(預設為60秒) The kill_host_bin does not exist by default, though the monitor willthrow a warning about it missing. See the section 5.10 "Kill HostFunctionality" in the PDF documentation.kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host</monitor>
<host default>
monitor_user mmm_monitor #mmm_monitor 使用者
monitor_password oldboy123 #mmm_monitor 密碼
</host>
debug 0
8.12.3.5 mysql-mmm 啟動
1) master-1,master-2,slave啟動代理:
所有資料庫主機啟動mmm-agent:
/etc/init.d/mysql-mmm-agent start
10.204.3.4:9989 0.0.0.0:* LISTEN 2407/mmm_agentd
2) monitor主機啟動mmm-monitor
/etc/init.d/mysql-mmm-monitor start
8.12.3.6 mysql-mmm 測試
mmm_control命令監控mysql伺服器狀態
[[email protected] ~]# mmm_control show
db1(192.168.0.60) master/ONLINE. Roles: reader(192.168.0.23), writer(192.168.0.20)
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.21)
測試兩個mysql伺服器能否實現故障自動切換
將db1的mysql服務停止
[[email protected] tools]# /etc/init.d/mysqld stop
Shutting down MySQL... SUCCESS!
等待30秒在mysql-mmm-monitor伺服器上進行監控查看
[[email protected] ~]# mmm_control show
db1(192.168.0.60) master/HARD_OFFLINE. Roles:
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22), writer(192.168.0.20)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.21), reader(192.168.0.23)
slave檢查master_host是否切換到了另一個主庫地址:
[[email protected] ~]# mysql -e "show slave status\G"|egrep "Master_Host:"
Master_Host: 192.168.0.61
恢複master-1(db1)
[[email protected] tools]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
monitor端檢查恢複情況
[[email protected] ~]# mmm_control show
db1(192.168.0.60) master/ONLINE. Roles: reader(192.168.0.21)
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22), writer(192.168.0.20)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.23)
我們可以看到當db1恢複後就充當slave的角色了!只有當db2掛了以後db1又會擔當起主伺服器的寫入功能。
8.12.3.7 mmm_control命令介紹
Valid commands are:
help - show this message
#查看協助資訊
ping - ping monitor
#ping監控
show - show status
#查看狀態資訊
checks [<host>|all [<check>|all]] - show checks status
#顯示檢查狀態,包括(ping、mysql、rep_threads、rep_backlog)
set_online <host> - set host <host> online
#設定某host為online狀態
set_offline <host> - set host <host> offline
#設定某host為offline狀態
mode - print current mode.
#列印當前的模式,是ACTIVE、MANUAL、PASSIVE?
#預設ACTIVE模式
set_active - switch into active mode.
#更改為active模式
set_manual - switch into manual mode.
#更改為manual模式
set_passive - switch into passive mode.
#更改為passive模式
move_role [--force] <role> <host> - move exclusive role <role> to host <host>
#更改host的模式,比如更改處於slave的mysql資料庫角色為write
(Only use --force if you know what you are doing!)
set_ip <ip> <host> - set role with ip <ip> to host <host>
#為host設定ip,只有passive模式的時候才允許更改!
mysql-mmm 架構詳細教程