主节点配置
安装mysql-server
[root@ubuntu:~]# apt install mysql-server
修改mysql配置
[root@ubuntu:~]# vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
server-id=216
log_bin=/var/log/mysql/mysql-bin.log
重启服务
[root@ubuntu:~]# systemctl restart mysql.service
查看二进制日志
[root@ubuntu:~]# ll /var/log/mysql/
total 40
drwxr-x--- 2 mysql adm 4096 Apr 23 17:15 ./
drwxrwxr-x 10 root syslog 4096 Apr 23 16:13 ../
-rw-r----- 1 mysql adm 18210 Apr 23 17:15 error.log
-rw-r----- 1 mysql mysql 724 Apr 23 17:15 mysql-bin.000001
-rw-r----- 1 mysql mysql 339 Apr 23 17:18 mysql-bin.000002
-rw-r----- 1 mysql mysql 64 Apr 23 17:15 mysql-bin.index
创建账号并授权
mysql> create user zgh@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to zgh@'10.0.0.%';
Query OK, 0 rows affected (0.01 sec)
从节点配置
安装mysql-server (和master的安装一样)
修改配置文件
[root@ubuntu:~]# vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
server-id=217
log_bin=/var/log/mysql/mysql-bin.log
启动服务
[root@ubuntu:~]# systemctl restart mysql.service
配置主从同步,启动同步
mysql> CHANGE MASTER TO
MASTER_HOST='10.0.0.216',
MASTER_USER='zgh',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=157;
mysql> start slave;
此时同步完成,可以直接尝试一下