首页 > 代码库 > mysql mmm配置

mysql mmm配置

技术分享

共五台电脑,分工如下:
115,116 master
117,118 slave
119 mon

首先配置主主同步

编辑master115,116配置文件

#mmm
log_bin             = /daan/mysql/5.6/data/mysql-bin.log 
log_bin_index       = /daan/mysql/5.6/data/mysql-bin.log.index 
relay_log           = /daan/mysql/5.6/data/mysql-relay-bin 
relay_log_index     = /daan/mysql/5.6/data/mysql-relay-bin.index 
expire_logs_days    = 10 
max_binlog_size     = 100M 
log_slave_updates   = 1
auto_increment_increment = 2
auto_increment_offset = 1
#116配置2
#auto_increment_offset = 2
bind-address = 0.0.0.0
?    重启mysql
?    登陆mysql给115,116,117,118添加用户用于复制
GRANT REPLICATION SLAVE  ON *.* TO rep@192.168.14.% IDENTIFIED BY rep;
FLUSH PRIVILEGES;
(如果复制失败就赋予ALL PRIVILEGES)
在116,117,118测试复制
CHANGE MASTER TO master_host=192.168.14.115, master_port=3306, master_user=rep, 
              master_password=rep, master_log_file=mysql-bin.000003, master_log_pos=417;
start slave;
show slave status\G;
115上测试复制116
reset slave;
stop slave;
CHANGE MASTER TO master_host=192.168.14.116, master_port=3306, master_user=rep, 
              master_password=rep, master_log_file=mysql-bin.000001, master_log_pos=216;
start slave;
show slave status\G;
show databases;
上面已配置完2主,两从配置.
CHANGE MASTER TO master_host=192.168.14.120, master_port=3306, master_user=rep, 
              master_password=rep, master_log_file=mysql-bin.000001, master_log_pos=216;
注意使用的是master的虚拟ip
安装mmm
下载http://mysql-mmm.org/downloads
在所有机器安装,解压后make install
15,16,17,18 mysql分配权限
GRANT ALL PRIVILEGES ON *.* TO monitor@192.168.14.% IDENTIFIED BY monitor1;  
GRANT ALL PRIVILEGES ON *.* TO agent@192.168.14.%   IDENTIFIED BY agent1;
GRANT ALL PRIVILEGES ON *.* TO rep@192.168.14.% IDENTIFIED BY rep1;
FLUSH privileges;
所有机打开防火墙9989
firewall-cmd --zone=public --add-port=9989/tcp --permanent
firewall-cmd --reload 
所有机添加用户
useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd
#所有机器
vi /etc/mysql-mmm/mmm_common.conf
(编写好一个后可以使用命令复制scp /etc/mysql-mmm/mmm_common.conf root@192.168.14.116:/etc/mysql-mmm/mmm_common.conf
scp /etc/mysql-mmm/mmm_agent.conf root@192.168.14.116:/etc/mysql-mmm/mmm_agent.conf
)
active_master_role          writer


<host default>
    cluster_interface       eth0

pid_path                /var/run/mmmd_agent.pid
    bin_path                /usr/lib/mysql-mmm/

    replication_user        rep
    replication_password    rep1

    agent_user              agent
    agent_password          agent1
</host>

<host db1>
    ip                      192.168.14.15
    mode                    master
    peer                    db2
</host>

<host db2>
    ip                      192.168.14.16
    mode                    master
    peer                    db1
</host>

<host db3>
    ip                      192.168.14.17
    mode                    slave
</host>

<host db4>
    ip                      192.168.14.18
    mode                    slave
</host>


<role writer>
    hosts                   db1, db2
    ips                     192.168.14.120
    mode                    exclusive
</role>

<role reader>
    hosts                   db3, db4
    ips                     192.168.14.121, 192.168.14.122
    mode                    balanced
</role>
#数据库15,16,17,18
vi /etc/mysql-mmm/mmm_agent.conf

include mmm_common.conf
this db1 #各自修改
#监控机119
vi /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf

<monitor>
    ip                      127.0.0.1
pid_path                /var/run/mmmd_mon.pid
port  9989
    bin_path                /usr/lib/mysql-mmm/
    status_path             /var/lib/misc/mmmd_mon.status
    ping_ips                192.168.14.15,192.168.14.16,192.168.14.17,192.168.14.18
</monitor>

<host default>
    monitor_user            monitor
    monitor_password        monitor1
</host>

debug 0
所有机安装模块 一路回车
cpan Proc::Daemon 
cpan Log::Log4perl
perl -MCPAN -e shell
install Net::ARP
#数据库机器启动代理
/etc/init.d/mysql-mmm-agent start
#监控机启动监控
chmod 600 /etc/mysql-mmm/* 
vi /etc/hosts
增加如下行
192.168.14.115 db1
192.168.14.116 db2
192.168.14.117 db3
启动:
/etc/init.d/mysql-mmm-monitor start
115,116增加虚拟ip
在ifcfg-eth0配置文件中手工添加如下两行:
IPADDR2=192.168.14.120
PREFIX2=24
保存文件后
执行生效
nmcli con load /etc/sysconfig/network-scripts/ifcfg-eth0
nmcli dev connect eth0
监控机上执行命令
mmm_control show
mmm_control set_online db1
mmm_control set_online db2
mmm_control set_online db3

 

mysql mmm配置