docker-compose安装PXC集群
2020-01-10 本文已影响0人
飞跑的蛤蟆
docker-compose安装pxc集群
用到的文件
docker-compose.yaml文件
version: '3.0'
services:
pxc1:
image: hub.docker-registry.com/percona/percona-xtradb-cluster:5.7.21
container_name: node1
ports:
- 3306:3306/tcp
volumes:
- v1:/var/lib/mysql
networks:
net1:
ipv4_address: 172.18.0.2
environment:
- MYSQL_ROOT_PASSWORD=123456
- CLUSTER_NAME=PXC
- XTRABACKUP_PASSWORD=123456
pxc2:
image: hub.docker-registry.com/percona/percona-xtradb-cluster:5.7.21
container_name: node2
ports:
- 3307:3306/tcp
volumes:
- v2:/var/lib/mysql
networks:
net1:
ipv4_address: 172.18.0.3
env_file:
- ./.env
depends_on:
- pxc1
pxc3:
image: hub.docker-registry.com/percona/percona-xtradb-cluster:5.7.21
container_name: node3
ports:
- 3308:3306/tcp
volumes:
- v3:/var/lib/mysql
networks:
net1:
ipv4_address: 172.18.0.4
env_file:
- ./.env
depends_on:
- pxc1
pxc4:
image: hub.docker-registry.com/percona/percona-xtradb-cluster:5.7.21
container_name: node4
ports:
- 3309:3306/tcp
volumes:
- v4:/var/lib/mysql
networks:
net1:
ipv4_address: 172.18.0.5
env_file:
- ./.env
depends_on:
- pxc1
pxc5:
image: hub.docker-registry.com/percona/percona-xtradb-cluster:5.7.21
container_name: node5
ports:
- 3310:3306/tcp
volumes:
- v5:/var/lib/mysql
networks:
net1:
ipv4_address: 172.18.0.6
env_file:
- ./.env
depends_on:
- pxc1
networks:
net1:
external: false
ipam:
config:
- subnet: 172.18.0.0/24
volumes:
v1:
v2:
v3:
v4:
v5:
.env文件
MYSQL_ROOT_PASSWORD=123456
CLUSTER_NAME=PXC
XTRABACKUP_PASSWORD=123456
CLUSTER_JOIN=node1
.dockerignore文件
Dockerfile
.git
.env
可能会遇到的问题
系统关机后,pxc集群可能会起不来,这就需要修改集群中的第一台数据库的配置项
操作步骤:
- 先查看要修改的是哪个数据卷(pxc_v1)
$ docker volume ls
local pxc_v1
local pxc_v2
local pxc_v3
local pxc_v4
local pxc_v5
- 查看数据卷的信息
docker volume inspect pxc_v1
[
{
"CreatedAt": "2019-11-07T22:47:20+08:00",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "pxc",
"com.docker.compose.version": "1.25.0dev",
"com.docker.compose.volume": "v1"
},
"Mountpoint": "/var/lib/docker/volumes/pxc_v1/_data",
"Name": "pxc_v1",
"Options": null,
"Scope": "local"
}
]
- 修改配置文件(grastate.dat)
将配置项safe_to_bootstrap
的值设置为1
$ cd /var/lib/docker/volumes/pxc_v1/_data
$ ls
2ee09b0e31f6-bin.000001 auto.cnf client-key.pem ibdata1 innobackup.backup.log public_key.pem xb_doublewrite
2ee09b0e31f6-bin.000002 ca-key.pem galera.cache ib_logfile0 mysql server-cert.pem
2ee09b0e31f6-bin.000003 ca.pem grastate.dat ib_logfile1 performance_schema server-key.pem
2ee09b0e31f6-bin.index client-cert.pem ib_buffer_pool ibtmp1 private_key.pem sys
# GALERA saved state
version: 2.1
uuid: aea1a37f-0106-11ea-8ff2-b7f0d5f49e3a
seqno: -1
safe_to_bootstrap: 0