-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdocker-compose.yaml
More file actions
334 lines (320 loc) · 9 KB
/
Copy pathdocker-compose.yaml
File metadata and controls
334 lines (320 loc) · 9 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
version: '3.7'
# 定义网络
networks:
weave-network:
driver: bridge
# 定义卷
volumes:
mysql-data:
driver: local
logs:
driver: local
prometheus-data:
driver: local
grafana-data:
driver: local
postgres-data:
driver: local
redis-data:
driver: local
nginx-config:
driver: local
nginx-logs:
driver: local
# 定义服务
services:
# Nginx负载均衡服务
nginx:
image: nginx:alpine
container_name: weave-nginx
restart: unless-stopped
networks:
- weave-network
ports:
- "8084:80" # 负载均衡器入口
- "80:80" # HTTP入口
- "443:443" # HTTPS入口(可选)
volumes:
- nginx-config:/etc/nginx/conf.d
- nginx-logs:/var/log/nginx
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./config/nginx/weave.conf:/etc/nginx/conf.d/weave.conf:ro
depends_on:
- weave-1
- weave-2
- weave-3
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80/nginx_status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
# Weave应用服务 - 实例1
weave-1:
build: .
container_name: weave-app-1
restart: unless-stopped
networks:
- weave-network
ports:
- "8081:8081"
environment:
- SERVER_PORT=8081
- INSTANCE_ID=weave-1
- DB_HOST=mysql
- DB_PORT=3306
- DB_USERNAME=weave_user
- DB_PASSWORD=${DB_PASSWORD:-default_password}
- DB_NAME=weave
- DB_CHARSET=utf8mb4
- REDIS_ADDR=redisearch:6379
- JWT_SECRET=${JWT_SECRET:-default_jwt_secret}
- JWT_ACCESS_TOKEN_EXPIRY=60
- JWT_REFRESH_TOKEN_EXPIRY=168
- CSRF_ENABLED=true
- CSRF_COOKIE_NAME=XSRF-TOKEN
- CSRF_HEADER_NAME=X-CSRF-Token
- LOG_LEVEL=info
- LOG_OUTPUT_PATH=/app/logs/output.log
- LOG_ERROR_PATH=/app/logs/error.log
depends_on:
- mysql
- redisearch
volumes:
- logs:/app/logs
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:8081/health" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Weave应用服务 - 实例2
weave-2:
build: .
container_name: weave-app-2
restart: unless-stopped
networks:
- weave-network
ports:
- "8082:8082"
environment:
- SERVER_PORT=8082
- INSTANCE_ID=weave-2
- DB_HOST=mysql
- DB_PORT=3306
- DB_USERNAME=weave_user
- DB_PASSWORD=${DB_PASSWORD:-default_password}
- DB_NAME=weave
- DB_CHARSET=utf8mb4
- REDIS_ADDR=redisearch:6379
- JWT_SECRET=${JWT_SECRET:-default_jwt_secret}
- JWT_ACCESS_TOKEN_EXPIRY=60
- JWT_REFRESH_TOKEN_EXPIRY=168
- CSRF_ENABLED=true
- CSRF_COOKIE_NAME=XSRF-TOKEN
- CSRF_HEADER_NAME=X-CSRF-Token
- LOG_LEVEL=info
- LOG_OUTPUT_PATH=/app/logs/output.log
- LOG_ERROR_PATH=/app/logs/error.log
depends_on:
- mysql
- redisearch
volumes:
- logs:/app/logs
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:8082/health" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Weave应用服务 - 实例3
weave-3:
build: .
container_name: weave-app-3
restart: unless-stopped
networks:
- weave-network
ports:
- "8083:8083"
environment:
- SERVER_PORT=8083
- INSTANCE_ID=weave-3
- DB_HOST=mysql
- DB_PORT=3306
- DB_USERNAME=weave_user
- DB_PASSWORD=${DB_PASSWORD:-default_password}
- DB_NAME=weave
- DB_CHARSET=utf8mb4
- REDIS_ADDR=redisearch:6379
- JWT_SECRET=${JWT_SECRET:-default_jwt_secret}
- JWT_ACCESS_TOKEN_EXPIRY=60
- JWT_REFRESH_TOKEN_EXPIRY=168
- CSRF_ENABLED=true
- CSRF_COOKIE_NAME=XSRF-TOKEN
- CSRF_HEADER_NAME=X-CSRF-Token
- LOG_LEVEL=info
- LOG_OUTPUT_PATH=/app/logs/output.log
- LOG_ERROR_PATH=/app/logs/error.log
depends_on:
- mysql
- redisearch
volumes:
- logs:/app/logs
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:8083/health" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# MySQL数据库服务
mysql:
# 使用官方MySQL镜像
image: mysql:8.0
# 容器名称
container_name: weave-mysql
# 重启策略
restart: unless-stopped
# 网络配置
networks:
- weave-network
# 端口映射 (可选,仅当需要从主机直接访问数据库时启用)
# ports:
# - "3306:3306"
# 环境变量配置
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root_password}
- MYSQL_DATABASE=weave
- MYSQL_USER=weave_user
- MYSQL_PASSWORD=${DB_PASSWORD:-default_password}
# 卷挂载 (数据持久化)
volumes:
- mysql-data:/var/lib/mysql
# 可选:初始化脚本
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
# 健康检查
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "--password=${MYSQL_ROOT_PASSWORD:-root_password}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# 默认启用,如需禁用可通过docker-compose命令参数控制
# 示例: docker-compose up -d --scale mysql=0 postgres
# Redis服务
redisearch:
image: redis/redis-stack:latest
container_name: weave-redis
networks:
- weave-network
ports:
- "6379:6379" # Redis port
- "8001:8001" # RedisInsight port
volumes:
- redis-data:/data
environment:
- REDIS_ARGS=--dir /data --appendonly no --save 1800 1
restart: unless-stopped
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 3
# PostgreSQL数据库服务(可选)
postgres:
# 使用官方PostgreSQL镜像
image: postgres:15
# 容器名称
container_name: weave-postgres
# 重启策略
restart: unless-stopped
# 网络配置
networks:
- weave-network
# 端口映射 (可选,仅当需要从主机直接访问数据库时启用)
# ports:
# - "5432:5432"
# 环境变量配置
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
- POSTGRES_USER=${DB_USERNAME:-weave_user}
- POSTGRES_DB=weave
# 卷挂载 (数据持久化)
volumes:
- postgres-data:/var/lib/postgresql/data
# 可选:初始化脚本
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
# 健康检查
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-weave_user} -d weave"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# 默认禁用,如需启用可通过docker-compose命令参数控制
# 示例: docker-compose up -d --scale mysql=0 postgres
# Prometheus监控服务
prometheus:
image: prom/prometheus:latest
container_name: weave-prometheus
restart: unless-stopped
networks:
- weave-network
ports:
- "9090:9090"
volumes:
- prometheus-data:/prometheus
- ./pkg/metrics/prometheus.yml:/etc/prometheus/prometheus.yml:ro
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
depends_on:
- weave-1
- weave-2
- weave-3
# Grafana可视化服务
grafana:
image: grafana/grafana:latest
container_name: weave-grafana
restart: unless-stopped
networks:
- weave-network
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
- ./config/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
depends_on:
- prometheus
# 使用说明:
# 1. 创建.env文件,设置以下环境变量(可选但推荐):
# DB_PASSWORD=your_secure_password
# JWT_SECRET=your_secure_jwt_secret
# MYSQL_ROOT_PASSWORD=your_root_password
#
# 2. 启动服务:
# docker-compose up -d
#
# 3. 停止服务:
# docker-compose down
#
# 4. 查看日志:
# docker-compose logs -f weave-app
# docker-compose logs -f weave-mysql
#
# 5. 进入容器:
# docker-compose exec weave-app /bin/sh
# docker-compose exec weave-mysql mysql -u root -p
#
# 6. 查看服务状态:
# docker-compose ps
#
# 7. 构建并重新启动服务:
# docker-compose up --build -d