function | ip | hostname | server id |
monitoring host | 192.168.0.201 | monitor | 无 |
master 1 | 192.168.0.202 | db1 | 1 |
master 2 | 192.168.0.203 | db2 | 2 |
slave 1 | 192.168.0.204 | db3 | 3 |
slave 2 | 192.168.0.205 | db4 | 4 |
ip | role |
192.168.0.211 | writer |
192.168.0.212 | reader |
192.168.0.213 | reader |
function | description | privileges |
monitor user | mmm监控用于对mysql服务器进程健康检查 | REPLICATION CLIENT |
agent user | mmm代理用来更改只读模式,复制的主服务器等 | SUPER, REPLICATION CLIENT, PROCESS |
replication user | 用于复制 | REPLICATION SLAVE |
1 2 3 | [root@db1 ~]# yum install mysql-server mysql [root@db1 ~]# service mysqld start [root@db1 ~]# mysqladmin -u root password 123.com |
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@db1 ~]# vi /etc/my.cnf #添加如下 [mysqld] binlog-do-db=test #需要记录二进制日志的数据库,多个用逗号隔开 binlog-ignore-db=mysql,information_schema #不需要记录二进制日志的数据库,多个用逗号隔开 auto_increment_increment=2 #字段一次递增多少 auto_increment_offset=1 #自增字段的起始值,值设置不同 replicate-do-db=test #同步的数据库,多个写多行 replicate-ignore-db = information_schema #不同步的数据库,多个写多行 server_id = 1 #每台设置不同 log_bin = mysql-bin log_slave_updates #当一个主故障,另一个立即接管 sync-binlog=1 #每条自动更新,安全性高,默认是0 [root@db1 ~]# service mysqld restart |
1 2 3 4 5 6 7 8 9 10 | [root@db1 ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.203', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; #对端状态显示的值 mysql> start slave; #启动同步 |
1 2 3 4 5 6 7 8 9 10 | [root@db2 ~]# mysql -u root -p123.com mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication'; mysql> flush privileges; mysql> change master to -> master_host='192.168.0.202', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=106; mysql> start slave; #启动同步 |
1 2 3 4 5 6 | mysql> change master to -> master_host='192.168.0.202', -> master_user='replication', -> master_password='replication', -> master_log_file='mysql-bin.000002', -> master_log_pos=434; |
1 2 3 4 | [root@db1 ~]# mysqldump -uroot -p123.com test > test.sql [root@db1 ~]# scp test.sql root@192.168.0.204:/root/ [root@db1 ~]# scp test.sql root@192.168.0.205:/root/ [root@db3 ~]# mysql -u root -p123.com test |
1 | rpm -ivh http://mirrors.ustc.edu.cn/fedor ... ease-6-8.noarch.rpm |
1 | [root@monitor1 ~]# yum -y install mysql-mmm-monitor |
1 | [root@db1 ~]# yum -y install mysql-mmm-agent |
1 2 3 4 | [root<a href="http://www.jobbole.com/members/8256fu">@db</a> ~]# mysql -u root -p123.com mysql> GRANT REPLICATIONCLIENT ON *.* TO 'mmm_monitor'@'192.168.0.%' IDENTIFIED BY'monitor'; mysql> GRANT SUPER,REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.0.%' IDENTIFIED BY'agent'; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | [root@monitor1 ~]# 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 replication replication_password replication agent_user mmm_agent agent_password agent </host> <host db1> ip 192.168.0.202 mode master peer db2 </host> <host db2> ip 192.168.0.203 mode master peer db1 </host> <host db3> ip 192.168.0.204 mode slave </host> <host db4> ip 192.168.0.205 mode slave </host> <role writer> hosts db1, db2 ips 192.168.0.211 mode exclusive #只有一个host可以writer,一般写操作是这个模式 </role> <role reader> hosts db3, db4 ips 192.168.0.212,192.168.0.213 mode balanced #多个host可以reader,一般读操作是这个模式 </role> |
1 | scp /etc/mysql-mmm/mmm_common.conf root@192.168.0.202/203/204/205:/etc/mysql-mmm/ |
1 2 3 | [root<a href="http://www.jobbole.com/members/8256fu">@db</a> ~]# vi /etc/mysql-mmm/mmm_agent.conf include mmm_common.conf this db1 #分别修改为本机的主机名,即db1、db2、db3和db4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@monitor1 ~]# vi /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.202,192.168.0.203,192.168.0.204,192.168.0.205 #真实数据库IP,来检测网络是否正常 auto_set_online 10 #恢复后自动设置在线的时间 </monitor> <host default> monitor_user mmm_monitor monitor_password monitor </host> debug 0 |
1 2 | [root@db1 ~]# /etc/init.d/mysql-mmm-agent start [root@db1 ~]# chkconfigmysql-mmm-agent on |
1 2 | [root@monitor1 ~]# /etc/init.d/mysql-mmm-monitor start [root@monitor1 ~]# chkconfigmysql-mmm-monitor on |
欢迎光临 168大数据 (http://www.bi168.cn/) | Powered by Discuz! X3.2 |