mysql+AA主主

來源:互聯網
上載者:User

標籤:password   設定檔   service   伺服器   防火牆   

mysql主主(AA)

實驗環境

master-1 192.168.3.1
master-2 192.168.3.10

關閉防火牆(兩台)
[[email protected] ~]# service iptables stop
[[email protected] ~]# setenforce 0


設定密碼
[[email protected] ~]# mysqladmin -u root password 123456

一、master-1操作
(1)安裝ntp時間伺服器
[[email protected] ~]# yum -y install ntp
[[email protected] ~]# vim /etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 8
[[email protected] ~]# service ntp restart

(2)修改設定檔
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=mysql-binlog
[[email protected] ~]# service mysqld restart

(3)授權使用者
[[email protected] ~]# mysql -u root -p123456
mysql>
mysql>  grant replication slave on *.* to ‘slave‘@‘192.168.3.10‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

(4)匯出資料
[[email protected] ~]# mysqldump -u root -p123456 --all-databases > /root/alldb.sql
[[email protected] ~]# scp /root/alldb.sql [email protected]:/root

二、master-2操作

(1)時間同步
[[email protected] ~]# yum -y install ntpdate
[[email protected] ~]# usr/sbin/ntpdate 192.168.3.10
[[email protected] ~]# service ntpd restart

(2)修改設定檔
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-binlog
[[email protected] ~]#  service mysqld restart

(3)授權使用者
[[email protected] ~]# mysql -u root -p123456
mysql>
mysql>  grant replication slave on *.* to ‘master‘@‘192.168.3.1‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

(4)匯出資料
[[email protected] ~]# mysqldump -u root -p123456 --all-databases > /root/alldba.sql
[[email protected] ~]# scp /root/alldba.sql [email protected]:/root

三、master-1操作

[[email protected] ~]# mysql -u root -p123456
mysql> show master status;
+---------------------+----------+--------------+------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000001 |      337 |              |                  |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

四、master-2操作
[[email protected] ~]# mysql -u root -p123456
mysql> change master to
    -> master_host=‘192.168.3.1‘,
    -> master_user=‘slave‘,
    -> master_password=‘123456‘,
    -> master_log_file=‘mysql-binlog.000001‘,
    -> master_log_pos=337;
Query OK, 0 rows affected (0.06 sec)

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

mysql> show master status;
+---------------------+----------+--------------+------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000001 |      336 |              |                  |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

五、master-1操作

[[email protected] ~]# mysql -u root -p123456
mysql> change master to
    -> master_host=‘192.168.3.10‘,
    -> master_user=‘master‘,
    -> master_password=‘123456‘,
    -> master_log_file=‘mysql-binlog.000001‘,
    -> master_log_pos=336;
Query OK, 0 rows affected (0.06 sec)

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

六、分別master-1 和 master-2上面查看sql/io線程是否開啟

(1)master-1查看

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.3.10
                  Master_User: myslave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-binlog.000001
          Read_Master_Log_Pos: 417
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 335
        Relay_Master_Log_File: mysql-binlog.000001
             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: 417
              Relay_Log_Space: 491
              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)


(2)master-2查看
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.3.1
                  Master_User: myslave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-binlog.000001
          Read_Master_Log_Pos: 785
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 702
        Relay_Master_Log_File: mysql-binlog.000001
             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: 785
              Relay_Log_Space: 858
              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)

註:兩端都為Yes 則成功

七、測試
1、在master-1查看庫
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.07 sec)

2.在master-2上面查看庫
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

註:兩台資料一模一樣,我們現在在master-1上面建立一個庫,看能否同步

3、在master-1建立庫

mysql> create database fuzhenyang;
Query OK, 1 row affected (0.00 sec)

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

mysql>

4、我們在master-2上面查看是否同步過來了
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| fuzhenyang         |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql>

此時我們已經看到fuzhenyang庫已經同步過來了

同樣操作在master-2上面建立庫看是否在master-1上面同步 如果能,mysql主從(AA)實驗完畢

本文出自 “空懷感” 部落格,轉載請與作者聯絡!

mysql+AA主主

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.