yum install docker
遇到问询选 yes
完毕后检查版本信息
docker version
出现版本信息即完成安装
systemctl start docker.service 启动docker systemctl enable docker.service 配置自启动3、安装mysql
docker pull mysql:5.7.13 # pull 命令:拉取/更新指定镜像4、启动主容器master
docker run --name master -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.13 # 运行命令 自定义名称 p:端口号:映射端口 e:环境变量——设置密码 d:后台运行 版本5、查看运行状态
docker ps -a # 显示所有容器(包括未运行) # status 中 Up 即为运行中6、开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent # 防火墙端口开放命令 --permanent:永久开启 firewall-cmd --reload # 防火墙重启7、通过Navicat连接
关于Navicat激活链接
mkdir master # 创建 master 目录 cp /etc/my.cnf /usr/mysql/master/my.cnf # 拷贝配置文件修改配置文件
在 [mysqld] 节点最后加上
log-bin=mysql-bin server-id=1 # 每个容器内 id 不重复即可9、容器启动 主容器master 从容器slave1、slave2
博主此处的从容器是将已经配置好的文件直接拷贝到目标位置
10、通过Navicat进行主从复制连接配置 / 启动容器
打开对应端口 3306 3307 3308 设置开机自启
重启防火墙
将配置类复制到各容器
重启容器
stop slave; # 停止从服务 CHANGE MASTER TO MASTER_HOST='192.168.200.130', MASTER_PORT=3306, MASTER_USER='root', MASTER_PASSWORD='root'; # 引号中内容依次是——IP、主服务端口、用户、密码 START SLAVE; # 连接 show slave status; # 显示连接状态
如标红这样就是连接成功,可以进行测试
对 master 服务进行操作,刷新从服务如 master 一样更新即为成功连接
- docker 中的 vim 安装
在 docker 中安装 vim 链接
apt-get update apt-get install -y vim # apt-get install vim
- 进入容器内部的命令建议使用
docker exec -it 容器id /bin/bash # 具体原因可查看其他文档,此处不表
- 按照本文逐步进行应当是不会出错,如果出现 exited(1) 这样的容器异常退出情况,检查 my.cnf 配置文件是否按照要求修改,可尝试删除容器重新操作和配置,此处提供一份完整配置内容
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Community Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] skip-host-cache skip-name-resolve user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql explicit_defaults_for_timestamp # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 127.0.0.1 #log-error = /var/log/mysql/error.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # * importANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ log-bin=mysql-bin server-id=1



