centos7安装mysql5.7.24后配置主从

Posted kuroniko

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7安装mysql5.7.24后配置主从相关的知识,希望对你有一定的参考价值。

 

1)使用docker安装完成mysql5.7.24,我规划的是3台:

192.168.0.170(Master)

192.168.0.169(Slave)

192.168.0.168(Slave)

2)配置三台机器的my.cnf配置文件

我三台机器的配置文件都是/usr/local/mysql/conf/my.cnf 

3)设置三台主从服务器配置
vi /usr/local/mysql/conf/my.cnf

[mysql]
default-character-set=utf8
[mysqld]
interactive_timeout = 120

wait_timeout = 120
max_allowed_packet = 32M
log-bin=mysql-bin
server-id=170

character-set-server=utf8

 

vi /usr/local/mysql/conf/my.cnf

[mysql]
default-character-set=utf8
[mysqld]
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M
log-bin=mysql-bin
server-id=169
character-set-server=utf8

 

vi /usr/local/mysql/conf/my.cnf

[mysql]
default-character-set=utf8
[mysqld]
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M
log-bin=mysql-bin
server-id=168

character-set-server=utf8

3)创建主从服务器容器

在170,169,168上运行启动mysql

docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24

docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24

docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24

 


4)登录170主服务器的mysql,查询master的状态

 


170主库创建用户

SET sql_mode=(SELECT REPLACE(@@sql_mode,\'ONLY_FULL_GROUP_BY\',\'\'));
GRANT REPLICATION SLAVE ON *.* to \'backup\'@\'%\' identified by \'123456\';


5)登录169和168从服务器的mysql,设置与主服务器相关的配置参数

 

SET sql_mode=(SELECT REPLACE(@@sql_mode,\'ONLY_FULL_GROUP_BY\',\'\'));
change master to master_host=\'192.168.0.170\',master_user=\'backup\',master_password=\'123456\',master_log_file=\'mysql-bin.000001\',master_log_pos=439;

master_host为docker的地址不能写127.0.0.1
master_user是在主库创建的用户
master_log_pos是主库show master status;查询出的Position(439是最开始查询出来的,和上面的截图22437不同)


然后在169和168上启动服务

start slave;

查看服务状态

show slave status;

Waiting for master to send event 就是成功了
Connecting to master 多半是连接不通

之后主库的修改都能同步到从库了

以上是关于centos7安装mysql5.7.24后配置主从的主要内容,如果未能解决你的问题,请参考以下文章

Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)

Centos7.5安装mysql5.7.24二进制包方式部署(keepalived+主从复制)

CentOS7.5 yum 安装与配置MySQL5.7.24

centos7安装二进制版的mysql5.7.24版本

Centos7.5安装mysql5.7.24二进制包方式部署

centos7 docker 安装 mysql5.7.24 导入11G的sql