MMM—MySQL高可用性解决方案

  • A+
所属分类:MySQL

MMM---MySQL高可用性解决方案

一.环境如下:

MMM_monitor: 192.168.1.1

MySQL_master: 192.168.1.2, 192.168.1.3

VIP_write: 192.168.1.11

VIP_read: 192.168.1.22, 192.168.1.33

MMM介绍参见:??http://www.bhlaab.com/html/1208.html

二.安装配置

1.安装MMM

rpm -ivh http://www.bhlaab.com/414/fedora/epel/6/x86_64/epel-release-6-5.noarch.rpm

yum install mysql-mmm

yum install mysql mysql-server

2.授权

mysql> GRANT FILE, REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.%' IDENTIFIED BY 'www.bhlaab.com'

mysql> GRANT PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'mmm_agent'@'192.168.1.%' IDENTIFIED BY 'www.bhlaab.com'

mysql> GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.1.1' IDENTIFIED BY 'www.bhlaab.com'

3.两台数据库服务器配置成互为主主

配置参见: http://www.bhlaab.com/html/1208.html

[192.168.1.2]

log_bin=mysql-bin

log_bin_index=mysql-bin.index

relay_log=mysql-relay-bin

relay_log_index=mysql-relay-bin.index

binlog_format=mixed

expire_logs_days =7

max_binlog_size = 100M

server-id = 2

auto-increment-increment = 2

auto-increment-offset = 2

[192.168.1.3]

log_bin=mysql-bin

log_bin_index=mysql-bin.index

relay_log=mysql-relay-bin

relay_log_index=mysql-relay-bin.index

binlog_format=mixed

expire_logs_days =7

max_binlog_size = 100M

server-id = 3

auto-increment-increment = 2

auto-increment-offset = 1

4.在数据库服务器上配置mmm监控代理服务

[192.168.1.2]# vi 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 repl

replication_password www.bhlaab.com

agent_user mmm_agent

agent_password www.bhlaab.com

</host>

<host db1>

ip 192.168.1.2

mode master

peer db2

</host>

<host db2>

ip 192.168.1.3

mode master

peer db1

</host>

<role writer>

hosts db1,db2

ips 192.168.1.11

mode exclusive

</role>

<role reader>

hosts db1,db2

ips 192.168.1.22,192.168.1.33

mode balanced

</role>

[192.168.1.2]# vi mmm_agent.conf

include mmm_common.conf

this db1

[192.168.1.2]# /etc/init.d/mysql-mmm-agent start

 

[192.168.1.3]# vi 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 repl

replication_password www.bhlaab.com

agent_user mmm_agent

agent_password www.bhlaab.com

</host>

<host db1>

ip 192.168.1.2

mode master

peer db2

</host>

<host db2>

ip 192.168.1.3

mode master

peer db1

</host>

<role writer>

hosts db1,db2

ips 192.168.1.11

mode exclusive

</role>

<role reader>

hosts db1,db2

ips 192.168.1.22,192.168.1.33

mode balanced

</role>

[192.168.1.3]# vi mmm_agent.conf

include mmm_common.conf

this db2

[192.168.1.3]# /etc/init.d/mysql-mmm-agent start

 

[192.168.1.1]# vi 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 repl

replication_password www.bhlaab.com

agent_user mmm_agent

agent_password www.bhlaab.com

</host>

<host db1>

ip 192.168.1.2

mode master

peer db2

</host>

<host db2>

ip 192.168.1.3

mode master

peer db1

</host>

<role writer>

hosts db1,db2

ips 192.168.1.11

mode exclusive

</role>

<role reader>

hosts db1,db2

ips 192.168.1.22,192.168.1.33

mode balanced

</role>

[192.168.1.1]# cat 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.1.2,192.168.1.3

auto_set_online 60

</monitor>

<host default>

monitor_user mmm_monitor

monitor_password www.bhlaab.com

</host>

debug 0

[192.168.1.1]# /etc/init.d/mysql-mmm-monitor start

[192.168.1.1]# mmm_control show

slave1(192.168.1.2) master/ONLINE. Roles: reader(192.168.1.22)

slave2(192.168.1.3) master/ONLINE. Roles: reader(192.168.1.33), writer(192.168.1.11)

[192.168.1.1]# mmm_control checks all

微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~

发表评论