實驗環境:CentOS7mysql
#安裝mariadb-server #主數據庫: [root@~ localhost]#vim /etc/my.cnf.d/server.cnf [mysqld] skip_name_resolve=ON innodb_file_per_table=ON autocommit=0 log_bin=master-log server_id=1 #從數據庫: [root@~ localhost]#vim /etc/my.cnf.d/server.cnf [mysqld] skip_name_resolve=ON innodb_file_per_table=ON autocommit=0 server_id=10 relay_log=relay-log read_only=ON #將兩臺設備加入ansible進行管理: [root@~ localhost]#ansible app -m shell -a 'systemctl start mariadb.service' [root@~ localhost]#ansible app -m shell -a 'ss -ntl' [root@~ localhost]#ansible app -m shell -a 'ntpdate 178.19.0.1' #主服務器: MariaDB [(none)]> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluser'@'172.16.254.47' IDENTIFIED BY '123456'; MariaDB [(none)]> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluser'@'172.16.252.142' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> SHOW MASTER STATUS; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-log.000005 | 750 #從服務器; MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='172.16.252.142',
MASTER_USER='repluser',MASTER_PASSWORD='123456',
MASTER_PORT=3306,MASTER_LOG_FILE='master-log.000005',MASTER_LOG_POS=750; MariaDB [(none)]> SHOW SLAVE STATUS\G; MariaDB [(none)]> START SLAVE;
##主主複製:sql
#第一臺主數據庫系統:二進制日誌和中繼日誌都開啓 [root@~ localhost]#vim /etc/my.cnf.d/server.cnf [mysqld] skip_name_resolve=ON innodb_file_per_table=ON autocommit=0 log_bin=master-log server_id=1 relay_log=relay-log #自動增加的ID,以奇數增加 auto_increment_offset=1 auto_increment_increment=2 #給另外一服務器受權 MariaDB [(none)]> grant replication client,replication slave on *.* to 'back'@'172.16.254.47' identity by '123456'; MariaDB [(none)]> flush privileges; #記錄file和binlog_do_db爲另外一個服務器使用 MariaDB [(none)]> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-log.000003 | 481 MariaDB [(none)]> start slave; #另外一數據庫服務器: [root@~ localhost]#vim /etc/my.cnf.d/server.cnf [mysqld] skip_name_resolve=ON innodb_file_per_table=ON autocommit=0 server_id=20 relay_log=relay-log #read_only=ON log_bin=master-log #以偶數增加的ID auto_increment_offset=2 auto_increment_increment=2 MariaDB [(none)]> grant replication client,replication slave on *.* to 'back'@'172.16.252.142' identity by '123456'; MariaDB [(none)]> change master to master_host='172.16.252.142',master_user='back',master_port=3306,master_log_file='master-log.000003',master_log_pos=481,master_password='123456'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> start slave;