docker搭建mysql集群
docker pull mysql主从配置文件修改,在某路径下分别配置my.cnf添加配置项:主(my-m.cnf):log-bin = mysql-bin server-id = 1从(my-s.cnf):log-bin = mysql-bin server-id = 2分别启动mysql镜像docker run -d -e MYSQL
·
首先下载docker镜像:docker pull mysql
然后主从配置文件修改,在服务器某路径下分别配置my.cnf
添加配置项:
主(my-m.cnf):log-bin = mysql-bin
server-id = 1
从(my-s.cnf):log-bin = mysql-bin
server-id = 2
分别启动mysql镜像
docker run -d -e MYSQL_ROOT_PASSWORD=root123 --name mysql-master -v /home/zxin10/soft/my-m.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -p 3307:3306 mysql
docker run -d -e MYSQL_ROOT_PASSWORD=root123 --name mysql-slaver -v /home/zxin10/soft/my-s.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -p 3308:3306 mysql
查看启动情况:docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b92584f5fba mysql "docker-entrypoint..." 16 hours ago Up 16 hours 0.0.0.0:3308->3306/tcp mysql-slaver
0bc9c63bd13d mysql "docker-entrypoint..." 16 hours ago Up 16 hours 0.0.0.0:3307->3306/tcp mysql-master
在主mysql新建一个用户test 用来同步数据,然后执行:
GRANT REPLICATION SLAVE ON *.* to 'test'@'%' identified by '123456';
命令执行成功后查看主库状态(show master status;),记住file和position的值,然后在从mysql执行:
change master to master_host='192.168.0.47',master_user='test',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=8446,master_port=3307;
启动同步:start slave;
查看同步状态:show slave status;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.47
Master_User: sky
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 8958
Relay_Log_File: 4b92584f5fba-relay-bin.000002
Relay_Log_Pos: 832
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
表示同步成功,可在主库新建表测试一下。
更多推荐
已为社区贡献1条内容
所有评论(0)