本文主要是介绍MySQL-MMM框架,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 5 | [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 < test.sql [root@db4 ~] # mysql -u root -p123.com test < test.sql |
1 2 3 | [root@db ~] # 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@monitor ~] # 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 2 3 | [root@db ~] # 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@monitor ~] # 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 |
这篇关于MySQL-MMM框架的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!