Skip to content

Commit 935fbe8

Browse files
committed
PXC-4719 [DOCS] - Update Docker to use Docker Compose 8.4
new file: docs/docker-compose.md modified: docs/docker.md modified: mkdocs-base.yml
1 parent fa63241 commit 935fbe8

4 files changed

Lines changed: 228 additions & 2 deletions

File tree

docs/_static/pxc-cluster-dirs.png

197 KB
Loading

docs/docker-compose.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Run with Docker Compose
2+
3+
For more information about using Docker, see the [Docker Docs](https://docs.docker.com/). Make
4+
sure that you are using the latest version of Docker. The ones
5+
provided via `apt` and `yum` may be outdated and cause errors.
6+
7+
We gather [Telemetry data] in the Percona packages and Docker images.
8+
9+
--8<--- "get-help-snip.md"
10+
11+
This guide shows you how to deploy a three-node Percona XtraDB Cluster 8.4 using Docker Compose. You generate SSL certificates on the first node and copy them to the other two nodes to enable secure communication.
12+
13+
!!! note
14+
15+
This setup is for testing and development purposes only. Do not use it in production without configuring proper storage, security, backup, and monitoring systems.
16+
17+
## Prerequisites
18+
19+
* Docker and Docker Compose installed
20+
21+
* At least 3 GB of memory per container
22+
23+
* Familiarity with Docker volumes and networks
24+
25+
## Directory Structure
26+
27+
You need to create a separate directory structure to organize your configuration, certificate files, and Docker Compose setup. This keeps your deployment clean and easy to manage.
28+
29+
Run the following commands to create the directory structure:
30+
31+
```{.bash data-prompt="$"}
32+
$ mkdir -p pxc-cluster/{certs,conf.d,init}
33+
$ cd pxc-cluster
34+
```
35+
36+
After running these commands, your working directory (pxc-cluster/) will contain:
37+
38+
![PXC cluster directories](_static/pxc-cluster-dirs.png)
39+
40+
This structure helps manage configuration files, TLS/SSL certificates, and setup scripts, ensuring a tidy and easy-to-manage deployment.
41+
{.power-number}
42+
43+
1. Create conf.d/custom.cnf with minimal SSL settings:
44+
45+
```ini
46+
[mysqld]
47+
ssl-ca=/etc/mysql/certs/ca.pem
48+
ssl-cert=/etc/mysql/certs/server-cert.pem
49+
ssl-key=/etc/mysql/certs/server-key.pem
50+
```
51+
52+
2. Create a file named `.env` in the directory root:
53+
54+
```ini
55+
MYSQL_ROOT_PASSWORD=rootpass
56+
XTRABACKUP_PASSWORD=xbpass
57+
```
58+
59+
⚠️ Security Note: Add .env to your .gitignore file to prevent committing secrets to version control.
60+
61+
3. Create the SSL Certificate Script. Save the following script as init/create-ssl-certs.sh:
62+
63+
```ini
64+
#!/bin/bash
65+
set -e
66+
67+
CERT_DIR=./certs
68+
mkdir -p "$CERT_DIR"
69+
cd "$CERT_DIR"
70+
71+
openssl genrsa 2048 > ca-key.pem
72+
openssl req -new -x509 -nodes -days 3650 \
73+
-key ca-key.pem \
74+
-subj "/C=XX/ST=State/L=City/O=Organization/CN=RootCA" \
75+
-out ca.pem
76+
77+
openssl req -newkey rsa:2048 -days 3650 -nodes \
78+
-keyout server-key.pem \
79+
-subj "/C=XX/ST=State/L=City/O=Organization/CN=pxc-node" \
80+
-out server-req.pem
81+
82+
openssl rsa -in server-key.pem -out server-key.pem
83+
openssl x509 -req -in server-req.pem -days 3650 \
84+
-CA ca.pem -CAkey ca-key.pem -set_serial 01 \
85+
-out server-cert.pem
86+
87+
88+
chmod 600 *.pem
89+
```
90+
91+
4. Make the script executable:
92+
93+
```{.bash data-prompt="$"}
94+
$ chmod +x init/create-ssl-certs.sh
95+
```
96+
97+
5. Run the script to create the certs:
98+
99+
```{.bash data-prompt="$"}
100+
$ ./init/create-ssl-certs.sh
101+
```
102+
103+
4. Copy Certificates to All Nodes
104+
105+
All three nodes in the cluster must use the same set of SSL certificates. After generating the certificates in the certs/ directory on node 1, you need to copy them to the directories for node 2 and node 3.
106+
107+
If you are running all containers from a single project directory (like with Docker Compose on one host), you can reuse the same certs/ directory for all nodes. However, if you’re organizing them into separate directories or deploying on separate hosts, you must explicitly copy the certificates.
108+
109+
To create the directories for node 2 and node 3:
110+
111+
```{.bash data-prompt="$"}
112+
$ mkdir -p certs-node2
113+
$ mkdir -p certs-node3
114+
```
115+
116+
Then copy the certificates:
117+
118+
```{.bash data-prompt="$"}
119+
$ cp -r certs/* certs-node2/
120+
$ cp -r certs/* certs-node3/
121+
```
122+
123+
If you’re deploying on separate machines, run the following from node 1:
124+
125+
```{.bash data-prompt="$"}
126+
$ scp -r ./certs/ user@node2-host:/path/to/pxc-cluster/certs
127+
$ scp -r ./certs/ user@node3-host:/path/to/pxc-cluster/certs
128+
```
129+
130+
Ensure each container mounts its own copy of the certs/ directory.
131+
132+
5. Create docker-compose.yml:
133+
134+
```ini
135+
136+
137+
# Docker Compose Configuration for Percona XtraDB Cluster
138+
139+
This is a Docker Compose file that defines a multi-container application for running a Percona XtraDB Cluster.
140+
141+
```yaml
142+
services:
143+
pxc1:
144+
image: percona/percona-xtradb-cluster:8.4
145+
container_name: pxc1
146+
environment:
147+
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
148+
- CLUSTER_NAME=pxc-cluster
149+
- CLUSTER_JOIN=pxc2,pxc3
150+
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
151+
volumes:
152+
- ./certs:/etc/mysql/certs:ro
153+
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
154+
networks:
155+
- pxcnet
156+
ports:
157+
- "3306:3306"
158+
command: ["--wsrep-new-cluster"]
159+
160+
pxc2:
161+
image: percona/percona-xtradb-cluster:8.4
162+
container_name: pxc2
163+
environment:
164+
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
165+
- CLUSTER_NAME=pxc-cluster
166+
- CLUSTER_JOIN=pxc1,pxc3
167+
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
168+
volumes:
169+
- ./certs:/etc/mysql/certs:ro
170+
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
171+
networks:
172+
- pxcnet
173+
174+
pxc3:
175+
image: percona/percona-xtradb-cluster:8.4
176+
container_name: pxc3
177+
environment:
178+
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
179+
- CLUSTER_NAME=pxc-cluster
180+
- CLUSTER_JOIN=pxc1,pxc2
181+
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
182+
volumes:
183+
- ./certs:/etc/mysql/certs:ro
184+
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
185+
networks:
186+
- pxcnet
187+
188+
networks:
189+
pxcnet:
190+
driver: bridge
191+
```
192+
193+
6. Start the Cluster
194+
195+
Start node 1 to initialize the cluster:
196+
197+
```{.bash data-prompt="$"}
198+
$ docker compose up -d pxc1
199+
```
200+
201+
Then, start the remaining nodes:
202+
203+
```{.bash data-prompt="$"}
204+
$ docker compose up -d pxc2 pxc3
205+
```
206+
207+
7. Validate the Cluster
208+
209+
Check the status of each node:
210+
211+
```{.bash data-prompt="$"}
212+
docker exec -it pxc1 mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
213+
docker exec -it pxc2 mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_cluster_status';"
214+
```
215+
216+
You should see all three nodes joined and synchronized.
217+
218+
219+
220+
Next Steps
221+
• Add persistent volumes for data directories
222+
• Use ProxySQL or HAProxy for load balancing
223+
• Integrate with PMM for monitoring
224+
• Enable backups using Percona XtraBackup
225+

docs/docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Running Percona XtraDB Cluster in a Docker Container
1+
# Run in a Docker container
22

33
Docker images of Percona XtraDB Cluster are hosted publicly on Docker Hub at
44
[https://hub.docker.com/r/percona/percona-xtradb-cluster/](https://hub.docker.com/r/percona/percona-xtradb-cluster/).

mkdocs-base.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ nav:
194194
- yum.md
195195
- tarball.md
196196
- compile.md
197-
- docker.md
197+
- docker.md
198+
- docker-compose.md
198199
- configure-nodes.md
199200
- bootstrap.md
200201
- add-node.md

0 commit comments

Comments
 (0)