文章转自http://www.cnblogs.com/baolong/p/5763412.html
通过以上的信息说明master与slave是数据隔离的, 所以我们可以通过docker创建N个mysql容器, 然后就能以很小的代价就能学习《高可用MySQL》中的数据模型 再也不用发愁机器不够用。
怎么查看容器的操作系统环境 一般就是 uname -a cat /etc/pro cat /etc/lsb-release
很幸运我们的容器是ubuntu14.04
root@1651d1cab219:/# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=14.04 DISTRIB_CODENAME=trusty DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"但是执行 apt-get install时候却什么也装不了 需要更改
cd /etc/apt/没有 vi vim ee 编辑器 只好追加内容到 sources.list
echo deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list echo deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list echo deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list echo deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list echo deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list echo deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse >> sources.list echo deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse >> sources.list echo deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse >> sources.list echo deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse >> sources.list echo deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse >> sources.list然后 更新源
apt-get update apt-get install vim然后通过vim把sources.list文件的前两行删除掉 再重新update一下。
apt-get update安装一个网络工具获取ip
apt-get install net-tools获取到master的ip地址
root@1651d1cab219:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02 inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:15119 errors:0 dropped:0 overruns:0 frame:0 TX packets:12633 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:34197557 (34.1 MB) TX bytes:897732 (897.7 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:22 errors:0 dropped:0 overruns:0 frame:0 TX packets:22 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2212 (2.2 KB) TX bytes:2212 (2.2 KB)slave也需要这么做
还有一种方法 可以创建Dockerfile依赖mysql镜像创建一个新的镜像。 上诉命令通过RUN来执行创建的新容器会有安装的软件。
最后通过slave的docker连接到master的容器mysql服务器上
master的服务器mysql账号root赋值权限
mysql> grant all privileges on *.* to root@'%' identified by ''; Query OK, 0 rows affected (0.02 sec) mysql> flush privileges; Query OK, 0 rows affected (0.02 sec)slave服务器执行如下命令
[root@bogon ~]# mysql -uroot -p -h 172.17.0.2 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.6.19-v1-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]>在master上将test_docker数据库删除,看slave的终端是否也不显示已删除的库
master操作
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | #bak_database | | mysql | | performance_schema | | test | | test_docker | +--------------------+ 6 rows in set (0.00 sec) mysql> drop database test_docker; Query OK, 0 rows affected (0.06 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | #bak_database | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec)slave操作
MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | #bak_database | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) MySQL [(none)]>