欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

mysql-mmm主主復(fù)制定義與解析

本文主要給大家介紹MySQL-mmm主主復(fù)制定義與解析,希望可以給大家補(bǔ)充和更新些知識,如有其它問題需要了解的可以持續(xù)在創(chuàng)新互聯(lián)行業(yè)資訊里面關(guān)注我的更新文章的。

在信宜等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需求定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,成都全網(wǎng)營銷,外貿(mào)網(wǎng)站建設(shè),信宜網(wǎng)站建設(shè)費(fèi)用合理。

        mysql-MMM主主復(fù)制

MMM(Master-Master replication manager for MySQL)是一套支持雙主故障切換和雙主日常管理的腳本程序,主要管理雙主復(fù)制,而實(shí)際上在應(yīng)用中只有一個主負(fù)責(zé)寫的操作,另一臺待機(jī)冗余,或者負(fù)責(zé)讀的一部分操作。還可以結(jié)合主從復(fù)制,分離讀寫請求。

mmm分為agent端和monitor端,agent端部署在數(shù)據(jù)庫節(jié)點(diǎn)上,monitor部署在監(jiān)控管理端。monitor在整個數(shù)據(jù)庫集群中是唯一存在的單點(diǎn)故障的點(diǎn),因?yàn)閙onitor端只復(fù)制監(jiān)控和管理agent節(jié)點(diǎn),任務(wù)量非常的輕,一般不會出現(xiàn)什么故障的,而且monitor端在為agent數(shù)據(jù)庫云服務(wù)器分配完vip地址后,即使停止了monitor服務(wù),也不會影響業(yè)務(wù)的,只需要及時的修復(fù)即可。實(shí)在不放心可以為monitor部署keepalived.

環(huán)境

主機(jī)名:系統(tǒng):IP地址:安裝軟件:數(shù)據(jù)庫角色
m1centos6.5192.168.100.150mysql mysql-server mysql-mmm*master
m2centos6.5192.168.100.151mysql mysql-server mysql-mmm*master
m3centos6.5192.168.100.152mysql mysql-server mysql-mmm*slave
m4centos6.5192.168.100.153mysql mysql-server mysql-mmm*slave
monitorcentos6.5192.168.100.154mysql   mysql-mmm*monitor監(jiān)控

數(shù)據(jù)庫角色,和對應(yīng)vip:

主機(jī):vip角色
m1192.168.100.250
write負(fù)責(zé)寫的操作
m2write平時不工作,待機(jī)冗余
m3192.168.100.201read讀的操作
m4192.168.100.202read讀的操作

修改主機(jī)名:依次修改m1 m2 m3 m4 monitor

分別在m1 - m4 安裝mysql服務(wù):

[root@m1 ~]# yum -y install mysql mysql-server mysql-devel
[root@m2 ~]# yum -y install mysql mysql-server mysql-devel
[root@m3 ~]# yum -y install mysql mysql-server mysql-devel
[root@m4 ~]# yum -y install mysql mysql-server mysql-devel

修改m1的mysql主配置文件:

[root@m1 ~]# vi /etc/my.cnf 
    
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/lib/mysql/mysql.err
slow_query_log_file=/var/lib/mysql/slow_query_log.log
user=mysql
character-set-server=utf8
log-bin=mysql-bin
server-id=150
binlog-ignore-db=mysql,information_schema
log-slave-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[client]
default_character_set=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

啟動mysql服務(wù),查看是否啟動

[root@m1 ~]# /etc/init.d/mysqld start
[root@m1 ~]# netstat -utpln |grep 3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1359/mysqld

     

將mysql的主配置文件同步到m2、m3、m4服務(wù)器

