docker 安装mysql5.7 主备过程

4 篇文章 0 订阅
1 篇文章 0 订阅

1.修改镜像的默认存储位置

vim /etc/systemd/system/multi-user.target.wants/docker.service

设置路径
ExecStart=/usr/bin/dockerd --graph=/mnt/lib/docker

2.设置镜像文件

获取阿里云镜像地址 

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

3.docker info 查看

[root@localhost ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.12.1-ce
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9b55aab90508bd389d7654c4baf173a981477d55
runc version: 9f9c96235cc97674e935002fc3d78361b696a69e
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-514.10.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.797GiB
Name: localhost.localdomain
ID: IZPN:OTU5:PBB5:TVTC:C7N5:7LJC:MJBI:RVG4:57G6:ZXOF:EVSP:43CJ
Docker Root Dir: /mnt/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Registry Mirrors:
 https://xxx.mirror.aliyuncs.com/
Live Restore Enabled: false

4.主数据库配置

修改配置文件并重启

#vi /etc/mysql/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=1 //[必须]服务器唯一ID,默认是1

创建远程备份用户

CREATE USER 'repl'@'从ip' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'从ip';
FLUSH PRIVILEGES;

备份数据

mysql> FLUSH TABLES WITH READ LOCK;

mysql> SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 1529881 | openser | mysql,test |
+------------------+----------+--------------+------------------+
(重启导出数据端口:mysqldump -u root -p123456 --opt -R openser > openser20121203.sql)

mysql> UNLOCK TABLES;

5.docker启动从数据库

docker run --name slave -e MYSQL_ROOT_PASSWORD=123456 -p 9002:3306 -d mysql:5.7

同步已有数据

docker容器复制到本地 格式:

docker cp container_id:<docker容器内的路径> <本地保存文件的路径>

本地复制文件到docker容器 格式:

docker cp 本地文件的路径 container_id:<docker容器内的路径>

进入容器

docker exec -it slave bash

docker镜像安装vim命令

apt-get update

apt-get install vim

#vim /etc/mysql/my.cnf
[mysqld]
log-bin=mysql-bin //[必须]启用二进制日志
server-id=2 //[必须]服务器唯一ID,默认是1,从库设置为2

#stop slave
#reset slave

change master to master_host='172.16.3.14',master_port=3306,master_user='repl',master_password='123456',master_log_file=' mysql-bin.000001',master_log_pos=3098;

start slave


show slave status\G
确认以下两个值为YES

***************
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

**************

 

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值