目的:
1)测试mariaDB的主从配置和mysql有什么不同
2)测试在docker中主从是否ok
- 从原mariaDB 提交slave镜像
[root@wxtest1607 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ea5f01306ed 8c21 "/bin/bash mysqld_saf" 19 minutes ago Up 19 minutes 8080/tcp, 0.0.0.0:53306->3306/tcp drunk_payne
[root@wxtest1607 ~]# docker commit 3ea5 slave:1.0
sha256:45f710211c3e7f4394182e42e3f23cedc5a3e606b030262697ae903f9d9f7694
[root@wxtest1607 ~]#
[root@wxtest1607 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
slave 1.0 45f710211c3e 7 seconds ago 917.7 MB
mariadb 1.0 8c212b8a0f7d 35 minutes ago 912.4 MB
- 配置master
#/etc/my.cnf 中加
server-id = 1
log-bin=mysql-bin
binlog-ignore-db=mysql
mysql中加账号
GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'repl';
#docker commit 4c65 master:1.0
提交master镜像
- 配置slave
#/etc/my.cnf 中加
server-id = 2
#docker commit f6c0 slave:2.0
提交master镜像
- 启动master 和 slave 镜像
[root@wxtest1607 test]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
slave 2.0 4052ab99dc74 5 minutes ago 922.9 MB
master 1.0 599dccd33b44 7 minutes ago 917.7 MB
#docker run -d -p 53306:3306 599d mysqld_safe
#docker run -d -p 53307:3306 4052 mysqld_safe
- slave change master to
mysql -uadmin -p123456 --port=53307 -h192.168.220.123
CHANGE MASTER TO MASTER_HOST='192.168.220.123', MASTER_USER='repl', MASTER_PASSWORD='repl',MASTER_PORT=53306;
start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.220.123
Master_User: repl
Master_Port: 53306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 245
Relay_Log_File: mariadb-relay-bin.000003
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
- 验证数据同步
#mysql -uadmin -p123456 --port=53306 -h192.168.220.123
mysql>create database test2;
#mysql -uadmin -p123456 --port=53307 -h192.168.220.123
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| test2 |
+--------------------+
5 rows in set (0.00 sec)