-
Notifications
You must be signed in to change notification settings - Fork 50
/
docker-compose.yml
121 lines (108 loc) · 5.52 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
version: '3.3'
# 在PXC里同时更新到同一行记录是可能存在这个风险的, 乐观并发控制, 只锁本地的行记录,不锁别人的,不锁全局,本地处理完再发给别人,那么就有可能大家同时更新同一行记录
# 一个巨坑,配置了一个docker网络,然后把该名称网络删掉,再新建同名网络但是配置其他IP段,发现该名称网络还是用了之前的IP段,反复删除了很多次,发现都是用了旧的IP段,最后systemctl stop docker,再重启后,才用了新网段IP
# docker开启SQL日志,--general_log_file用绝对路时,发现失败了,没有在该路径生成日志文件
# 查看日志 cat /var/lib/mysql/mysql-sql.log
# 查看最后100行日志 tail -n 100 /var/lib/mysql/mysql-sql.log
# 扑街的教训,percona/percona-xtradb-cluster:5.7.25镜像要挂载/var/lib/mysql目录到宿主机,宿主机目录要授予 777 的操作权限, 否则挂载目录后, 数据库跑不起来
# mkdir -p data/mysql-cluster-node01 data/mysql-cluster-node02 data/mysql-cluster-node03 data/mysql-cluster-node04 data/mysql-cluster-node05
# chmod 777 data/mysql-cluster-node01 data/mysql-cluster-node02 data/mysql-cluster-node03 data/mysql-cluster-node04 data/mysql-cluster-node05
# 扑街的教训,docker-compose引用已存在的网络,格式如下,亲测过的,被网上的博客坑了
# networks:
# 外部网络的名称: # 必须是外部docker网卡的名称,被网上的博客坑了,白白浪费几个小时
# external: true
services:
mysql-cluster-node01:
image: percona/percona-xtradb-cluster:5.7.25
container_name: mysql-cluster-node01
restart: always
environment:
- TZ=Asia/Shanghai
- CLUSTER_NAME=mysql-cluster
- MYSQL_ROOT_PASSWORD=password
- CMDARG=--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-time-zone=+8:00 --log-timestamps=SYSTEM --general_log=on --general_log_file=mysql-sql.log
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/mysql-cluster-node01:/var/lib/mysql
networks:
percona-xtradb-cluster-network:
ipv4_address: 172.16.17.11
mysql-cluster-node02:
image: percona/percona-xtradb-cluster:5.7.25
container_name: mysql-cluster-node02
restart: always
environment:
- TZ=Asia/Shanghai
- CLUSTER_NAME=mysql-cluster
- MYSQL_ROOT_PASSWORD=password
- CLUSTER_JOIN=mysql-cluster-node01
- CMDARG=--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-time-zone=+8:00 --log-timestamps=SYSTEM --general_log=on --general_log_file=mysql-sql.log
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/mysql-cluster-node02:/var/lib/mysql
networks:
percona-xtradb-cluster-network:
ipv4_address: 172.16.17.12
mysql-cluster-node03:
image: percona/percona-xtradb-cluster:5.7.25
container_name: mysql-cluster-node03
restart: always
environment:
- TZ=Asia/Shanghai
- CLUSTER_NAME=mysql-cluster
- MYSQL_ROOT_PASSWORD=password
- CLUSTER_JOIN=mysql-cluster-node01
- CMDARG=--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-time-zone=+8:00 --log-timestamps=SYSTEM --general_log=on --general_log_file=mysql-sql.log
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/mysql-cluster-node03:/var/lib/mysql
networks:
percona-xtradb-cluster-network:
ipv4_address: 172.16.17.13
mysql-cluster-node04:
image: percona/percona-xtradb-cluster:5.7.25
container_name: mysql-cluster-node04
restart: always
environment:
- TZ=Asia/Shanghai
- CLUSTER_NAME=mysql-cluster
- MYSQL_ROOT_PASSWORD=password
- CLUSTER_JOIN=mysql-cluster-node01
- CMDARG=--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-time-zone=+8:00 --log-timestamps=SYSTEM --general_log=on --general_log_file=mysql-sql.log
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/mysql-cluster-node04:/var/lib/mysql
networks:
percona-xtradb-cluster-network:
ipv4_address: 172.16.17.14
mysql-cluster-node05:
image: percona/percona-xtradb-cluster:5.7.25
container_name: mysql-cluster-node05
restart: always
environment:
- TZ=Asia/Shanghai
- CLUSTER_NAME=mysql-cluster
- MYSQL_ROOT_PASSWORD=password
- CLUSTER_JOIN=mysql-cluster-node01
- CMDARG=--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-time-zone=+8:00 --log-timestamps=SYSTEM --general_log=on --general_log_file=mysql-sql.log
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/mysql-cluster-node05:/var/lib/mysql
networks:
percona-xtradb-cluster-network:
ipv4_address: 172.16.17.15
networks:
percona-xtradb-cluster-network:
driver: bridge
ipam:
config:
- subnet: 172.16.17.0/24
# docker exec -it mysql-cluster-node01 sh -c 'mysql -u root -ppassword -e "DROP DATABASE IF EXISTS walle; CREATE DATABASE walle DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; SHOW DATABASES;"'
# docker exec -it mysql-cluster-node02 sh -c 'mysql -u root -ppassword -e "SHOW DATABASES;"'
# docker exec -it mysql-cluster-node03 sh -c 'mysql -u root -ppassword -e "SHOW DATABASES;"'
# docker exec -it mysql-cluster-node04 sh -c 'mysql -u root -ppassword -e "SHOW DATABASES;"'
# docker exec -it mysql-cluster-node05 sh -c 'mysql -u root -ppassword -e "SHOW DATABASES;"'
# 使用外部定义的docker网络
# networks:
# percona-xtradb-cluster-network:
# external: true