docker 容器模式下部署mysql 主从复制

1.计划用两台host来部署,分别部署一台 mysql,一主一从,
2.配置好主从mysql配置文件,更改文件名即可
[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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
主与从server-id = 1 修改为server-id = 2
3.启动 mysql 容器,两个主机的容器都要启动,端口分别为3306,3307
docker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql-master -v /root/docker-mysql-data/mysql-master:/var/lib/mysql -v /root/docker-mysql-data/my-master.cnf:/etc/mysql/my.cnf -p 3306:3306 mysql:5.6
测试:mysql -uroot -p123456 -h127.0.0.1登录本机的mysql容器内
4.进入主mysql 容器
创建一个用户,并授予权限,replication slave ,
grant replication slave on *.* to ‘slave’@’%’ identified by ‘123456’; flush privileges;
show master status;
5. 从mysql容器配置
change master to master_host='172.17.0.2',master_user='slave',master_password='slave',
master_log_file='mysql-bin.000004',master_log_pos=1160,master_port=3306;
mysql> start slave;
mysql> show slave status \G;

上一篇:Jquery chosen动态设置值 select Ajax动态载入数据 设置chosen和获取他们选中的值


下一篇:JAVA读取HDFS信息