一看必會系列:docker mysql 主從集群測試

來源:本站原創 容器技術 超過271 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

進入容器修改配置文件
[[email protected] ~]# docker exec -it masterdb /bin/bash
[email protected]:/# 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

[email protected]:/# 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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=3807轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
?
?
萌宠夺宝游戏