|
| 1 | +# Introduction |
| 2 | + |
1 | 3 | This is a sample work to learn about docker, containers, running MySQL in docker and setting up MySQL
|
2 | 4 | replication using docker containers.
|
3 | 5 |
|
| 6 | +# Directory structure explained |
4 | 7 | Here is the directory structure and its explanation
|
5 | 8 |
|
6 | 9 | MySQLReplDocker
|
7 | 10 | |
|
8 | 11 | +--- conf/
|
9 |
| - | | |
10 | 12 | | +--- master1.cnf
|
11 | 13 | | +--- master2.cnf
|
12 | 14 | | +--- slave1.cnf
|
13 | 15 | | +--- slave2.cnf
|
14 |
| - | |
15 | 16 | +--- data/
|
16 |
| - | | |
17 | 17 | | +--- master1/
|
18 | 18 | | +--- master2/
|
19 | 19 | | +--- slave1/
|
20 | 20 | | +--- slave2/
|
21 |
| - | |
22 | 21 | +--- docker/
|
23 |
| - | | |
24 | 22 | | +--- master-2-slave.yml
|
25 | 23 | | +--- master-2-master.yml
|
26 | 24 | | +--- slave-2-master-2-master-2-slave.yml
|
27 |
| - | |
28 | 25 | +--- scripts/
|
29 |
| - | | |
30 | 26 | | +--- common-functions.sh
|
31 | 27 | | +--- master-2-slave.sh
|
32 | 28 | | +--- master-2-master.sh
|
33 | 29 | | +--- slave-2-master-2-master-2-slave.sh
|
34 |
| - | |
35 | 30 | +--- start.sh
|
36 | 31 | +--- stop.sh
|
37 | 32 | +--- check_params.sh
|
38 | 33 |
|
39 | 34 |
|
40 |
| -The folder "conf" contains the MySQL configuration for master and slave nodes. |
41 |
| - |
42 |
| -The folder "data" contains folders to hold data for master and slave nodes. |
43 |
| - |
44 |
| -The folder "docker" contains the docker container configuation files |
45 |
| - |
46 |
| -The folder "scripts" contains bash script which does the real job of setup of replication between the nodes |
47 |
| - |
48 |
| - |
49 |
| - |
| 35 | +* The folder "___conf___" contains the MySQL configuration for master and slave nodes. |
| 36 | +* The folder "___data___" contains folders to hold data for master and slave nodes. |
| 37 | +* The folder "___docker___" contains the docker container configuation files |
| 38 | +* The folder "___scripts___" contains bash script which does the real job of setup of replication between the nodes |
50 | 39 |
|
| 40 | +# How to get MySQL containers up and running |
51 | 41 | To run a MySQL master-slave container replication execute the command
|
52 |
| - |
53 |
| -```bash start.sh master-slave``` |
54 |
| - |
| 42 | +```sh |
| 43 | +bash start.sh master-slave |
| 44 | +``` |
55 | 45 | To run a MySQL master-master container replication execute the command
|
56 |
| - |
57 |
| -```bash start.sh master-master``` |
58 |
| - |
| 46 | +```sh |
| 47 | +bash start.sh master-master |
| 48 | +``` |
59 | 49 | To run a MySQL slave-master-master-slave replication execute the command
|
60 |
| - |
61 |
| -```bash start.sh slave-master-master-slave``` |
| 50 | +```sh |
| 51 | +bash start.sh slave-master-master-slave |
| 52 | +``` |
| 53 | + |
| 54 | +# Seeing replication in action |
| 55 | +In order to see if the replication is actually working, you need to enable our nerd mode. Lets kick in. Execute the following command to see the docker containers which are currently running |
| 56 | +```sh |
| 57 | +bash info.sh master-slave |
| 58 | +``` |
| 59 | +This will list down the containers, where you can clearly identity the MySQL master(s) and slave(s) nodes. In order to connect to any of the container, you can execute |
| 60 | +```sh |
| 61 | +docker container exec -it <name-of-container> mysql -u root -p <mysql-password> |
| 62 | +``` |
| 63 | +> NOTE: Find the passwords in .env file |
| 64 | +
|
| 65 | +You can repeat the command for all the MySQL containers and then play around and see the replication action coming live. |
0 commit comments