[root@m1 ~]# for i in 1 2 3;do scp /etc/my.cnf root@192.168.100.15$i:/etc/;done
The authenticity of host '192.168.100.151 (192.168.100.151)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.151' (RSA) to the list of known hosts.
root@192.168.100.151's password: 
my.cnf                                            100%  465     0.5KB/s   00:00    
The authenticity of host '192.168.100.152 (192.168.100.152)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.152' (RSA) to the list of known hosts.
root@192.168.100.152's password: 
my.cnf                                            100%  465     0.5KB/s   00:00    
The authenticity of host '192.168.100.153 (192.168.100.153)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.153' (RSA) to the list of known hosts.
root@192.168.100.153's password: 
my.cnf                                            100%  465     0.5KB/s   00:00

 

登陸數(shù)據(jù)庫查看該數(shù)據(jù)庫的bin-log文件名和偏移量:

    記下File Position的信息,等會要在m1-m2-m3數(shù)據(jù)庫上用到。

[root@m1 ~]# mysqladmin -uroot password 123123
[root@m1 ~]# mysql -uroot -p123123
mysql> show master status;
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql-bin.000003 |      249 |              | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)

授權(quán)允許復(fù)制

mysql> grant replication slave on *.* to 'replication'@'192.168.100.%' identified by '123123';
Query OK, 0 rows affected (0.02 sec)
    ##授權(quán)replication用戶在192.168.100.0這個網(wǎng)段有對數(shù)據(jù)庫復(fù)制的權(quán)限
mysql> flush privileges;    ##刷新權(quán)限
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

更改m2數(shù)據(jù)庫配置文件

    這是m1服務(wù)器同步過來的配置文件,只需將server-id改了就可以了,server-id在mysql集群中是唯一的標(biāo)識符,在這里以ip地址結(jié)尾定義了

[root@m2 ~]# sed -i '/server-id/s/150/151/g' /etc/my.cnf 
[root@m2 ~]# grep id /etc/my.cnf 
server-id=151
pid-file=/var/run/mysqld/mysqld.pid

啟動登入數(shù)據(jù)庫

[root@m2 ~]# /etc/init.d/mysqld start
[root@m2 ~]# mysqladmin -uroot password 123123
[root@m2 ~]# mysql -uroot -p123123

在m2上查看bin-log文件和偏移量記錄下來,并授權(quán)用戶復(fù)制權(quán)限

mysql> show master status;
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql-bin.000003 |      249 |              | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
mysql> grant replication slave on *.* to 'replication'@'192.168.100.%' identified by '123123';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)

在m1上添加另一個主m2 同步數(shù)據(jù)

[root@m1 ~]# mysql -uroot -p123123
mysql> change master to
    -> master_host='192.168.100.151',   ##m2的ip
    -> master_user='replication',  ##m2上面授權(quán)的用戶
    -> master_password='123123',    ##m2上授權(quán)用戶的密碼
    -> master_log_file='mysql-bin.000003',  ##m2的bin-log文件(剛剛在m2上查到的)
    -> master_log_pos=249;    ##日志文件的偏移量
Query OK, 0 rows affected (0.08 sec)

指定完了以后啟動同步

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

查看同步狀態(tài)信息:

    這兩項(xiàng)都為yes算是成功了

            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.151
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 495
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 497
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 495
              Relay_Log_Space: 653
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 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: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)
ERROR: 
No query specified

在m2上添加m2的另一個主m1:

mysql> change master to
    -> master_host='192.168.100.150',
    -> master_user='replication',
    -> master_password='123123',
    -> master_log_file='mysql-bin.000003',
    -> master_log_pos=249;
Query OK, 0 rows affected (0.10 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.150
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 741
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 497
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 741
              Relay_Log_Space: 653
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 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: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)
ERROR: 
No query specified

驗(yàn)證:

在m1和m2上各創(chuàng)建個庫驗(yàn)證是否同步:

    m1上創(chuàng)建

mysql> create database m1_test;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m1_test            |
| mysql              |
| test               |
|          |
+--------------------+
5 rows in set (0.00 sec)

m2上查看

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m1_test            |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.07 sec)

m2上新建庫

