MariaDB 10 (MySQL DB) 多主复制并实现读写分离_MySQL
MariaDB
二、资源配置
-
主机属性
系统 | 名字 | 角色 | 主机名 | ip地址 | 关系 |
Centos6.5x86_64 | DB1 | Master | essun.mariadb1.com | 192.168.1.109 | 与DB2互为主从 |
Centos6.5x86_64 | DB2 | Master | essun.mariadb2.com | 192.168.1.112 | 与DB1互为主从 |
Centos6.5x86_64 | DB3 | Slave | essun.mariadb3.com | 192.168.1.113 | DB1的从库 |
Centos6.5x86_64 | Monitor | Monitor | essun.monitor.com | 192.168.1.116 | 监控所有主机 |
-
虚拟ip(VIP)
DB1 192.168.1.109 192.168.1.24
DB2 192.168.1.112 192.168.1.24,192.168.1.22
DB3 192.168.1.113 192.168.1.23
三、拓扑图
四、实现过程
1、配置DB1
修改配置文件/etc/my.cnf,添加如下语句
server-<span style="COLOR: rgb(0,0,255)">id</span>=<span style="COLOR: rgb(128,0,128)">1</span><span style="COLOR: rgb(0,0,0)">log_bin</span>=/mariadb/data/mysql-<span style="COLOR: rgb(0,0,0)">binbinlog_format</span>=<span style="COLOR: rgb(0,0,0)">rowlog</span>-slave-<span style="COLOR: rgb(0,0,0)">updates sync_binlog</span>=<span style="COLOR: rgb(128,0,128)">1</span><span style="COLOR: rgb(0,0,0)">auto_increment_increment</span>=<span style="COLOR: rgb(128,0,128)">2# <span>默认地,AUTO_INCREMENT 的开始值是 1,每条新记录递增 1。</span></span><span style="COLOR: rgb(0,0,0)">auto_increment_offset</span>=<span style="COLOR: rgb(128,0,128)">1 </span>
授权用户
MariaDB [(none)]> grant replication slave,replication client on *.* to <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.112</span><span style="COLOR: rgb(128,0,0)">'</span> identified by <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.12</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>> grant replication slave,replication client on *.* to <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.113</span><span style="COLOR: rgb(128,0,0)">'</span> identified by <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
查看binlog日志标记
MariaDB [(none)]><span style="COLOR: rgb(0,0,0)"> show master status;</span>+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.<span style="COLOR: rgb(128,0,128)">000003</span> |<span style="COLOR: rgb(128,0,128)">756</span> |||+------------------+----------+--------------+------------------+<span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
2、配置DB2
修改配置文件/etc/my.cnf,添加如下语句
log-bin=mysql-<span style="COLOR: rgb(0,0,0)">binbinlog_format</span>=<span style="COLOR: rgb(0,0,0)">ROWlog</span>-slave-<span style="COLOR: rgb(0,0,0)">updatessync_binlog</span>=<span style="COLOR: rgb(128,0,128)">1</span><span style="COLOR: rgb(0,0,0)">auto_increment_increment</span>=<span style="COLOR: rgb(128,0,128)">2</span><span style="COLOR: rgb(0,0,0)">auto_increment_offset</span>=<span style="COLOR: rgb(128,0,128)">2</span><span style="COLOR: rgb(0,0,0)">server</span>-<span style="COLOR: rgb(0,0,255)">id</span>=<span style="COLOR: rgb(128,0,128)">2</span>
授权用户
MariaDB [(none)]> grant replication slave,replication client on *.* to <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.109</span><span style="COLOR: rgb(128,0,0)">'</span> identified by <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.15</span> sec)
查看binlog日志标记
MariaDB [(none)]><span style="COLOR: rgb(0,0,0)"> show master status;</span>+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.<span style="COLOR: rgb(128,0,128)">000007</span> |<span style="COLOR: rgb(128,0,128)">548</span> |||+------------------+----------+--------------+------------------+<span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
连接DB1
MariaDB [(none)]><span style="COLOR: rgb(0,0,0)"> show master status;</span>+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.<span style="COLOR: rgb(128,0,128)">000007</span> |<span style="COLOR: rgb(128,0,128)">548</span> |||+------------------+----------+--------------+------------------+<span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
3、配置DB3
修改配置文件/etc/my.cnf添加如下语句
server-<span style="COLOR: rgb(0,0,255)">id</span>=<span style="COLOR: rgb(128,0,128)">3</span><span style="COLOR: rgb(0,0,0)">log</span>-bin=mysql-<span style="COLOR: rgb(0,0,0)">binlog</span>-slave-<span style="COLOR: rgb(0,0,0)">updates<br></span><span>relay</span>-log=relay-log-bin
连接DB1
MariaDB [(none)]> change master to master_host=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.109</span><span style="COLOR: rgb(128,0,0)">'</span>,master_user=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>,master_password=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_file=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">mysql-bin.000003</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_pos=<span style="COLOR: rgb(128,0,128)">756</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.03</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> start slave;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.00</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> show slave status/G</span>*************************** <span style="COLOR: rgb(128,0,128)">1</span>. row ***************************<span style="COLOR: rgb(0,0,0)"> Slave_IO_State: Waiting </span><span style="COLOR: rgb(0,0,255)">for</span><span style="COLOR: rgb(0,0,0)"> master to send eventMaster_Host: </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.109</span><span style="COLOR: rgb(0,0,0)">Master_User: repluserMaster_Port: </span><span style="COLOR: rgb(128,0,128)">3306</span><span style="COLOR: rgb(0,0,0)">Connect_Retry: </span><span style="COLOR: rgb(128,0,128)">60</span><span style="COLOR: rgb(0,0,0)">Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000003</span><span style="COLOR: rgb(0,0,0)">Read_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">756</span><span style="COLOR: rgb(0,0,0)"> Relay_Log_File: relay</span>-log-bin.<span style="COLOR: rgb(128,0,128)">000002</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">535</span><span style="COLOR: rgb(0,0,0)">Relay_Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000003</span><span style="COLOR: rgb(0,0,0)"> Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table: Last_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_Error: Skip_Counter: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Exec_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">756</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Space: </span><span style="COLOR: rgb(128,0,128)">830</span><span style="COLOR: rgb(0,0,0)">Until_Condition: None Until_Log_File:Until_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Allowed: Yes Master_SSL_CA_File: </span>/etc/slave/<span style="COLOR: rgb(0,0,0)">cacert.pem Master_SSL_CA_Path:Master_SSL_Cert: </span>/etc/slave/<span style="COLOR: rgb(0,0,0)">mysql.crtMaster_SSL_Cipher: Master_SSL_Key: </span>/etc/slave/<span style="COLOR: rgb(0,0,0)">mysql.keySeconds_Behind_Master: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Last_IO_Error: Last_SQL_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_SQL_Error:Replicate_Ignore_Server_Ids: Master_Server_Id: </span><span style="COLOR: rgb(128,0,128)">1</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Crl: </span>/etc/slave/<span style="COLOR: rgb(0,0,0)">cacert.pem Master_SSL_Crlpath: Using_Gtid: NoGtid_IO_Pos:</span><span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)<span style="FONT-SIZE: 14px; FONT-FAMILY: verdana, Arial, Helvetica, sans-serif; LINE-HEIGHT: 1.5; BACKGROUND-COLOR: rgb(255,255,255)"> </span>
DB1连接DB2
MariaDB [(none)]> change master to master_host=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.112</span><span style="COLOR: rgb(128,0,0)">'</span>,master_user=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>,master_password=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_file=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">mysql-bin.000007</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_pos=<span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.03</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> start slave;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.00</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> show slave status/G</span>*************************** <span style="COLOR: rgb(128,0,128)">1</span>. row ***************************<span style="COLOR: rgb(0,0,0)"> Slave_IO_State: Waiting </span><span style="COLOR: rgb(0,0,255)">for</span><span style="COLOR: rgb(0,0,0)"> master to send eventMaster_Host: </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.112</span><span style="COLOR: rgb(0,0,0)">Master_User: repluserMaster_Port: </span><span style="COLOR: rgb(128,0,128)">3306</span><span style="COLOR: rgb(0,0,0)">Connect_Retry: </span><span style="COLOR: rgb(128,0,128)">60</span><span style="COLOR: rgb(0,0,0)">Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000007</span><span style="COLOR: rgb(0,0,0)">Read_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)"> Relay_Log_File: essun</span>-relay-bin.<span style="COLOR: rgb(128,0,128)">000002</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">535</span><span style="COLOR: rgb(0,0,0)">Relay_Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000007</span><span style="COLOR: rgb(0,0,0)"> Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table: Last_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_Error: Skip_Counter: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Exec_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Space: </span><span style="COLOR: rgb(128,0,128)">832</span><span style="COLOR: rgb(0,0,0)">Until_Condition: None Until_Log_File:Until_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher: Master_SSL_Key:Seconds_Behind_Master: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Last_IO_Error: Last_SQL_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_SQL_Error:Replicate_Ignore_Server_Ids: Master_Server_Id: </span><span style="COLOR: rgb(128,0,128)">2</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: NoGtid_IO_Pos:</span><span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
4、测试
在DB2中建立一个数据库testdb
MariaDB [(none)]> change master to master_host=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.112</span><span style="COLOR: rgb(128,0,0)">'</span>,master_user=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>,master_password=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_file=<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">mysql-bin.000007</span><span style="COLOR: rgb(128,0,0)">'</span>,master_log_pos=<span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.03</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> start slave;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.00</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>><span style="COLOR: rgb(0,0,0)"> show slave status/G</span>*************************** <span style="COLOR: rgb(128,0,128)">1</span>. row ***************************<span style="COLOR: rgb(0,0,0)"> Slave_IO_State: Waiting </span><span style="COLOR: rgb(0,0,255)">for</span><span style="COLOR: rgb(0,0,0)"> master to send eventMaster_Host: </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.112</span><span style="COLOR: rgb(0,0,0)">Master_User: repluserMaster_Port: </span><span style="COLOR: rgb(128,0,128)">3306</span><span style="COLOR: rgb(0,0,0)">Connect_Retry: </span><span style="COLOR: rgb(128,0,128)">60</span><span style="COLOR: rgb(0,0,0)">Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000007</span><span style="COLOR: rgb(0,0,0)">Read_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)"> Relay_Log_File: essun</span>-relay-bin.<span style="COLOR: rgb(128,0,128)">000002</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">535</span><span style="COLOR: rgb(0,0,0)">Relay_Master_Log_File: mysql</span>-bin.<span style="COLOR: rgb(128,0,128)">000007</span><span style="COLOR: rgb(0,0,0)"> Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table: Last_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_Error: Skip_Counter: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Exec_Master_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">548</span><span style="COLOR: rgb(0,0,0)">Relay_Log_Space: </span><span style="COLOR: rgb(128,0,128)">832</span><span style="COLOR: rgb(0,0,0)">Until_Condition: None Until_Log_File:Until_Log_Pos: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher: Master_SSL_Key:Seconds_Behind_Master: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)">Last_IO_Error: Last_SQL_Errno: </span><span style="COLOR: rgb(128,0,128)">0</span><span style="COLOR: rgb(0,0,0)"> Last_SQL_Error:Replicate_Ignore_Server_Ids: Master_Server_Id: </span><span style="COLOR: rgb(128,0,128)">2</span><span style="COLOR: rgb(0,0,0)"> Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: NoGtid_IO_Pos:</span><span style="COLOR: rgb(128,0,128)">1</span> row <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span> sec)
在DB1中对testdb,插入一条数据
MariaDB [testdb]> insert t1 values (<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">tom</span><span style="COLOR: rgb(128,0,0)">'</span>,<span style="COLOR: rgb(128,0,128)">24</span><span style="COLOR: rgb(0,0,0)">);Query OK, </span><span style="COLOR: rgb(128,0,128)">1</span> row affected (<span style="COLOR: rgb(128,0,128)">0.01</span> sec)
在DB3中查看结果
MariaDB [(none)]> <span style="COLOR: rgb(0,0,255)">select</span> *<span style="COLOR: rgb(0,0,0)"> from testdb.t1;</span>+------+-----+| name | age |+------+-----+| tom|<span style="COLOR: rgb(128,0,128)">24</span> || king |<span style="COLOR: rgb(128,0,128)">24</span> |+------+-----+<span style="COLOR: rgb(128,0,128)">2</span> rows <span style="COLOR: rgb(0,0,255)">in</span> set (<span style="COLOR: rgb(128,0,128)">0.00</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>>
OK!三台DB的主从配置正常工作
在DB1~3上安装mysql-mmmo-agent
注:mysql-mmm-agent是在epel源中,所以要下载EPEL源安装包即可http://download.fedoraproject.org/pub/epel/6/i386/repoview/epel-release.html
下载对应的版本就可以的。
#rpm -ivh epel-release-<span style="COLOR: rgb(128,0,128)">6</span>-<span style="COLOR: rgb(128,0,128)">8</span><span style="COLOR: rgb(0,0,0)">.noarch.rpm</span><span style="COLOR: rgb(0,0,255)">yum</span> -y <span style="COLOR: rgb(0,0,255)">install</span> mysql-mmm-agent
每一个节点都要安装
在每一个节点上要给Monitor授权用户
MariaDB [(none)]> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">mmm_agent</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.116</span><span style="COLOR: rgb(128,0,0)">'</span> IDENTIFIED BY <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">123456</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.01</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>> GRANT REPLICATION CLIENT ON *.* TO <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">mmm_monitor</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.116</span><span style="COLOR: rgb(128,0,0)">'</span> IDENTIFIED BY <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">123456</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.01</span><span style="COLOR: rgb(0,0,0)"> sec)MariaDB [(none)]</span>> GRANT REPLICATION CLIENT ON *.* TO <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">repluser</span><span style="COLOR: rgb(128,0,0)">'</span>@<span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">192.168.1.116</span><span style="COLOR: rgb(128,0,0)">'</span> IDENTIFIED BY <span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">replpass</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">;Query OK, </span><span style="COLOR: rgb(128,0,128)">0</span> rows affected (<span style="COLOR: rgb(128,0,128)">0.01</span> sec)
6、在Monitor节点上要安装
#<span style="COLOR: rgb(0,0,255)">yum</span> -y <span style="COLOR: rgb(0,0,255)">install</span> mysql-mmm*
此包同样也在epel源中
7、在Monitor端的设置/etc/mysql-mmm/mmm_common.conf
<span style="COLOR: rgb(0,0,0)">active_master_role writer</span><host default><span style="COLOR: rgb(0,0,0)"> cluster_interface eth0 pid_path </span>/var/run/mysql-mmm/<span style="COLOR: rgb(0,0,0)">mmm_agentd.pid bin_path </span>/usr/libexec/mysql-mmm/<span style="COLOR: rgb(0,0,0)"> replication_user repluser #复制用户 replication_password replpass #复制密码 agent_user mmm_agent #代理用户 agent_password </span><span style="COLOR: rgb(128,0,128)">123456</span><span style="COLOR: rgb(0,0,0)"> #代理用户的密码</span></host><host db1><span style="COLOR: rgb(0,0,0)"> ip </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.109</span><span style="COLOR: rgb(0,0,0)"> mode master peer db2</span></host><host db2><span style="COLOR: rgb(0,0,0)"> ip </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.112</span><span style="COLOR: rgb(0,0,0)"> mode master peer db1</span></host> <host db3><span style="COLOR: rgb(0,0,0)"> ip </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.113</span><span style="COLOR: rgb(0,0,0)"> mode slave</span></host><role writer><span style="COLOR: rgb(0,0,0)"> hosts db1, db2 ips </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.24</span><span style="COLOR: rgb(0,0,0)"> mode exclusive #排它</span></role> <role reader><span style="COLOR: rgb(0,0,0)"> hosts db2, db3 ips </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.22</span>, <span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.23</span><span style="COLOR: rgb(0,0,0)"> mode balanced #均衡</span></role>
将此文件分发到各DB1~3中的/etc/mysql-mmm/下
8、每一个DB中都会有mmm_agent的配置文件,编辑mmm_agent.conf
在数据库服务器上,还有一个mmm_agent.conf需要修改,其内容是:
<span style="COLOR: rgb(0,0,0)">include mmm_common.conf# The </span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">this</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)"> variable refers to this server.Proper operation requires# that </span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">this</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)"> server (db1 by default), as well as all other servers, have the# proper IP addresses set </span><span style="COLOR: rgb(0,0,255)">in</span><span style="COLOR: rgb(0,0,0)"> mmm_common.conf.this db2</span>
第一行表示:将之前Monitor中的mmm_common.conf文件载入到此文件中,供此文件中的参数设用。
最后一行标记此主机的角色(引用mmm_common.conf中的host段)在不同的数据库服务器上要分别改为db1和db3否则代理就会无法启动。
9、编辑mmm_mon.confg
在Monitor上,修改mmm_mon.conf文件,修改后内容为:
<span style="COLOR: rgb(0,0,0)">include mmm_common.conf</span><monitor><span style="COLOR: rgb(0,0,0)"> ip </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.116</span><span style="COLOR: rgb(0,0,0)"> #当前monitor主机地址 pid_path </span>/var/run/mysql-mmm/<span style="COLOR: rgb(0,0,0)">mmm_mond.pid bin_path </span>/usr/libexec/mysql-<span style="COLOR: rgb(0,0,0)">mmm status_path </span>/var/lib/mysql-mmm/<span style="COLOR: rgb(0,0,0)">mmm_mond.status ping_ips </span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.109</span>, <span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.112</span><span style="COLOR: rgb(0,0,0)"> #真实DB地址 auto_set_online </span><span style="COLOR: rgb(128,0,128)">10</span><span style="COLOR: rgb(0,0,0)"> # The kill_host_bin does not exist by default, though the monitor will # throw a warning about it missing.See the section </span><span style="COLOR: rgb(128,0,128)">5.10</span> <span style="COLOR: rgb(128,0,0)">"</span><span style="COLOR: rgb(128,0,0)">Kill Host</span> # Functionality<span style="COLOR: rgb(128,0,0)">"</span><span style="COLOR: rgb(128,0,0)"> in the PDF documentation.</span><span style="COLOR: rgb(0,0,0)"> # # kill_host_bin </span>/usr/libexec/mysql-mmm/monitor/<span style="COLOR: rgb(0,0,0)">kill_host #</span></monitor><host default><span style="COLOR: rgb(0,0,0)"> monitor_user mmm_monitor #监控DB的用户名 monitor_password </span><span style="COLOR: rgb(128,0,128)">123456</span><span style="COLOR: rgb(0,0,0)"> #密码</span></host><span style="COLOR: rgb(0,0,0)">debug </span><span style="COLOR: rgb(128,0,128)">0</span> #关闭debug功能,如果程序无法监控得到,可以使用debug 1查错
10、启动MMM
在各DB端启动mmm-agent
#cd /etc/init.d/<span style="COLOR: rgb(0,0,0)"># chkconfig mysql</span>-mmm-<span style="COLOR: rgb(0,0,0)">monitor on# service mysql</span>-mmm-monitor start
在Monitor端启动监控程序
#cd /etc/init.d/<span style="COLOR: rgb(0,0,0)"># chkconfig mysql</span>-mmm-<span style="COLOR: rgb(0,0,0)">monitor on# service mysql</span>-mmm-monitor start
过几秒钟,就可以使用mmm_control show查看在线监控端(DB)了
[root@essun ~]# service mysql-mmm-<span style="COLOR: rgb(0,0,0)">monitor statusmmm_mond (pid</span><span style="COLOR: rgb(128,0,128)">5395</span><span style="COLOR: rgb(0,0,0)">) is running...[root@essun </span>~<span style="COLOR: rgb(0,0,0)">]# mmm_control showdb1(</span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.109</span>) master/<span style="COLOR: rgb(0,0,0)">ONLINE. Roles:db2(</span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.112</span>) master/ONLINE. Roles: reader(<span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.22</span>), writer(<span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.24</span><span style="COLOR: rgb(0,0,0)">)db3(</span><span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.113</span>) slave/ONLINE. Roles: reader(<span style="COLOR: rgb(128,0,128)">192.168</span>.<span style="COLOR: rgb(128,0,128)">1.23</span>)
注:可以使用
[root@essun ~]# mmm_control --<span style="COLOR: rgb(0,0,0)">helpInvalid command </span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(128,0,0)">--help</span><span style="COLOR: rgb(128,0,0)">'</span><span style="COLOR: rgb(0,0,0)">Valid commands are: help </span>-<span style="COLOR: rgb(0,0,0)"> show this message </span><span style="COLOR: rgb(0,0,255)">ping</span> - <span style="COLOR: rgb(0,0,255)">ping</span><span style="COLOR: rgb(0,0,0)"> monitor show </span>-<span style="COLOR: rgb(0,0,0)"> show status checks [</span><host>|all [<check>|all]] -<span style="COLOR: rgb(0,0,0)"> show checks status set_online </span><host> - set host <host><span style="COLOR: rgb(0,0,0)"> online set_offline </span><host> - set host <host><span style="COLOR: rgb(0,0,0)"> offline mode </span>-<span style="COLOR: rgb(0,0,0)"> print current mode. set_active </span>-<span style="COLOR: rgb(0,0,0)"> switch into active mode. set_manual </span>-<span style="COLOR: rgb(0,0,0)"> switch into manual mode. set_passive </span>-<span style="COLOR: rgb(0,0,0)"> switch into passive mode. move_role [</span>--force] <role> <host> - move exclusive role <role> to host <host><span style="COLOR: rgb(0,0,0)"> (Only use </span>--force <span style="COLOR: rgb(0,0,255)">if</span> you know what you are doing!<span style="COLOR: rgb(0,0,0)">) set_ip </span><ip> <host> - set role with ip <ip> to host <host></host></ip></host></ip></host></role></host></role></host></host></host></host></check></host>
查看mmm_control的可用参数
11、模拟DB2下线
Monitor当前状态
让DB2下线,当前可写主机是db1,db3
db2没有下线之前还可以读写,当下线之后,可写的切换到DB1上了,所有读的都到了db3上了
当DB2重新上线后的情况如下
注:DB1、DB同时只能一有个写,一个读!
========================================== Mariadb高可用演示完毕========================

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

我们用户们在使用这款平台的时候应该都能够了解到上面对于一些功能的多样性,我们知道一些歌曲的歌词都写的非常的不错。有时候甚至都会多听几遍,觉得其中的含义都是非常深刻的,所以我们想要去了解其中的胜意,就想要直接的复制下来当文案来使用,不过对于要使用的话,还是要学会如何去复制歌词才可以,这些操作方面我相信大家们应该都并不模式,但是在手机上面操作确实是有点难度,所以为了能够让大家们更好的了解的话,今日小编就来为你们好好的讲解上面的一些操作体验,如果你们也喜欢的话,就和小编一起来看看吧,不要错过了。

华为手机如何实现双微信登录?随着社交媒体的兴起,微信已经成为人们日常生活中不可或缺的沟通工具之一。然而,许多人可能会遇到一个问题:在同一部手机上同时登录多个微信账号。对于华为手机用户来说,实现双微信登录并不困难,本文将介绍华为手机如何实现双微信登录的方法。首先,华为手机自带的EMUI系统提供了一个很便利的功能——应用双开。通过应用双开功能,用户可以在手机上同

如何在华为手机上实现微信分身功能随着社交软件的普及和人们对隐私安全的日益重视,微信分身功能逐渐成为人们关注的焦点。微信分身功能可以帮助用户在同一台手机上同时登录多个微信账号,方便管理和使用。在华为手机上实现微信分身功能并不困难,只需要按照以下步骤操作即可。第一步:确保手机系统版本和微信版本符合要求首先,确保你的华为手机系统版本已更新到最新版本,以及微信App

编程语言PHP是一种用于Web开发的强大工具,能够支持多种不同的编程逻辑和算法。其中,实现斐波那契数列是一个常见且经典的编程问题。在这篇文章中,将介绍如何使用PHP编程语言来实现斐波那契数列的方法,并附上具体的代码示例。斐波那契数列是一个数学上的序列,其定义如下:数列的第一个和第二个元素为1,从第三个元素开始,每个元素的值等于前两个元素的和。数列的前几个元

在当今的软件开发领域中,Golang(Go语言)作为一种高效、简洁、并发性强的编程语言,越来越受到开发者的青睐。其丰富的标准库和高效的并发特性使它成为游戏开发领域的一个备受关注的选择。本文将探讨如何利用Golang来实现游戏开发,并通过具体的代码示例来展示其强大的可能性。1.Golang在游戏开发中的优势作为一种静态类型语言,Golang在构建大型游戏系统

PHP游戏需求实现指南随着互联网的普及和发展,网页游戏的市场也越来越火爆。许多开发者希望利用PHP语言来开发自己的网页游戏,而实现游戏需求是其中一个关键步骤。本文将介绍如何利用PHP语言来实现常见的游戏需求,并提供具体的代码示例。1.创建游戏角色在网页游戏中,游戏角色是非常重要的元素。我们需要定义游戏角色的属性,比如姓名、等级、经验值等,并提供方法来操作这些

在PS复制图层快捷键中,我们可以知道使用PS的时候如果想要进行复制图层的操作,可以使用到快捷键【Ctrl+J】进行快速复制。这篇复制图层快捷键的介绍就能够告诉大家具体的操作方法,下面就是详细的内容,赶紧看看吧。PS复制图层快捷键答:【Ctrl+J】具体方法:1、在ps中打开图像,选中需要复制的图层。2、键盘同时按下【Ctrl+J】,即可完成对图层的复制。其他复制方式:1、打开图像后,按住图层,向下放【新建图层】图标移动。2、移动到该图标上后,松手。3、即可完成图层复制。

1、剪切指的是将选定的内容从一个位置移动到另一个位置的操作。2、复制操作是在选定的内容上创建一个副本,并将这个副本保存在系统的剪贴板中,且原内容会保留在原来的位置上。3、如果用户想把内容移动到其他位置并删除原来的位置上的内容,就可以使用剪切操作。4、如果用户需要创建内容的副本,且在不影响原内容的情况下将其粘贴到其他地方,那就要使用复制操作。
