MySQL主主複製

來源:互聯網
上載者:User

標籤:mysql

(1)伺服器1的配置1)安裝mariadb-server
[[email protected] ~]# yum -y install mariadb-server
2)編輯/etc/my.cnf檔案
[[email protected] ~]# vim /etc/my.cnf    在[mysqld]段的最後添加以下內容    skip_name_resolve = ON    innodb_file_per_table = ON    server-id = 1 (id號不能跟從伺服器相同)    log-bin = master-log (自訂主伺服器的二進位記錄檔名)    relay-log = slave-log (自訂從伺服器的二進位記錄檔名)    auto_increment_offset = 1     auto_increment_increment = 2
3)在伺服器2上查看的master狀態
MariaDB [(none)]> show master status\G*************************** 1. row ***************************            File: master-log.000003        Position: 422    Binlog_Do_DB: Binlog_Ignore_DB:
4)啟動mariadb server並進行如下配置
[[email protected] ~]# systemctl start mariadb.service[[email protected] ~]# mysql    MariaDB [(none)]> grant replication slave,replication client on *.* to ‘repluser‘@‘10.1.51.%‘ identified by ‘replpasswd‘;    MariaDB [(none)]> change master to master_host=‘10.1.51.50‘,master_user=‘repluser‘,master_password=‘replpasswd‘,master_log_file=‘master-log.000003‘,master_log_pos=422;    MariaDB [(none)]> start slave;    MariaDB [(none)]> SHOW SLAVE STATUS\G (僅是部分內容)        Master_Host: 10.1.51.50        Master_User: repluser        Master_Port: 3306        Connect_Retry: 60        Master_Log_File: master-log.000003        Read_Master_Log_Pos: 422        Relay_Log_File: slave-log.000002        Relay_Log_Pos: 530        Relay_Master_Log_File: master-log.000003        Slave_IO_Running: Yes        Slave_SQL_Running: Yes        Master_Server_Id: 2
(2)伺服器2的配置1)安裝mariadb-server
[[email protected] ~]# yum -y install mariadb-server
2)編輯/etc/my.cnf檔案
[[email protected] ~]# vim /etc/my.cnf    skip_name_resolve = ON    innodb_file_per_table = ON    server-id = 2    relay-log = slave-log    lob-bin = master-log    auto_increment_offset = 2     auto_increment_increment = 2
3)在伺服器1查看master狀態
MariaDB [(none)]> show master status\G*************************** 1. row ***************************            File: master-log.000003        Position: 245    Binlog_Do_DB: Binlog_Ignore_DB:
4)啟動mariadb server並配置
[[email protected] ~]# systemctl start mariadb.service[[email protected] ~]# mysql    MariaDB [(none)]> grant replication slave,replication client on *.* to ‘repluser‘@‘10.1.51.%‘ identified by ‘replpasswd‘;    MariaDB [(none)]> change master to master_host=‘10.1.51.60‘,master_user=‘repluser‘,master_password=‘replpasswd‘,master_log_file=‘master-log.000003‘,master_log_pos=245;    MariaDB [(none)]> start slave;    MariaDB [(none)]> show slave status\G (僅是部分內容)          Master_Host: 10.1.51.60        Master_User: repluser        Master_Port: 3306        Connect_Retry: 60        Master_Log_File: master-log.000003        Read_Master_Log_Pos: 422        Relay_Log_File: slave-log.000003        Relay_Log_Pos: 530        Relay_Master_Log_File: master-log.000003        Slave_IO_Running: Yes        Slave_SQL_Running: Yes        Master_Server_Id: 1
(3)測試1)在任意一台伺服器上建立mydb資料庫
MariaDB [(none)]> create database mydb;
2)在另一台伺服器上查看
MariaDB [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mydb               || mysql              || performance_schema || test               |+--------------------+


本文出自 “汪立明” 部落格,請務必保留此出處http://afterdawn.blog.51cto.com/7503144/1928227

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.