mysql> create database test_m2;
Query OK, 1 row affected (0.04 sec)

m1上查看

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m1_test            |
| mysql              |
| test               |
| test_m2            |
+--------------------+
5 rows in set (0.00 sec)

正常同步了。

在m3-m4從數(shù)據(jù)庫上指定主的數(shù)據(jù)庫

[root@m3 ~]# sed -i '/server-id/s/150/152/g' /etc/my.cnf
[root@m3 ~]# grep id /etc/my.cnf 
server-id=152
pid-file=/var/run/mysqld/mysqld.pid
[root@m3 ~]# /etc/init.d/mysqld start
[root@m3 ~]# mysqladmin -uroot password 123123
[root@m3 ~]# mysql -uroot -p123123
mysql> change master to
    -> master_host='192.168.100.150',
    -> master_user='replication',
    -> master_password='123123',
    -> master_log_file='mysql-bin.000003',
    -> master_log_pos=249;
Query OK, 0 rows affected (0.08 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.150
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 929
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 931
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 929
              Relay_Log_Space: 1087
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 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: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.04 sec)
ERROR: 
No query specified
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m1_test            |
| mysql              |
| test               |
| test_m2            |
+--------------------+
5 rows in set (0.08 sec)
mysql>
[root@m4 ~]# sed -i '/server-id/s/150/153/g' /etc/my.cnf
[root@m4 ~]# grep id /etc/my.cnf 
server-id=153
pid-file=/var/run/mysqld/mysqld.pid
[root@m4 ~]# /etc/init.d/mysqld start
[root@m4 ~]# mysqladmin -uroot password 123123
[root@m4 ~]# mysql -uroot -p123123
mysql> change master to
    -> master_host='192.168.100.150',
    -> master_user='replication',
    -> master_password='123123',
    -> master_log_file='mysql-bin.000003',
    -> master_log_pos=249;
Query OK, 0 rows affected (0.10 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.150
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 929
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 931
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 929
              Relay_Log_Space: 1087
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 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: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)
ERROR: 
No query specified
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m1_test            |
| mysql              |
| test               |
| test_m2            |
+--------------------+
5 rows in set (0.00 sec)

安裝mysql-mmm:

    下載epel擴(kuò)展yum源:  在所用服務(wù)器上執(zhí)行

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

     安裝mmm軟件:   在所有服務(wù)器上執(zhí)行

yum -y install mysql-mmm*

授權(quán): 在m1上授權(quán),其他主機(jī)會自動同步權(quán)限

[root@m1 ~]# mysql -uroot -p123123

mysql> grant replication client on *.* to 'mmm_monitor'@'192.168.100.%' identified by 'monitor';
Query OK, 0 rows affected (0.02 sec)
mysql> grant super,replication client,process on *.* to 'mmm_agent'@'192.168.100.&' identified by 'agent';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

修改配置文件: mmm_common.conf(所有節(jié)點(diǎn)的通用配置文件)

