-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathblog_start.sh
More file actions
251 lines (217 loc) · 7.04 KB
/
Copy pathblog_start.sh
File metadata and controls
251 lines (217 loc) · 7.04 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
#!/bin/bash
echo ' __ ';
echo ' ____ _____ ___ _________ ____/ /__ ';
echo ' / __ `/ __ \/ _ \/ ___/ __ \/ __ / _ \';
echo ' / /_/ / /_/ / __/ /__/ /_/ / /_/ / __/';
echo ' \__,_/ .___/\___/\___/\____/\__,_/\___/ ';
echo ' /_/ ';
# 项目目录
folder="/blog"
if [ -d $folder ]; then
read -p "检测到项目文件夹已存在,是否将其删除后重新创建?y/n: " isDeleteFolder;
if [ $isDeleteFolder = "y" ]; then
rm -rf $folder;
else
echo "exit";
exit;
fi
fi
mkdir -p ${folder}/redis/conf ${folder}/redis/data ${folder}/rabbitmq ${folder}/mariadb/sql ${folder}/mariadb/db ${folder}/nginx/cert ${folder}/nginx/logs ${folder}/nginx/upload ${folder}/nginx/www ${folder}/nginx/www/admin ${folder}/nginx/www/blog;
cat << EOF > ${folder}/redis/conf/redis.conf
# bind 0.0.0.0
protected-mode yes
port 6379
dir /data
daemonize no
requirepass "密码"
logfile "redis.log"
dbfilename redis.rdb
appendfilename "appendonly.aof"
appendonly yes
activedefrag yes
active-defrag-ignore-bytes 100mb
active-defrag-cycle-min 1
active-defrag-cycle-max 25
EOF
cat << EOF > ${folder}/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 50m;
client_body_buffer_size 10m;
client_header_timeout 1m;
client_body_timeout 1m;
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
server {
listen 443 ssl;
server_name 前台域名;
ssl_certificate /usr/local/nginx/cert/xxx.pem;
ssl_certificate_key /usr/local/nginx/cert/xxx.key;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4:!RSA;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header 'X-XSS-Protection' '1; mode=block' always;
location / {
root /www/blog;
index index.html index.htm;
try_files \$uri \$uri/ /index.html;
proxy_ignore_client_abort on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl;
server_name 后台域名;
ssl_certificate /usr/local/nginx/cert/xxx.pem;
ssl_certificate_key /usr/local/nginx/cert/xxx.key;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4:!RSA;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header 'X-XSS-Protection' '1; mode=block' always;
location / {
root /www/admin;
index index.html index.htm;
try_files \$uri \$uri/ /index.html;
proxy_ignore_client_abort on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl;
server_name 文件子域名;
ssl_certificate /usr/local/nginx/cert/xxx.pem;
ssl_certificate_key /usr/local/nginx/cert/xxx.key;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4:!RSA;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header 'X-XSS-Protection' '1; mode=block' always;
location / {
root /usr/local/upload/;
autoindex on;
}
}
}
EOF
cat << EOF > ${folder}/docker-compose.yml
version: '3.9'
services:
redis:
image: redis:6.2.7
container_name: redis_blog
ports:
- 6371:6379
volumes:
- ${folder}/redis/conf/redis.conf:/etc/redis/redis.conf
- ${folder}/redis/data:/data
networks:
- blog
command: redis-server /etc/redis/redis.conf
mariadb:
image: mariadb:10.6.8
container_name: mariadb_blog
ports:
- 3306:3306
volumes:
- ${folder}/mariadb/db/:/var/lib/mysql
- ${folder}/mariadb/sql/:/docker-entrypoint-initdb.d/
environment:
- MARIADB_ROOT_PASSWORD=数据库密码
networks:
- blog
rabbitmq:
image: rabbitmq:3.9.18-management
container_name: rabbitmq_blog
ports:
- 5672:5672
- 15672:15672
volumes:
- ${folder}/rabbitmq/:/var/lib/rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=账号
- RABBITMQ_DEFAULT_PASS=密码
networks:
- blog
myblog:
image: myblog:latest
container_name: myblog
volumes:
- ${folder}/log/:/var/log/blog/
- ${folder}/lib/:${folder}/lib/
build:
context: ${folder}/
dockerfile: Dockerfile-BlogJar
ports:
- 8081:8081
networks:
- blog
depends_on:
- redis
- mariadb
- rabbitmq
nginx:
image: nginx:1.23.3
container_name: nginx_blog
ports:
- 80:80
- 443:443
volumes:
- ${folder}/nginx/nginx.conf:/etc/nginx/nginx.conf
- ${folder}/nginx/logs:/var/log/nginx
- ${folder}/nginx/www:/www
- ${folder}/nginx/cert:/usr/local/nginx/cert
- ${folder}/nginx/upload/:/usr/local/upload/
environment:
- TZ=Asia/Shanghai
networks:
- blog
depends_on:
- myblog
networks:
blog:
name: blog
EOF
cat << EOF > ${folder}/Dockerfile-BlogJar
FROM openjdk:8-jre
MAINTAINER apecode<apecode@qq.com>
RUN echo "Asia/Shanghai" > /etc/timezone
EXPOSE 8081
ADD blog-api.jar app.jar
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Dloader.path=${folder}/lib", "-jar", "/app.jar"]
EOF
echo
echo "项目文件初始化完成,请根据文档修改相应配置";
echo ">>> cd ${folder}"
echo ">>> ls"
echo