系统环境:
系统版本:CentOS 7.6
环境配置: 关闭selinux、firewalld
基本工具: lrzsz、vim

设备:
主库 IP 192.168.1.170 root 123
从库 IP 192.168.1.171 root 123

实施步骤:
1、主从两台机器都执行卸载系统自带的MariaDB
[root@localhost home]# yum remove -y mariadb*

2、主从两台机器都执行解压RPM包
[root@localhost home]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar 

3、安装
[root@localhost home]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
[root@localhost home]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
[root@localhost home]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
[root@localhost home]# yum install -y net-tools
[root@localhost home]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

4、主从两台机器都执行启动数据库 && 开机自启动
[root@localhost home]# systemctl start mysqld
[root@localhost home]# systemctl start mysqld

5、查看主从两台机器的mysql初始密码
[root@localhost home]# cat /var/log/mysqld.log |grep password

6、主从都执行登录数据库后修改密码
set password for root@localhost = password('Admin12345.');

7、修改主库的配置文件

[root@localhost home]# cat /etc/my.cnf

For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#

Remove leading # and set to the amount of RAM for the most important data

cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

#

Remove leading # to turn on a very important data integrity option: logging

changes to the binary log between backups.

log_bin

#

Remove leading # to set options mainly useful for reporting servers.

The server defaults are faster for transactions and fast SELECTs.

Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-bin=mysql-bin-master #启用二进制日志
server-id=1 #数据库ID 唯一
binlog-do-db=DB1 #指定要被从库同步的库
binlog-ignore-db=mysql #指定不被从库同步的库

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

8、重启主库
[root@localhost home]# systemctl restart mysqld

9、登录主库并创建一个账号被从库同步用
[root@localhost home]# mysql -uroot -pAdmin12345.

mysql> grant replication slave on . to slave@192.168.1.171 identified by 'Admin12345.';

刷新权限
mysql> flush privileges;

登录主库和从库设置远程登录
.......

10、登录从库修改配置文件
[root@localhost ~]# cat /etc/my.cnf

For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#

Remove leading # and set to the amount of RAM for the most important data

cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

#

Remove leading # to turn on a very important data integrity option: logging

changes to the binary log between backups.

log_bin

#

Remove leading # to set options mainly useful for reporting servers.

The server defaults are faster for transactions and fast SELECTs.

Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

server-id=2

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

11、用slve账号在从库试试登录主库
....OK
退出quit;

12、在从库用纯数据库的root进来停掉slve账号
mysql> stop slave;

13、配置主库的master状态信息
change master to master_host='192.168.1.170',master_port=3306,master_user='slave',master_password='Apeng12345.',master_log_file='mysql-bin-master.000002',master_log_pos=1178;

14、在从库登录纯数据库root账号状态下——>开启slave账号
mysql> start slave;

15、查看状态同步状态
show slave status;