(1)服务器1的配置
1)安装mariadb-server
[root@localhost ~]# yum -y install mariadb-server
2)编辑/etc/my.cnf文件
[root@localhost ~]# 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并进行如下配置
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# 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
[root@localhost ~]# yum -y install mariadb-server
2)编辑/etc/my.cnf文件
[root@localhost ~]# 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并配置
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# 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 |
+--------------------+