一看必会系列:docker mysql 主从集群测试

来源:本站原创 容器技术 超过210 views围观 0条评论

 

仓库操作
docker pull mysql:5.6
docker images
docker tag docker.io/mysql 192.168.142.130:5000/mysql56:v2
docker tag 97fdbdd65c6a 192.168.142.130:5000/mysql56:v2
docker images
docker push 192.168.142.130:5000/mysql56:v2

主从服务器操作

docker run   –restart=always -p  3356:3306 –name masterdb -v  /db/mysqlCluster/master:/var/lib/mysql  -e  MYSQL_ROOT_PASSWORD=123456   -d  192.168.142.130:5000/mysql56:v2

docker run   –restart=always -p  3356:3306 –name slavedb -v  /db/mysqlCluster/master:/var/lib/mysql  -e  MYSQL_ROOT_PASSWORD=123456   -d  192.168.142.130:5000/mysql56:v2

进主服务器
docker exec -it masterdb /bin/bash
进从服务器
docker exec -it slavedb /bin/bash

apt-get update && apt-get install vim -y

进入容器修改配置文件
[root@centos010 ~]# docker exec -it masterdb /bin/bash
root@9838a377e3e2:/# vim /etc/mysql/mysql.conf.d/mysqld.cnf

主服务器配置
server-id = 1
log_bin = mysql-bin
lower_case_table_names=1

从服务器配置
server-id = 2
log_bin = mysql-bin
lower_case_table_names=1

root@9838a377e3e2:/# mysql -u root -p      
Enter password:

主从服务器配置,实际这个权限给只读就行
GRANT REPLICATION SLAVE ON *.* TO ‘re’@’%’ IDENTIFIED BY ‘123456’;
flush privileges;

从服务器
注意端口
CHANGE MASTER TO MASTER_HOST=’192.168.142.130′,MASTER_USER=’re’, MASTER_PASSWORD=’123456′,MASTER_LOG_FILE=’mysql-bin.000001′, MASTER_LOG_POS=387, master_port=3356;
flush privileges;
start slave;

从服务器查看
mysql> show slave STATUS \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.142.130
                  Master_User: re
                  Master_Port: 3356
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 387
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes   —成功
            Slave_SQL_Running: Yes

从服务器建立普通帐号测试只读
GRANT select ON *.* TO ‘user01’@’%’ IDENTIFIED BY’123456′ WITH GRANT OPTION;

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3807转载请注明转自CCIE那点事
如果喜欢:点此订阅本站