mysql-mmm文檔下載地址
http://down.51cto.com/data/339582
部署環境
操作系統:Red Hat Enterprise Linux Server release 6.1
Master1:192.168.5.73
Master2:192.168.5.76
Monitor:192.168.5.77
安裝步驟
1、假設mysql Mater-Master模式已經配置成功,可以參考mysql master-slave配置文章
http://360537539.blog.51cto.com/3803422/781612
爲了避免master-master AUTO_INCREMENT列值重複情況,需要在my.cnf配置中配置如下內容
master1:
- auto_increment_increment = 2
- auto_increment_offset = 1
master2:
- auto_increment_increment = 2
- auto_increment_offset = 2
有關auto_increment_increment和auto_increment_offset參考
http://blog.csdn.net/wh62592855/article/details/6726724
2、安裝mysql-mmm-agent mysql-mmm-common mysql-mmm-mon,redhat和centos系統通過yum方式安裝比較方便(省去了很多依賴包的安裝),但是默認的centos軟件倉庫默認不包含這些rpm包,需要epel-release的支持。
1)安裝epel-release包
#rpm -Uvh http://mirror.xfes.ru/fedora-epel/6/i386/epel-release-6-5.noarch.rpm,不同的系統版本注意選擇對應的鏡像位置
2)安裝mysql-mmm系列包
yum install mysql-mmm* -y
3)創建mysql 用戶並賦予權限
條件:
monitor user
A MySQL user with privileges REPLICATION CLIENT for MMM monitor.
agent user
A MySQL user with privileges SUPER, REPLICATION CLIENT, PROCESS for
MMM agent.
replication user
A MySQL user with privileges REPLICATION SLAVE used for replication.
運行命令
- mysql>GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.%' IDENTIFIED BY 'ictsoft';
- mysql> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.%' IDENTIFIED BY 'ictsoft';
- mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.%' IDENTIFIED BY 'ictsoft';
4、配置mysql-mmm
vi /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 ictsoft
- agent_user mmm_agent
- agent_password ictsoft
- </host>
- <host db1>
- ip 192.168.5.73
- mode master
- peer db2
- </host>
- <host db2>
- ip 192.168.5.76
- mode master
- peer db1
- </host>
- <role writer>
- hosts db1, db2
- ips 192.168.5.80
- mode exclusive
- </role>
- <role reader>
- hosts db1, db2
- ips 192.168.5.84, 192.168.5.82
- mode balanced
- </role>
192.168.5.73 192.168.5.76爲anget的ip地址
192.168.5.80 192.168.5.82 192.168.5.84是3個浮動ip,192.168.5.84, 192.168.5.82對應’讀’角色,192.168.5.80對應’寫’角色,浮動ip會根據mysql服務的情況進行漂移,後面會詳細介紹。
將配置文件拷貝到monitor和agent的響應目錄下(/etc/mysql-mmm/mysql-common.conf)
修改mysql-mmm-agent.conf
vi /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this db1
注意此處this的值要和common中的配置相對應
修改mysql-mmm-monitor.conf
- include mmm_common.conf
- <monitor>
- ip 127.0.0.1
- pid_path /var/run/mmm_mond.pid
- bin_path /usr/lib/mysql-mmm/
- status_path /var/lib/misc/mmm_mond.status
- ping_ips 192.168.5.73
- </monitor>
- <host default>
- monitor_user mmm_monitor
- monitor_password ictsoft
- </host>
- debug 1
5、啓動mysql-mmm-agent和mysql-mmm-monitor服務
#/etc/init.d/mysql-mmm-agent start
#/etc/init.d/mysql-mmm-monitor start
6、檢測狀態
monitor端
- #mmm_control show
- b1(192.168.5.73) master/AWAITING_RECOVERY. Roles:
- db2(192.168.5.76) master/AWAITING_RECOVERY. Roles:
對兩臺db做set_online操作
- #mmm_control set_online db1
- #mmm_control set_online db2
查看狀態
- #mmm_control show
- db1(192.168.5.73) master/ONLINE. Roles: reader(192.168.5.82), writer(192.168.5.80)
- db2(192.168.5.76) master/ONLINE. Roles: reader(192.168.5.84)
7、測試
停掉db1的mysql,在monitor端查看狀態
- #mmm_control show
- db1(192.168.5.73) master/HARD_OFFLINE. Roles:
- db2(192.168.5.76) master/ONLINE. Roles: reader(192.168.5.82), reader(192.168.5.84), writer(192.168.5.80)
發現原來在db1上的讀和寫角色(ip)都漂移到了db2,啓動db1的mysql后角色重新分配