You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,26 +8,21 @@ We gather [Telemetry data](telemetry.md) in the Percona packages and Docker imag
8
8
9
9
--8<--- "get-help-snip.md"
10
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.
11
+
The 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
12
13
-
The following procedure describes setting up a simple 3-node cluster
14
-
for evaluation and testing purposes. Do not use these instructions in a
15
-
production environment because the MySQL certificates generated in this
16
-
procedure are self-signed.
17
-
18
-
In a production environment, you should generate and store the certificates to be used by Docker and configure proper storage, security, backup, and monitoring systems.
13
+
The following procedure is for evaluation and testing only. Do not use these instructions in a production environment because the MySQL certificates generated here are self-signed. In production, generate and store proper certificates and configure storage, security, backup, and monitoring.
19
14
20
15
## Prerequisites
21
16
22
-
* Docker and Docker Compose installed
17
+
* Docker and Docker Compose installed (or Podman 4.1 or later and Podman Compose; see [Appendix: Podman Alternative](#appendix-podman-alternative))
23
18
24
19
* At least 3 GB of memory per container
25
-
20
+
26
21
* Familiarity with Docker volumes and networks
27
22
28
23
## Directory Structure
29
24
30
-
You must create a separate directory structure to organize your configuration, certificate files, and Docker Compose setup. This step keeps your deployment clean and easy to manage.
25
+
You must create a separate directory structure to organize your configuration, certificate files, and Docker Compose setup. The directory structure keeps your deployment clean and easy to manage.
31
26
32
27
Run the following commands to create the directory structure:
33
28
@@ -40,9 +35,11 @@ After running these commands, your working directory (pxc-cluster/) will contain
This structure helps manage configuration files, TLS/SSL certificates, and setup scripts, ensuring a tidy and easy-to-manage deployment.
38
+
The directory structure helps manage configuration files, TLS/SSL certificates, and setup scripts, ensuring a tidy and easy-to-manage deployment.
44
39
{.power-number}
45
40
41
+
## Configuration Files
42
+
46
43
1. Create conf.d/custom.cnf with minimal SSL settings:
47
44
48
45
@@ -62,6 +59,8 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
62
59
63
60
Add `.env` to your .gitignore file to prevent committing secrets to version control.
64
61
62
+
## SSL Certificate Generation
63
+
65
64
3. Copy the SSL certificate generation script. Save the script as `init/create-ssl-certs.sh`:
66
65
67
66
```text
@@ -101,37 +100,21 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
101
100
./init/create-ssl-certs.sh
102
101
```
103
102
104
-
4. Copy Certificates to All Nodes
103
+
4. Copy Certificates to All Nodes (only for multi-host)
105
104
106
-
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.
107
-
108
-
If you run 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, you must explicitly copy the certificates if you’re organizing them into separate directories or deploying on separate hosts.
109
-
110
-
To create the directories for node 2 and node 3:
111
-
112
-
113
-
```shell
114
-
mkdir -p certs-node2
115
-
mkdir -p certs-node3
116
-
```
117
-
118
-
Then copy the certificates:
119
-
120
-
121
-
```shell
122
-
cp -r certs/* certs-node2/
123
-
cp -r certs/* certs-node3/
124
-
```
105
+
All three nodes in the cluster must use the same set of SSL certificates. The `docker-compose.yml` in the guide mounts the same `./certs` directory for all three services (pxc1, pxc2, pxc3). For a single-host deployment, you do not need to create separate certificate directories; the `certs/` you created in step 5 is used by all nodes.
125
106
126
-
If you’re deploying on separate machines, run the following from node 1:
107
+
If you deploy on separate machines instead of one host, copy the certificates to each machine so each has its own `certs/` (or equivalent path) for its Compose project. From node 1, run:
Ensure each container mounts its own copy of the certs/ directory.
115
+
Ensure each host's Compose file mounts that host's certificate directory.
116
+
117
+
## Docker Compose Setup
135
118
136
119
5. Create docker-compose.yml:
137
120
@@ -143,11 +126,11 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
143
126
environment:
144
127
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
145
128
- CLUSTER_NAME=pxc-cluster
146
-
- CLUSTER_JOIN=pxc2,pxc3
147
129
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
148
130
volumes:
149
131
- ./certs:/etc/mysql/certs:ro
150
132
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
133
+
- ./data-pxc1:/var/lib/mysql
151
134
networks:
152
135
- pxcnet
153
136
ports:
@@ -164,11 +147,12 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
164
147
environment:
165
148
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
166
149
- CLUSTER_NAME=pxc-cluster
167
-
- CLUSTER_JOIN=pxc1,pxc3
150
+
- CLUSTER_JOIN=pxc1
168
151
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
169
152
volumes:
170
153
- ./certs:/etc/mysql/certs:ro
171
154
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
155
+
- ./data-pxc2:/var/lib/mysql
172
156
networks:
173
157
- pxcnet
174
158
healthcheck:
@@ -182,11 +166,12 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
182
166
environment:
183
167
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
184
168
- CLUSTER_NAME=pxc-cluster
185
-
- CLUSTER_JOIN=pxc1,pxc2
169
+
- CLUSTER_JOIN=pxc1
186
170
- XTRABACKUP_PASSWORD=${XTRABACKUP_PASSWORD}
187
171
volumes:
188
172
- ./certs:/etc/mysql/certs:ro
189
173
- ./conf.d:/etc/percona-xtradb-cluster.conf.d:ro
174
+
- ./data-pxc3:/var/lib/mysql
190
175
networks:
191
176
- pxcnet
192
177
healthcheck:
@@ -199,6 +184,8 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
199
184
driver: bridge
200
185
```
201
186
187
+
## Deployment
188
+
202
189
6. Start the Cluster
203
190
204
191
Start node 1 to initialize the cluster:
@@ -207,23 +194,105 @@ This structure helps manage configuration files, TLS/SSL certificates, and setup
207
194
```shell
208
195
docker compose up -d pxc1
209
196
```
197
+
(With Podman: `podman compose up -d pxc1` or `podman-compose up -d pxc1`.)
210
198
211
199
Then, start the remaining nodes:
212
200
213
201
214
202
```shell
215
203
docker compose up -d pxc2 pxc3
216
204
```
205
+
(With Podman: `podman compose up -d pxc2 pxc3` or `podman-compose up -d pxc2 pxc3`.)
206
+
207
+
## Validation
217
208
218
209
7. Validate the Cluster
219
210
220
-
Check the status of each node:
211
+
Check the status of each node. Exact commands (run from the host; use the same password as in your `.env`):
221
212
222
-
223
213
```shell
224
214
docker exec -it pxc1 mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
225
215
docker exec -it pxc2 mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_cluster_status';"
226
216
```
217
+
(With Podman: use `podman exec` instead of `docker exec`.)
227
218
228
219
You should see all three nodes joined and synchronized.
229
220
221
+
## Troubleshooting
222
+
223
+
* Containers exit or fail to start: Check logs with `docker compose logs pxc1` (and pxc2, pxc3). Ensure the bootstrap node (pxc1) is healthy before starting pxc2 and pxc3.
224
+
225
+
* Cluster size stays at 1: Start pxc1 first, wait for pxc1 to be ready (healthcheck passing), then start pxc2 and pxc3. If nodes start too soon, the nodes may not join; restart pxc2 and pxc3 after pxc1 is up.
226
+
227
+
* Permission denied on certs or config: Ensure `certs/` and `conf.d/` are readable by the container. On SELinux with Podman, use the `:Z` or `:z` volume option (see [Appendix: Podman Alternative](#appendix-podman-alternative)).
228
+
229
+
* Nodes cannot reach each other: Verify all containers are on the same network (`docker network inspect pxc-cluster_pxcnet` or equivalent). Open firewall ports 3306, 4567, 4568, and 4444 if running on separate hosts.
230
+
231
+
## Cleanup and Shutdown
232
+
233
+
To stop the cluster and remove containers (data in `data-pxc1/`, `data-pxc2/`, `data-pxc3/` is preserved):
234
+
235
+
```shell
236
+
docker compose down
237
+
```
238
+
239
+
To stop and remove containers and volumes (the `-v` option deletes all database data):
240
+
241
+
```shell
242
+
docker compose down -v
243
+
```
244
+
245
+
Note: The Compose file in the guide uses bind mounts (`./data-pxc1`, etc.), not named volumes, so `-v` removes only any named volumes if present. To fully reset, remove the data directories manually: `rm -rf data-pxc1 data-pxc2 data-pxc3` (only when the containers are stopped).
246
+
247
+
## Appendix: Podman Alternative
248
+
249
+
Podman can be used as an alternative to Docker because Podman supports the same container images. However, Podman is not fully compatible with Docker Compose.
250
+
251
+
To run the deployment with Podman, you may need to use tools such as podman compose, podman-compose, or a configured Docker Compose compatibility layer, depending on your environment.
252
+
253
+
Podman uses a different architecture (for example, pods and rootless containers), so networking, volume mounts, and service behavior may differ from Docker Compose.
254
+
255
+
The deployment is designed and tested with Docker Compose. Podman support is not guaranteed. If you use Podman, verify that the cluster operates correctly before using the cluster beyond testing or experimentation.
256
+
257
+
You can use the same Compose file and workflow with [Podman](https://podman.io/). Use Podman 4.1 or later; the built-in `podman compose` subcommand requires 4.1 or newer. With older Podman, use the separate podman-compose tool. Then:
258
+
259
+
* Prerequisites: Podman and Podman Compose (for example, `pip install podman-compose` or your distro's package) if you are not using built-in `podman compose`. For rootless Podman, ensure the user has enough resources (for example, `sysctl user.max_user_namespaces` and subuid/subgid ranges).
260
+
261
+
* Commands: Replace `docker compose` with `podman compose` or `podman-compose`, and `docker exec` with `podman exec`. Examples:
262
+
263
+
* Start node 1: `podman compose up -d pxc1` (or `podman-compose up -d pxc1`)
264
+
265
+
* Start other nodes: `podman compose up -d pxc2 pxc3`
266
+
267
+
* Validate: `podman exec -it pxc1 mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_cluster_size';"`
268
+
269
+
* Directory structure: The same layout (`pxc-cluster/` with `certs/`, `conf.d/`, and `init/`) works with Podman. Run `podman compose` from the project directory (for example, `pxc-cluster/`) so the relative volume paths in the Compose file resolve correctly.
270
+
271
+
* Compose file: The `docker-compose.yml` in the guide works as-is with Podman; the `bridge` network and volume mounts are supported. For rootless Podman, see the volume mount options below.
272
+
273
+
### Handling rootless permissions (most important for Podman)
274
+
275
+
In Docker, the daemon runs as root and can override file permissions. In Podman, if you run as a normal user, the MySQL process inside the container (usually UID 1001 or 999) may not have permission to read the files you created on the host. Ensure the files are readable by the container. On systems with SELinux, use the `:Z` (private) or `:z` (shared) mount option so Podman relabels the volume for the container. In your `docker-compose.yml`, use:
Apply the same volume options to every service (pxc1, pxc2, pxc3). Without `:Z` or `:z`, the container may fail to read certs or config when running rootless on SELinux.
284
+
285
+
### podman-compose vs docker-compose
286
+
287
+
* If you use podman-compose (the Python tool): podman-compose reads the directory structure and `.env` file the same way Docker does.
288
+
289
+
* If you use docker-compose with the Podman socket: Using docker-compose with the Podman socket is often more stable for PXC. Set `DOCKER_HOST` to point at the Podman socket (for example, `unix:///run/user/$(id -u)/podman/podman.sock`) so `docker compose` talks to Podman.
290
+
291
+
### Network considerations
292
+
293
+
PXC uses specific ports for cluster communication (4567, 4568, 4444). Podman uses different networking (netavark or CNI). If nodes cannot find each other:
294
+
295
+
* Keep using a named network in the Compose file (for example, `pxcnet`) so Podman can resolve container names (pxc1, pxc2, pxc3).
296
+
297
+
* If problems persist, try setting `network_mode: slirp4netns` on the services, or run the stack rootful to use the default bridge.
0 commit comments