[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   ##復(fù)制同步的用戶名
    replication_password    123123    ##同步的密碼
    agent_user              mmm_agent   ##代理的用戶名
    agent_password          agent   ##代理密碼
</host>  
<host db1>
    ip      192.168.100.150
    mode    master
    peer    db2
</host>
<host db2>
    ip      192.168.100.151
    mode    master
    peer    db1
</host>
<host db3>
    ip      192.168.100.152
    mode    slave
</host>
<host db4>
    ip      192.168.100.153
    mode    slave
</host>
<role writer>
    hosts   db1, db2
    ips     192.168.100.250    ##寫的vip
    mode    exclusive      ##獨(dú)占模式
</role>
<role reader>
    hosts   db3, db4
    ips     192.168.100.201, 192.168.100.202   ##讀的vip
    mode    balanced    ##平衡模式
</role>

同步配置文件到m1 m2 m3 m4 上:

[root@monitor ~]# for i in 150 151 152 153;do scp /etc/mysql-mmm/mmm_common.conf root@192.168.100.$i:/etc/mysql-mmm/;done
The authenticity of host '192.168.100.150 (192.168.100.150)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.150' (RSA) to the list of known hosts.
root@192.168.100.150's password: 
mmm_common.conf                                           100%  851     0.8KB/s   00:00    
The authenticity of host '192.168.100.151 (192.168.100.151)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.151' (RSA) to the list of known hosts.
root@192.168.100.151's password: 
mmm_common.conf                                           100%  851     0.8KB/s   00:00    
The authenticity of host '192.168.100.152 (192.168.100.152)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.152' (RSA) to the list of known hosts.
root@192.168.100.152's password: 
mmm_common.conf                                           100%  851     0.8KB/s   00:00    
The authenticity of host '192.168.100.153 (192.168.100.153)' can't be established.
RSA key fingerprint is 6b:3d:8b:50:dc:45:ea:58:38:6e:5d:0d:9b:8f:04:f2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.153' (RSA) to the list of known hosts.
root@192.168.100.153's password: 
mmm_common.conf                                           100%  851     0.8KB/s   00:00

修改數(shù)據(jù)庫mysql-m1到mysql-m4:

[root@m1 ~]# vi /etc/mysql-mmm/mmm_agent.conf 
[root@m1 ~]# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db1
[root@m2 ~]# vi /etc/mysql-mmm/mmm_agent.conf 
[root@m2 ~]# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db2
[root@m3 ~]# vi /etc/mysql-mmm/mmm_agent.conf 
[root@m3 ~]# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db3
[root@m4 ~]# vi /etc/mysql-mmm/mmm_agent.conf 
[root@m4 ~]# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db4
[root@monitor ~]# vi /etc/mysql-mmm/mmm_mon.conf 
[root@monitor ~]# cat /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.100.150, 192.168.100.151, 192.168.100.152, 192.168.100.153
        ##監(jiān)測每個節(jié)點(diǎn)數(shù)據(jù)庫:修改為每個服務(wù)器的真實(shí)ip地址
    auto_set_online     60     ##自動上線時間,
</monitor>
<host default>
    monitor_user        mmm_monitor     ##監(jiān)控服務(wù)的用戶名
    monitor_password    monitor     ##監(jiān)控服務(wù)的密碼,這兩項(xiàng)是在m1上授權(quán)的
</host>
debug 0

啟動服務(wù):m1-m4的mmm-agent服務(wù); 監(jiān)控端的mmm-monitor服務(wù)

[root@m1 ~]# /etc/init.d/mysql-mmm-agent start
Starting MMM Agent Daemon:                                 [確定]
[root@m1 ~]#
[root@m2 ~]# 
[root@m2 ~]# /etc/init.d/mysql-mmm-agent start
Starting MMM Agent Daemon:                                 [確定]
[root@m3 ~]# /etc/init.d/mysql-mmm-agent start
Starting MMM Agent Daemon:                                 [確定]
[root@m4 ~]# /etc/init.d/mysql-mmm-agent start
Starting MMM Agent Daemon:                                 [確定]

[root@monitor ~]# /etc/init.d/mysql-mmm-monitor start
Starting MMM Monitor Daemon:                               [確定]

查看各代理數(shù)據(jù)庫狀態(tài)

[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/ONLINE. Roles: writer(192.168.100.250)
  db2(192.168.100.151) master/ONLINE. Roles: 
  db3(192.168.100.152) slave/ONLINE. Roles: reader(192.168.100.201)
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.202)

            ##發(fā)現(xiàn)寫的請求交給db1的vip,讀的請求交給db3 db4 vip

使用vip登錄數(shù)據(jù)庫:

    先在m1上授權(quán):因?yàn)樵O(shè)置了同步,只在一個數(shù)據(jù)庫上授權(quán),其他數(shù)據(jù)庫會同步權(quán)限

