配置MYSQL伺服器實現主主複製

來源:互聯網
上載者:User

標籤:mysql 主主複製

聲明

昨夜星辰

部落格:http://yestreenstars.blog.51cto.com/

本文由本人創作,如需轉載,請註明出處,謝謝合作!

目的

配置MYSQL伺服器實現主主複製。

實驗環境

伺服器1(以下簡稱S1):

IP:192.168.1.88


伺服器2(以下簡稱S2):

IP:192.168.1.89


OS:CentOS 6.2 32

MYSQL:5.1.73

配置

# 先停止S1和S2的iptables防火牆。service iptables stop# 修改S1的/etc/my.cnf檔案,在[mysqld]欄位下添加以下內容:log-bin=mysql-binlog-slave-updatesserver-id=1# 同理,修改S2的/etc/my.cnf檔案,在[mysqld]欄位下添加以下內容(注意server-id不能一樣):log-bin=mysql-binlog-slave-updatesserver-id=2# 重啟S1和S2的mysqld服務。service mysqld restart# 登入S2的資料庫,執行鎖表命令,防止在查看二進位記錄檔時有人對資料進行修改操作,然後再執行查看命令,記錄二進位記錄檔名和當前位置。mysql> flush tables with read lock;Query OK, 0 rows affected (0.00 sec)mysql> show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000003 |      191 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)# 登入S1的資料庫,建立用於複製的使用者並將S2配置成主複製伺服器(讀者注意根據實際情況修改具體參數)。mysql> grant replication slave on *.* to ‘slave‘@‘192.168.1.89‘ identified by ‘123456‘;Query OK, 0 rows affected (0.00 sec)mysql> change master to master_host=‘192.168.1.89‘,master_user=‘slave‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=191;Query OK, 0 rows affected (0.05 sec)# 在S1的資料庫上執行鎖表和查看二進位記錄檔資訊的命令。mysql> flush tables with read lock;Query OK, 0 rows affected (0.00 sec)mysql> show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000003 |      260 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)# 在S2的資料庫執行解鎖表命令,並建立用於複製的使用者並將S1配置成主複製伺服器。mysql> unlock tables;Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave on *.* to ‘slave‘@‘192.168.1.88‘ identified by ‘123456‘;Query OK, 0 rows affected (0.00 sec)mysql> change master to master_host=‘192.168.1.88‘,master_user=‘slave‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=260;Query OK, 0 rows affected (0.03 sec)# 在S1的資料庫執行解鎖表命令,並啟動複製。mysql> unlock tables;Query OK, 0 rows affected (0.00 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)# 在S2的資料庫啟動複製。mysql> start slave;Query OK, 0 rows affected (0.00 sec)# 最後,執行show slave status;命令可以查看配置是否成功,如果下面這兩個為YES即為成功。Slave_IO_Running: YesSlave_SQL_Running: Yes            # 讀者也可以通過建立資料庫等操作來驗證是否同步。


本文出自 “昨夜星辰” 部落格,請務必保留此出處http://yestreenstars.blog.51cto.com/1836303/1568800

配置MYSQL伺服器實現主主複製

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.