標籤: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主主複製