[root@m1 ~]# mysql -uroot -p123123 -s
mysql> grant all on *.* to 'root'@192.168.100.154 identified by '123123';
mysql> flush privileges;
[root@monitor ~]# mysql -uroot -p123123 -h 192.168.100.250 -s
mysql> show databases;
Database
information_schema
m1_test
mysql
test
test_m2

登陸讀的數(shù)據(jù)庫:

[root@monitor ~]# mysql -uroot -p123123 -h 192.168.100.201 -s
mysql> show databases;
Database
information_schema
m1_test
mysql
test
test_m2
mysql>

在生產(chǎn)環(huán)境中,只需在應(yīng)用服務(wù)器上,指定寫數(shù)據(jù)的vip地址,和讀數(shù)據(jù)的vip地址池即可。

測試:

    模擬主服務(wù)器m1故障,將mysql停止了,再查看狀態(tài):

[root@m1 ~]# /etc/init.d/mysqld stop
停止 mysqld:                                              [確定]
[root@m1 ~]#
[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/HARD_OFFLINE. Roles:   ##顯示為離線狀態(tài)
  db2(192.168.100.151) master/ONLINE. Roles: writer(192.168.100.250)  ##vip轉(zhuǎn)移到db2
  db3(192.168.100.152) slave/ONLINE. Roles: reader(192.168.100.201)
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.202)

    再把m1啟動

[root@m1 ~]# /etc/init.d/mysqld start
正在啟動 mysqld:                                          [確定]
[root@m1 ~]#
[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/AWAITING_RECOVERY. Roles:   ##恢復(fù)狀態(tài)
  db2(192.168.100.151) master/ONLINE. Roles: writer(192.168.100.250)
  db3(192.168.100.152) slave/ONLINE. Roles: reader(192.168.100.201)
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.202)
[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/ONLINE. Roles:   ##在線狀態(tài)
  db2(192.168.100.151) master/ONLINE. Roles: writer(192.168.100.250)
  db3(192.168.100.152) slave/ONLINE. Roles: reader(192.168.100.201)
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.202)

    模擬從數(shù)據(jù)庫m3故障,將數(shù)據(jù)庫mysql停止查看狀態(tài),再啟動查看狀態(tài)

[root@m3 ~]# /etc/init.d/mysqld stop
停止 mysqld:                                              [確定]

        此時會將讀數(shù)據(jù)庫db3的vip轉(zhuǎn)移到db4;db4暫時負(fù)責(zé)讀的操作

[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/ONLINE. Roles: 
  db2(192.168.100.151) master/ONLINE. Roles: writer(192.168.100.250)
  db3(192.168.100.152) slave/HARD_OFFLINE. Roles: 
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.201), reader(192.168.100.202)
[root@m3 ~]# /etc/init.d/mysqld start
正在啟動 mysqld:                                          [確定]
[root@m3 ~]#

        在db3數(shù)據(jù)庫恢復(fù)正常后,vip會轉(zhuǎn)移回來,從新工作接受讀的操作

[root@monitor ~]# mmm_control show
  db1(192.168.100.150) master/ONLINE. Roles: 
  db2(192.168.100.151) master/ONLINE. Roles: writer(192.168.100.250)
  db3(192.168.100.152) slave/ONLINE. Roles: reader(192.168.100.201)
  db4(192.168.100.153) slave/ONLINE. Roles: reader(192.168.100.202)

看了以上關(guān)于mysql-mmm主主復(fù)制定義與解析,希望能給大家在實(shí)際運(yùn)用中帶來一定的幫助。本文由于篇幅有限,難免會有不足和需要補(bǔ)充的地方,如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時售前售后,隨時幫您解答問題的。

 

分享文章:mysql-mmm主主復(fù)制定義與解析
鏈接分享:http://www.chinadenli.net/article42/jogdec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)網(wǎng)站設(shè)計公司靜態(tài)網(wǎng)站微信小程序搜索引擎優(yōu)化用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)