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高可用演示完毕========================

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

Wir Benutzer sollten in der Lage sein, die Vielfalt einiger Funktionen zu verstehen, wenn wir diese Plattform nutzen. Wir wissen, dass die Texte einiger Songs sehr gut geschrieben sind. Manchmal hören wir es sogar mehrmals und haben das Gefühl, dass die Bedeutung sehr tiefgreifend ist. Wenn wir die Bedeutung verstehen möchten, möchten wir sie jedoch direkt kopieren und als Text verwenden Sie müssen nur lernen, wie man Liedtexte kopiert. Ich glaube, Sie haben alle keine Erfahrung mit diesen Vorgängen, aber es ist in der Tat etwas schwierig, sie heute auf Ihrem Mobiltelefon zu bedienen Der Herausgeber ist hier, um Ihnen zu helfen. Wenn es Ihnen auch gefällt, schauen Sie es sich nicht an.

Wie implementiert man die doppelte WeChat-Anmeldung auf Huawei-Mobiltelefonen? Mit dem Aufkommen der sozialen Medien ist WeChat zu einem unverzichtbaren Kommunikationsmittel im täglichen Leben der Menschen geworden. Viele Menschen können jedoch auf ein Problem stoßen: Sie können sich gleichzeitig auf demselben Mobiltelefon bei mehreren WeChat-Konten anmelden. Für Huawei-Mobiltelefonbenutzer ist es nicht schwierig, eine doppelte WeChat-Anmeldung zu erreichen. In diesem Artikel wird erläutert, wie eine doppelte WeChat-Anmeldung auf Huawei-Mobiltelefonen erreicht wird. Erstens bietet das EMUI-System, das mit Huawei-Mobiltelefonen geliefert wird, eine sehr praktische Funktion – das doppelte Öffnen von Anwendungen. Durch die doppelte Öffnungsfunktion der Anwendung können Benutzer gleichzeitig

So implementieren Sie die WeChat-Klonfunktion auf Huawei-Mobiltelefonen Mit der Popularität sozialer Software und der zunehmenden Bedeutung von Datenschutz und Sicherheit rückt die WeChat-Klonfunktion allmählich in den Mittelpunkt der Aufmerksamkeit der Menschen. Die WeChat-Klonfunktion kann Benutzern helfen, sich gleichzeitig bei mehreren WeChat-Konten auf demselben Mobiltelefon anzumelden, was die Verwaltung und Nutzung erleichtert. Es ist nicht schwierig, die WeChat-Klonfunktion auf Huawei-Mobiltelefonen zu implementieren. Sie müssen lediglich die folgenden Schritte ausführen. Schritt 1: Stellen Sie sicher, dass die Version Ihres Mobiltelefonsystems und die WeChat-Version den Anforderungen entsprechen. Stellen Sie zunächst sicher, dass die Version Ihres Huawei-Mobiltelefonsystems sowie die WeChat-App auf die neueste Version aktualisiert wurden.

Die Programmiersprache PHP ist ein leistungsstarkes Werkzeug für die Webentwicklung, das eine Vielzahl unterschiedlicher Programmierlogiken und Algorithmen unterstützen kann. Unter diesen ist die Implementierung der Fibonacci-Folge ein häufiges und klassisches Programmierproblem. In diesem Artikel stellen wir vor, wie Sie die Fibonacci-Folge mit der Programmiersprache PHP implementieren, und fügen spezifische Codebeispiele bei. Die Fibonacci-Folge ist eine mathematische Folge, die wie folgt definiert ist: Das erste und das zweite Element der Folge sind 1, und ab dem dritten Element ist der Wert jedes Elements gleich der Summe der beiden vorherigen Elemente. Die ersten paar Elemente der Sequenz

Im heutigen Bereich der Softwareentwicklung wird Golang (Go-Sprache) als effiziente, prägnante und hochgradig parallele Programmiersprache von Entwicklern zunehmend bevorzugt. Seine umfangreiche Standardbibliothek und die effizienten Parallelitätsfunktionen machen es zu einer hochkarätigen Wahl im Bereich der Spieleentwicklung. In diesem Artikel wird untersucht, wie man Golang für die Spieleentwicklung verwendet, und seine leistungsstarken Möglichkeiten anhand spezifischer Codebeispiele demonstriert. 1. Golangs Vorteile bei der Spieleentwicklung: Als statisch typisierte Sprache wird Golang beim Aufbau großer Spielsysteme verwendet.

Implementierungsleitfaden für PHP-Spielanforderungen Mit der Popularität und Entwicklung des Internets erfreut sich der Markt für Webspiele immer größerer Beliebtheit. Viele Entwickler hoffen, die PHP-Sprache zur Entwicklung ihrer eigenen Webspiele nutzen zu können, und die Umsetzung der Spielanforderungen ist ein wichtiger Schritt. In diesem Artikel wird erläutert, wie Sie mithilfe der PHP-Sprache allgemeine Spielanforderungen implementieren und spezifische Codebeispiele bereitstellen. 1. Spielfiguren erstellen In Webspielen sind Spielfiguren ein sehr wichtiges Element. Wir müssen die Attribute des Spielcharakters wie Name, Level, Erfahrungswert usw. definieren und Methoden für deren Bedienung bereitstellen

In den PS-Tastenkombinationen zum Kopieren von Ebenen können wir erkennen, dass Sie zum schnellen Kopieren die Tastenkombination [Strg+J] verwenden können, wenn Sie eine Ebene mit PS kopieren möchten. Diese Einführung in die Tastenkombinationen zum Kopieren von Ebenen kann Ihnen die spezifische Operationsmethode erläutern. Im Folgenden finden Sie den detaillierten Inhalt. Schauen Sie sich also um. PS-Tastenkombination zum Kopieren der Ebene: [Strg+J] Spezifische Methode: 1. Öffnen Sie das Bild in PS und wählen Sie die Ebene aus, die kopiert werden muss. 2. Drücken Sie gleichzeitig [Strg+J] auf der Tastatur, um das Kopieren der Ebene abzuschließen. Andere Kopiermethoden: 1. Nachdem Sie das Bild geöffnet haben, halten Sie die Ebene gedrückt und verschieben Sie das Symbol [Neue Ebene] nach unten. 2. Nachdem Sie sich zum Symbol bewegt haben, lassen Sie es los. 3. Die Ebenenkopie ist abgeschlossen.

1. Unter Schneiden versteht man den Vorgang des Verschiebens ausgewählter Inhalte von einer Position an eine andere. 2. Der Kopiervorgang erstellt eine Kopie des ausgewählten Inhalts und speichert die Kopie in der Zwischenablage des Systems. Der ursprüngliche Inhalt bleibt an seinem ursprünglichen Speicherort. 3. Wenn der Benutzer den Inhalt an einen anderen Ort verschieben und den Inhalt am ursprünglichen Ort löschen möchte, kann er den Ausschneidevorgang verwenden. 4. Wenn der Benutzer eine Kopie des Inhalts erstellen und an anderer Stelle einfügen muss, ohne den Originalinhalt zu beeinträchtigen, verwenden Sie den Kopiervorgang.
