docker安装mysql主从复制
2017-07-13 16:15
543 查看
参与文献 http://blog.csdn.net/qq362228416/article/details/48569293
docker 安装mysql主从备份
下载mysql镜像 我们获取最新镜像
环境准备如下:
服务器: 我的服务器ip: 47.94.175.83
保证3307端口和3308端口没有被占用
在主机上安装docker之后运行 从官网拉取最新镜像
docker pull mysql:latest
准备配置文件:
命令如下:
cd /
touch my-m.cnf
touch my-s.cnf
开始编辑文件
1,首创创两个文件 vi my-m.cnf(主库配置),vi my-s.cnf(从库配置)
my-m.cnf内容如下
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
主要是这两行,只需要在原来的配置里面加上就行
2
1
2
my-s.cnf内容如下
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
同样,主要的是这两行
2,OK,有了配置文件,就可以启动MySQL的了,先启动主库
1
3,启动从库
1
如图4所示,连接主库,并运行以下命令,创建一个用户用来同步数据
1
5,查看主库状态
1
记住文件,位置的值,如果没查到数据,请检查第一,第二步,配置问题。
我查出来的是mysql-bin.000003,436
如图6所示,连接到从库,运行以下命令,设置主库链接
2
1
2
7,启动同步
1
8,查看同步状态
1
如果看到等待主发送事件..什么的就成功了,你现在在主库上的修改,都会同步到从库上
docker 安装mysql主从备份
下载mysql镜像 我们获取最新镜像
环境准备如下:
服务器: 我的服务器ip: 47.94.175.83
保证3307端口和3308端口没有被占用
在主机上安装docker之后运行 从官网拉取最新镜像
docker pull mysql:latest
准备配置文件:
命令如下:
cd /
touch my-m.cnf
touch my-s.cnf
开始编辑文件
1,首创创两个文件 vi my-m.cnf(主库配置),vi my-s.cnf(从库配置)
my-m.cnf内容如下
# Copyright (c) 2014, 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] 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 log-bin = mysql-bin server-id = 1 # 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 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 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/1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
主要是这两行,只需要在原来的配置里面加上就行
log-bin = mysql-bin server-id = 11
2
1
2
my-s.cnf内容如下
# Copyright (c) 2014, 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] 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 log-bin = mysql-bin server-id = 2 # 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 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 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/1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
同样,主要的是这两行
log-bin = mysql-bin server-id = 2
2,OK,有了配置文件,就可以启动MySQL的了,先启动主库
$ docker run -d -e MYSQL_ROOT_PASSWORD=admin --name mysql-master -v /soft/my-m.cnf:/etc/mysql/my.cnf -p 3307:3306 mysql1
1
3,启动从库
$ docker run -d -e MYSQL_ROOT_PASSWORD=admin --name mysql-slave -v /soft/my-s.cnf:/etc/mysql/my.cnf -p 3308:3306 mysql1
1
如图4所示,连接主库,并运行以下命令,创建一个用户用来同步数据
$ GRANT REPLICATION SLAVE ON *.* to 'backup'@'%' identified by '123456';1
1
5,查看主库状态
$ show master status;1
1
记住文件,位置的值,如果没查到数据,请检查第一,第二步,配置问题。
我查出来的是mysql-bin.000003,436
如图6所示,连接到从库,运行以下命令,设置主库链接
$ change master to master_host='47.94.175.83',master_user='backup',master_password='123456', master_log_file='mysql-bin.000003',master_log_pos=436,master_port=3307;1
2
1
2
7,启动同步
$ start slave;1
1
8,查看同步状态
$ show slave status1
1
如果看到等待主发送事件..什么的就成功了,你现在在主库上的修改,都会同步到从库上
相关文章推荐
- MySQL安装与主从复制配置
- RHEL6.4_64安装MySQL主从复制
- MYsql编译安装及主从复制
- mysql 5.7 docker 主从复制架构搭建
- MySQL单机多实例安装并配置主从复制
- mysql多实例的安装以及主从复制配置
- MySQL单机多实例安装并配置主从复制
- mysql5.6二进制安装,主从/主主复制
- Linux CentOS 6.5安装与配置Mysql 主从复制(图)
- mysql主从复制及mysql-proxy0.8安装
- 虚拟机centos6.3 安装 mysql5.6.15 并设置 mysql主从复制
- 源码编译安装 MySQL 5.5.x 主从复制
- mysql 安装、主从复制
- 【转载】MySQL单机多实例安装并配置主从复制
- mysql多实例的安装以及主从复制配置
- win2003系统下学习Mysql主从复制安装配置
- MySQL主从复制的安装配置
- mysql主从复制安装配置
- Mysql 主从复制安装指南
- Centos7下配置安装mysql5.5主从复制(一主两从)