MySQL雙方配置實驗步驟

來源:互聯網
上載者:User

標籤:雙主   複製   mysql   

實驗環境:

    兩台MariaDB伺服器,IP分別為: 172.16.2.16 和 172.16.2.17

    MariaDB的版本是5.5.36,使用二進位方式安裝。已安裝完成。

    /mydata/data  資料庫檔案存放目錄

    /mydata/binlog/ 二進位記錄檔存放位置

    /mydata/relaylog/ 中繼日誌存放位置

實驗目地:

    把兩台伺服器搭建為兩主模型工作。

實驗操作過程:

172.16.2.16的配置過程

/etc/my.cnf設定檔[mysqld]段如下

[mysqld]port = 3306socket = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 4Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size= 16Mthread_concurrency = 8auto-increment-increment = 2                設定自動成長的每次增進值,此伺服器的增長值為奇數auto-increment-offset = 1              設定自動成長值的初始值log-bin=/mydata/binlog/mysql-bin       修改二進位記錄檔存放位置relay-log=/mydata/relaylog/relay-log    中繼日誌存入位置binlog_format=mixedserver-id= 1                      這裡使用預設的server-iddatadir=/mydata/data              設定資料庫存放的目錄sync_binlog = 1           設定二進位日誌工作特性為即時把日誌寫入二進位記錄檔

為對方節點授權

MariaDB [(none)]> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO [email protected]‘172.16.2.17‘ IDENTIFIED BY ‘slavepass‘;MariaDB [(none)]> FLUSH PRIVILEGES;


172.16.2.17節點配置資訊

/etc/my.cnf設定檔[mysqld]段如下

[mysqld]port = 3306socket = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 4Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size= 16Mthread_concurrency = 8log-bin=/mydata/binlog/mysql-binrelay-log=/mydata/relaylog/relay-logbinlog_format=mixedserver-id= 2                        這裡server-id為2datadir=/mydata/dataauto-increment-increment = 2auto-increment-offset = 2

為對方節點授權

MariaDB [(none)]> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO [email protected]‘172.16.2.16‘ IDENTIFIED BY ‘slavepass‘;MariaDB [(none)]> FLUSH PRIVILEGES;

    

在雙方節點分別串連對方節點,在串連對方前,需要知道對方當前使用的二進位記錄檔及檔案中事務的位置

在節點一查看當前二進位日誌資訊,得到使用的記錄檔為  mysql-bin.000012  ,最新的事件ID是 676  

MariaDB [(none)]> SHOW MASTER STATUS; [object Object]

在第二個節點串連第一個節點

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘172.16.2.16‘, MASTER_USER=‘slaveuser‘,MASTER_PASSWORD=‘slavepass‘,MASTER_LOG_FILE=‘mysql-bin.000012‘, MASTER_LOG_POS=676;MariaDB [(none)]> START SLAVE;

在節點一查看當前二進位日誌資訊,得到使用的記錄檔為  mysql-bin.000006 ,最新的事件ID是 245

MariaDB [(none)]> SHOW MASTER STATUS;

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/49/CF/wKioL1Qa_MaRwep9AACVhy_r-k0841.jpg" title="clipboard.png" alt="wKioL1Qa_MaRwep9AACVhy_r-k0841.jpg" />

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘172.16.2.17‘, MASTER_USER=‘slaveuser‘,MASTER_PASSWORD=‘slavepass‘,MASTER_LOG_FILE=‘mysql-bin.000006‘, MASTER_LOG_POS=245;MariaDB [(none)]> START SLAVE;

配置完成後測試:

    1,在第一個節點上建立資料庫,然後到第二個節點查看,如果有說明複製成功。

    2,在第二個節點上為第一個節點建立的資料庫建立表,在第一個節點查看,如果有說明雙向複製沒有問題。


本文出自 “紅顏易逝豪情長” 部落格,請務必保留此出處http://wukui.blog.51cto.com/1080241/1554971

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.