栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Docker安装、mysql主从复制搭建

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker安装、mysql主从复制搭建

1、安装Docker
yum install docker

遇到问询选 yes
完毕后检查版本信息

docker version


出现版本信息即完成安装

2、配置自启动
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激活链接

8、mysql配置类 找到 /etc 或 /etc/mysql 目录下的 my.cnf 文件

创建所需目录、拷贝文件


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

博主此处的从容器是将已经配置好的文件直接拷贝到目标位置

配置 / 启动容器
打开对应端口 3306 3307 3308 设置开机自启
重启防火墙
将配置类复制到各容器
重启容器

10、通过Navicat进行主从复制连接

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;
# 显示连接状态


如标红这样就是连接成功,可以进行测试

11、测试主从复制

对 master 服务进行操作,刷新从服务如 master 一样更新即为成功连接

End
  • 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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/320716.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号