准备两个节点,修改数据库配置文件 my.cnf
[root@master ~]# vim /etc/my.cnf
###在[mysqld]下添加
log_bin=mysql-bin
server_id=1 #与另一个节点id不同
###重启数据库
[root@master ~]# systemctl restart mysqld/mariadb
初始化数据库
[root@master ~]# mysql_secure_installation
进入主数据库授权
[root@master ~]# mysql -uroot -p123456
MariaDB [(none)]> grant replication slave on *.* to 'test'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
###查看master的状态
MariaDB [(none)]> show master status \G
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 1625
Binlog_Do_DB: Binlog_Ignore_DB:
1 row in set (0.00 sec)
配置从数据库
[root@slave ~]# mysql -uroot -p123456
MariaDB [(none)]> change master to
master_host='192.168.100.10',master_user='test',master_password='123456',
master_log_file='mysql-bin.000003',master_log_pos=1625;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> start slave; ###启动从数据库
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status \G #查看状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yesm