配置主服务器
root@ubuntu-ptg:~# vim /etc/mysql/mariadb.conf.d/50-server.cnf
vim
[mysqld]
log_bin
server-id=1
log-basename=master
root@ubuntu-ptg:~# mysql -uroot
MariaDB [(none)]> CREATE USER 'repluser'@'192.168.103.%' IDENTIFIED BY 'replpass';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'192.168.103.%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SHOW MASTER status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 | 447 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
配置从服务器
vim /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
server-id=18
root@ubuntu-ptg:~# mysql -uroot
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.103.114', MASTER_USER='repluser', MASTER_PASSWORD='replpass', MASTER_PORT=3306, MASTER_LOG_FILE='master-bin.000003', MASTER_LOG_POS=447, MASTER_CONNECT_RETRY=10;
MariaDB [(none)]> start slave;
测试:
主服务器
MariaDB [(none)]> CREATE database ptg111 ;
Query OK, 1 row affected (0.00 sec)
从服务器
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| ptg111 |
+--------------------+
4 rows in set (0.00 sec)
实现mariadb主主复制
主1服务器
root@ubuntu-ptg:~# vim /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
server-id=8
log-bin
auto_increment_offset=1
auto_increment_increment=2
mysql -uroot
MariaDB [(none)]> CREATE USER 'repluser'@'192.168.103.%' IDENTIFIED BY 'replpass';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO
MariaDB [(none)]> CHANGE MASTER TO
MASTER_HOST='192.168.103.114',
MASTER_USER='repluser',
MASTER_PASSWORD='replpass',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysqld-bin.000001',
MASTER_LOG_POS=942,
MASTER_CONNECT_RETRY=10;
主2服务器
root@ubuntu-ptg:~# vim /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
server-id=18
log-bin
auto_increment_offset=1
auto_increment_increment=2
mysql -uroot
MariaDB [(none)]> CREATE USER 'repluser'@'192.168.103.%' IDENTIFIED BY 'replpass';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO
MariaDB [(none)]> CHANGE MASTER TO
MASTER_HOST='192.168.103.113',
MASTER_USER='repluser',
MASTER_PASSWORD='replpass',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysqld-bin.000001',
MASTER_LOG_POS=657,
MASTER_CONNECT_RETRY=10;
测试:
103服务器
MariaDB [(none)]> CREATE database ptg103;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| ptg103 |
| ptg104 |
+--------------------+
104服务器
MariaDB [(none)]> CREATE database ptg104;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| ptg103 |
| ptg104 |
+--------------------+
5 rows in set (0.00 sec)