经过几个月的开发,开发的项目即将进入交付环节。

然而,客户限制Windows环境部署,但本人对Linux比较熟、中间件在Windows部署也比较麻烦。

因此,使用两种方法部署,间接使用Linux系统:1. WSL执行一键部署脚本、2.Docker镜像。

部署策略

对于客户而言,需要尽可能【一键式】部署。

因此,通过大模型生成PowerShell版本部署脚本、启动服务脚本、停止服务脚本。

也可以借助大模型生成对应Bash版本部署脚本。

交付客户前,将配置文件说明、命令写到文档中,并录演示视频。

最后,给用户提供了两种部署方法:Linux一键部署安装包、Docker一键部署安装包。

大模型Prompt

当然,不会自己硬写脚本,大模型即可代劳。Prompt如下:

1
2
3
4
5
6
7
8
9
10
11
我需要使用bash脚本部署我的工程,请bash通过读取配置文件。环境可能是ubuntu、centos7或centos8,请提供bash脚本及配置文件。

1.允许用户自定义是否安装
2.允许用户指定ip、port、账号密码,当指定了上述配置时,需要尝试连接,如果连接成功则不要安装。如果连接失败,则提示用户修改配置文件。
3.我需要安装mysql或postgresql时,设置为配置中的账号和密码

依赖如下:
openjdk17
mysql
postgresql
nginx

大模型生成配置文件

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
[common]
install_java=yes
install_nginx=yes
install_thingsboard=yes

[mysql]
install=yes
host=localhost
port=3306
user=uuuu
password=pppp

[mysql_slave]
enable=false
url=
username=
password=

[postgresql]
install=yes
host=localhost
port=5432
user=uuuu
password=pppp

[redis]
install=yes
host=localhost
port=6379
database=0
password=

[nginx]
thingsboard_ssl_certificate=
thingsboard_ssl_certificate_key=
xxx_ssl_certificate=
xxx_ssl_certificate_key=

[port]
a_port=8080
b_port=8081
c_port=8001

最终一键部署脚本

*略去需要保密信息

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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
#!/bin/bash

CONFIG_FILE="deploy.conf"

# 获取当前脚本目录
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
SQL_FILE="$SCRIPT_DIR/ruoyi-admin/xxx.sql"

# 检查配置文件
if [ ! -f "$CONFIG_FILE" ]; then
echo "错误:配置文件 $CONFIG_FILE 不存在"
exit 1
fi

# 读取配置文件
declare -A CONFIG
CURRENT_SECTION=""
while IFS= read -r line; do
line=${line%%#*} # 去除注释
line=${line// /} # 去除空格
[[ -z $line ]] && continue

if [[ $line == \[*\] ]]; then
CURRENT_SECTION=${line:1:-1}
elif [[ $line == *=* ]]; then
key="${CURRENT_SECTION}_${line%%=*}"
CONFIG[$key]=${line#*=}
fi
done < "$CONFIG_FILE"

# 获取配置项函数
get_config() {
local key="$1"
echo "${CONFIG[${key}]:-}"
}

# 定义数据库配置变量
MYSQL_ROOT_PASSWORD=$(get_config 'mysql_password')
PG_POSTGRES_PASSWORD=$(get_config 'postgresql_password')
DB_USER=$(get_config 'mysql_user')
DB_PASSWORD=$(get_config 'mysql_password')
PG_USER=$(get_config 'postgresql_user')
PG_PASSWORD=$(get_config 'postgresql_password')
PG_HOST=$(get_config 'postgresql_host')
PG_PORT=$(get_config 'postgresql_port')

# 新增:导入 xxx.sql 到 MySQL 数据库
import_xxx_sql() {
local host=$1
local port=$2
local user=$3
local password=$4
local sql_file=$5

# 检查 SQL 文件是否存在
if [ ! -f "$sql_file" ]; then
echo "错误:SQL 文件 $sql_file 不存在"
exit 1
fi

# 检查数据库是否存在
if mysql -h$host -P$port -u$user -p$password -e "USE xxx" 2>/dev/null; then
echo "数据库 xxx 已存在,跳过创建"
else
echo "创建数据库 xxx..."
mysql -h$host -P$port -u$user -p$password -e "CREATE DATABASE xxx;"
fi

# 导入 SQL 文件
echo "导入 $sql_file 到 xxx 数据库..."
mysql -h$host -P$port -u$user -p$password xxx < "$sql_file"
if [ $? -eq 0 ]; then
echo "导入成功"
else
echo "导入失败"
exit 1
fi
}

# 更新 sys_menu 表
update_sys_menu() {
local host=$1
local port=$2
local user=$3
local password=$4
local thingsboard_url=$5

if [ -z "$thingsboard_url" ]; then
echo "警告:thingsboard_url 未配置,跳过 sys_menu 更新"
return
fi

echo "更新 sys_menu 表 (menu_id=2005) 的 path 字段为 $thingsboard_url"
mysql -h$host -P$port -u$user -p$password xxx <<EOF
UPDATE sys_menu SET path = "$thingsboard_url" WHERE menu_id = 2005;
EOF

if [ $? -eq 0 ]; then
echo "sys_menu 表更新成功"
else
echo "警告:sys_menu 表更新失败"
fi
}

# 获取系统信息
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$ID

# 兼容Alibaba Linux
if [[ "$ID" == "alinux" ]]; then
OS_NAME="centos"
# 根据版本号映射到CentOS版本
if [[ "$VERSION_ID" == "2"* ]]; then
OS_VERSION="7"
elif [[ "$VERSION_ID" == "3"* ]]; then
OS_VERSION="8"
fi
else
OS_VERSION=${VERSION_ID%%.*}
fi
else
echo "无法检测操作系统"
exit 1
fi
}

# 关闭IPv6并确保持续生效(修改版)
disable_ipv6() {
echo "开始禁用IPv6..."

# 检查是否已存在相关配置
if grep -q "net.ipv6.conf.all.disable_ipv6" /etc/sysctl.conf; then
# 更新现有配置
sudo sed -i 's/^net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 1/' /etc/sysctl.conf
sudo sed -i 's/^net.ipv6.conf.default.disable_ipv6.*/net.ipv6.conf.default.disable_ipv6 = 1/' /etc/sysctl.conf
else
# 添加新配置
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
fi

# 立即应用设置
sudo sysctl -p

echo "IPv6已禁用并设置为持续生效"
}

# 安装包管理工具
install_package() {
local package=$1
case $OS_NAME in
ubuntu)
sudo apt install -y $package
;;
centos|rhel|alinux)
# 统一处理CentOS/RHEL/Alibaba Linux
if [ $OS_VERSION -eq 7 ]; then
sudo yum install -y $package --nogpgcheck
else
sudo dnf install -y $package --nogpgcheck
fi
;;
*)
echo "不支持的发行版: $OS_NAME"
exit 1
;;
esac
}

# 检查服务连接
check_db_connection() {
local db_type=$1
local host=$2
local port=$3
local user=$4
local password=$5

case $db_type in
mysql)
if ! command -v mysql &> /dev/null; then
install_package "mysql-client"
fi
mysql -h$host -P$port -u$user -p$password -e "SELECT 1;" &> /dev/null
return $?
;;
postgresql)
if ! command -v psql &> /dev/null; then
install_package "postgresql-client"
fi
PGPASSWORD="$password" psql -h $host -p $port -U $user -d postgres -c "SELECT 1;" &> /dev/null
return $?
;;
*)
return 1
;;
esac
}

# 等待数据库可用
wait_for_db() {
local db_type=$1
local host=$2
local port=$3
local user=$4
local password=$5

echo "等待 $db_type$host:$port 可用..."
for i in {1..60}; do
if check_db_connection "$db_type" "$host" "$port" "$user" "$password"; then
echo "$db_type 已就绪"
return 0
fi
sleep 5
echo "等待 $db_type 服务 ($i/60)..."
done
echo "错误: $db_type 服务启动超时"
return 1
}

# 创建 PostgreSQL 数据库
ensure_postgresql_db() {
local host=$1
local port=$2
local user=$3
local password=$4
local db_name=$5
local admin_user="postgres"
local admin_password=$PG_POSTGRES_PASSWORD

# 检查数据库是否存在
if PGPASSWORD="$password" psql -h $host -p $port -U $user -d postgres -lqt | cut -d \| -f 1 | grep -qw $db_name; then
echo "数据库 $db_name 已存在"
else
echo "创建数据库 $db_name..."

# 使用管理员用户创建数据库
PGPASSWORD="$admin_password" psql -h $host -p $port -U $admin_user <<EOF
CREATE DATABASE $db_name;
GRANT ALL PRIVILEGES ON DATABASE $db_name TO $user;
EOF
fi

# 确保用户对public模式有权限
echo "确保 $user$db_name 的 public 模式有权限..."
PGPASSWORD="$admin_password" psql -h $host -p $port -U $admin_user -d $db_name <<EOF
GRANT ALL ON SCHEMA public TO $user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $user;
EOF
}

# 安装 基础依赖
install_base() {
# 先禁用IPv6
disable_ipv6

case $OS_NAME in
ubuntu)
apt update
DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get -y install tzdata
apt install -y sudo curl systemctl
apt install -y language-pack-zh-han*
echo LANG=zh_CN.UTF-8 > /etc/default/locale
source /etc/default/locale
;;

centos|rhel|alinux)
# 统一处理CentOS/RHEL/Alibaba Linux
if [ $OS_VERSION -eq 7 ]; then
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
yum clean all && \
yum makecache
else
cp -r /etc/yum.repos.d/ /etc/yum.repos.d_bak
rm -rf /etc/yum.repos.d/CentOS-Linux*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*
yum clean all && yum makecache
fi

yum install -y sudo freetype fontconfig epel-release --nogpgcheck

# 安装中文语言包并设置系统语言为中文
echo "安装中文语言包并设置系统语言..."
sudo yum install -y glibc-langpack-zh.x86_64
echo LANG=zh_CN.UTF-8 > /etc/locale.conf
source /etc/locale.conf
;;
esac
}

# 安装 Java
install_java() {
case $OS_NAME in
ubuntu)
sudo apt update
sudo apt install -y openjdk-17-jdk
;;

centos|rhel|alinux)
sudo yum install -y rpm/jdk-17.0.15_linux-x64_bin.rpm --nogpgcheck
;;
esac
}

# 安装 MySQL
install_mysql() {
case $OS_NAME in
ubuntu)
# 预置root密码
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD"
sudo apt install -y mysql-server
sudo systemctl enable --now mysql

# 自动创建配置用户
sudo mysql -uroot -p$MYSQL_ROOT_PASSWORD <<EOF
CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF
;;

centos|rhel|alinux)
sudo yum module -y disable mysql
if [ $OS_VERSION -eq 7 ]; then
sudo yum install -y rpm/mysql84-community-release-el7-1.noarch.rpm --nogpgcheck
else
sudo yum install -y rpm/mysql84-community-release-el8-1.noarch.rpm --nogpgcheck
fi

sudo yum install -y mysql-community-server --nogpgcheck
sudo systemctl enable --now mysqld

# 获取临时密码
temp_pass=$(sudo grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')

# 自动修改root密码
mysql -uroot -p"$temp_pass" --connect-expired-password <<EOF 2>/dev/null
ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';
FLUSH PRIVILEGES;
EOF

# 创建配置用户
mysql -uroot -p$MYSQL_ROOT_PASSWORD <<EOF
CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF
;;
esac
}

# 安装 PostgreSQL
install_postgresql() {
case $OS_NAME in
ubuntu)
sudo apt install -y postgresql postgresql-contrib
sudo service postgresql start

# 使用单个psql命令避免目录错误
sudo -u postgres psql <<EOF
ALTER USER postgres WITH PASSWORD '$PG_POSTGRES_PASSWORD';
CREATE USER $PG_USER WITH PASSWORD '$PG_PASSWORD';
ALTER USER $PG_USER CREATEDB;
CREATE DATABASE thingsboard;
GRANT ALL PRIVILEGES ON DATABASE thingsboard TO $PG_USER;
EOF

# 确保用户对public模式有权限
sudo -u postgres psql -d thingsboard <<EOF
GRANT ALL ON SCHEMA public TO $PG_USER;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $PG_USER;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $PG_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $PG_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $PG_USER;
EOF
;;

centos|rhel|alinux)

if [ $OS_VERSION -eq 7 ]; then
sudo yum install -y rpm/postgresql15-libs-15.9-1PGDG.rhel7.x86_64.rpm --nogpgcheck
sudo yum install -y rpm/postgresql15-15.9-1PGDG.rhel7.x86_64.rpm --nogpgcheck
sudo yum install -y rpm/postgresql15-server-15.9-1PGDG.rhel7.x86_64.rpm --nogpgcheck

# Initialize your PostgreSQL DB
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable --now postgresql-15
else
sudo yum install -y rpm/postgresql16-libs-16.9-3PGDG.rhel8.x86_64.rpm --nogpgcheck
sudo yum install -y rpm/postgresql16-16.9-3PGDG.rhel8.x86_64.rpm --nogpgcheck
sudo yum install -y rpm/postgresql16-server-16.9-3PGDG.rhel8.x86_64.rpm --nogpgcheck

sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable --now postgresql-16
fi

# 创建用户和数据库
sudo -u postgres psql <<EOF
ALTER USER postgres WITH PASSWORD '$PG_POSTGRES_PASSWORD';
CREATE USER $PG_USER WITH PASSWORD '$PG_PASSWORD';
ALTER USER $PG_USER CREATEDB;
CREATE DATABASE thingsboard;
GRANT ALL PRIVILEGES ON DATABASE thingsboard TO $PG_USER;
EOF

# 确保用户对public模式有权限
sudo -u postgres psql -d thingsboard <<EOF
GRANT ALL ON SCHEMA public TO $PG_USER;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $PG_USER;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $PG_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $PG_USER;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUences TO $PG_USER;
EOF
;;
esac

# 设置主机和端口为本地值
PG_HOST="localhost"
PG_PORT="5432"
}

install_redis() {
case $OS_NAME in
ubuntu)
sudo apt install -y redis-server
;;
centos|rhel|alinux)
if [ $OS_VERSION -eq 7 ]; then
sudo yum install -y redis --nogpgcheck
else
sudo dnf install -y redis --nogpgcheck
fi
;;
esac

# 获取Redis配置
local redis_password=$(get_config 'redis_password')
local redis_conf=""

# 确定配置文件路径
case $OS_NAME in
ubuntu)
redis_conf="/etc/redis/redis.conf"
;;
centos|rhel|alinux)
redis_conf="/etc/redis.conf"
;;
esac

# 配置密码(如果设置了)
if [ -n "$redis_password" ]; then
echo "设置Redis密码..."
sudo sed -i "s/^# requirepass .*/requirepass $redis_password/" "$redis_conf"
sudo sed -i "s/^requirepass .*/requirepass $redis_password/" "$redis_conf"
fi

# 启动服务
case $OS_NAME in
ubuntu)
sudo systemctl restart redis-server
sudo systemctl enable redis-server
;;
centos|rhel|alinux)
sudo systemctl restart redis
sudo systemctl enable redis
;;
esac
}


# 安装 Nginx
install_nginx() {
case $OS_NAME in
ubuntu)
sudo apt install -y nginx
;;
centos|rhel|alinux)
if [ $OS_VERSION -eq 7 ]; then
sudo yum install -y epel-release --nogpgcheck
sudo yum install -y nginx --nogpgcheck
else
sudo yum install -y nginx --nogpgcheck
fi
;;
esac
sudo systemctl enable --now nginx
}

# 安装 ThingsBoard - 添加目录验证
install_thingsboard() {
case $OS_NAME in
ubuntu)
sudo apt install -y ./rpm/thingsboard-4.0.1.deb

# 确保正确的安装目录结构
if [ ! -d "/usr/share/thingsboard" ]; then
echo "错误:ThingsBoard 未正确安装到 /usr/share/thingsboard"
exit 1
fi
;;
centos|rhel|alinux)
sudo yum install -y rpm/thingsboard-4.0.1.rpm --nogpgcheck

# 确保正确的安装目录结构
if [ ! -d "/usr/share/thingsboard" ]; then
echo "错误:ThingsBoard 未正确安装到 /usr/share/thingsboard"
exit 1
fi
;;
esac

}

# 配置ThingsBoard数据库连接
configure_thingsboard() {
local config_file="/etc/thingsboard/conf/thingsboard.conf"
local pg_user=$(get_config 'postgresql_user')
local pg_password=$(get_config 'postgresql_password')

# 检查配置文件是否存在
if [ ! -f "$config_file" ]; then
echo "警告:ThingsBoard配置文件 $config_file 不存在"
return
fi

# 检查配置是否已存在
if grep -q "SPRING_DATASOURCE_URL" "$config_file"; then
echo "数据库配置已存在,跳过配置"
return
fi

# 添加数据库配置
echo "# DB Configuration" | sudo tee -a "$config_file" > /dev/null
echo "export DATABASE_TS_TYPE=sql" | sudo tee -a "$config_file" > /dev/null
echo "export SPRING_DATASOURCE_URL=jdbc:postgresql://${PG_HOST}:${PG_PORT}/thingsboard" | sudo tee -a "$config_file" > /dev/null
echo "export SPRING_DATASOURCE_USERNAME=$pg_user" | sudo tee -a "$config_file" > /dev/null
echo "export SPRING_DATASOURCE_PASSWORD=$pg_password" | sudo tee -a "$config_file" > /dev/null

echo "已配置ThingsBoard使用PostgreSQL数据库 (${PG_HOST}:${PG_PORT})"
}

# 配置ThingsBoard内存设置 - 使用MB单位
configure_thingsboard_memory() {
local config_file="/etc/thingsboard/conf/thingsboard.conf"

# 检查配置文件是否存在
if [ ! -f "$config_file" ]; then
echo "警告:ThingsBoard配置文件 $config_file 不存在"
return
fi

# 检测系统内存(MB)
local mem_total
mem_total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
mem_total=$((mem_total / 1024)) # 转换KB为MB

if [ -z "$mem_total" ]; then
echo "错误:无法检测系统内存"
return
fi

if [ "$mem_total" -le 4096 ]; then
echo "系统内存为 ${mem_total}MB <= 4GB,配置ThingsBoard使用2048MB内存"

# 检查是否已配置
if ! grep -q "Xms2048M" "$config_file"; then
echo "# Update ThingsBoard memory usage for low-memory systems" | sudo tee -a "$config_file"
echo "export JAVA_OPTS=\"\$JAVA_OPTS -Xms2048M -Xmx2048M\"" | sudo tee -a "$config_file"
else
echo "内存配置已存在,跳过"
fi
else
echo "系统内存为 ${mem_total}MB > 4GB,使用默认内存配置"
fi
}

# 初始化ThingsBoard数据库
init_thingsboard() {
echo "初始化ThingsBoard数据库..."
local pg_user=$(get_config 'postgresql_user')
local pg_password=$(get_config 'postgresql_password')
local pg_host=$(get_config 'postgresql_host')
local pg_port=$(get_config 'postgresql_port')

# 确保psql命令可用
if ! command -v psql &> /dev/null; then
echo "安装PostgreSQL客户端..."
if [ "$OS_NAME" = "ubuntu" ]; then
install_package "postgresql-client"
else
install_package "postgresql"
fi
fi

# 创建索引并清理数据
PGPASSWORD="$pg_password" psql \
-h "$pg_host" \
-p "$pg_port" \
-U "$pg_user" \
-d thingsboard \
-c "
CREATE INDEX IF NOT EXISTS idx_device_label
ON device (tenant_id, label);

DELETE FROM device;
DELETE FROM device_credentials;
DELETE FROM customer;
"

if [ $? -eq 0 ]; then
echo "数据库初始化成功"
else
echo "警告:数据库初始化失败"
fi
}

# 执行ThingsBoard安装脚本并启动服务 - 添加权限验证
install_and_start_thingsboard() {
# 设置端口
local port_thingsboard=$(get_config 'port_thingsboard_port')

# 检查内存状态
local mem_total=$(free -m | awk '/^Mem:/{print $2}')

echo "执行ThingsBoard安装脚本..."

# 确保安装目录有正确权限
sudo chown -R thingsboard:thingsboard /usr/share/thingsboard
sudo chmod 755 /usr/share/thingsboard

# 确保在正确的目录执行
(cd /usr/share/thingsboard && sudo bin/install/install.sh --loadDemo)

# 配置防火墙(仅当firewall-cmd存在时)
if command -v firewall-cmd &> /dev/null; then
echo "配置防火墙..."
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
else
echo "未找到firewall-cmd,跳过防火墙配置"
fi

# 扩大请求体限制
{
echo "export HTTP_BIND_PORT=$port_thingsboard"
echo "export HTTP_MAX_PAYLOAD_SIZE_LIMIT_CONFIGURATION=\"/api/image*/**=52428800;/api/resource/**=52428800;/api/**=524288000\""
echo "export SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=512MB"
echo "export SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=512MB"
echo "export HTTP_TRANSPORT_MAX_PAYLOAD_SIZE_LIMIT_CONFIGURATION=\"/api/v1/*/rpc/**=655360;/api/v1/**=524288000;/api/**=524288000\""
echo "export NETTY_MAX_PAYLOAD_SIZE=524288000"
} | sudo tee -a /etc/bashrc > /dev/null

source /etc/bashrc

echo "启动ThingsBoard服务..."
# 使用systemctl如果可用,否则使用service
if command -v systemctl &> /dev/null; then
sudo systemctl enable --now thingsboard
# 添加服务状态检查
sleep 30
echo "检查ThingsBoard服务状态..."
sudo systemctl status thingsboard --no-pager

# 如果服务失败,查看日志
if ! systemctl is-active --quiet thingsboard; then
echo "ThingsBoard服务启动失败,查看日志..."
sudo tail -n 100 /var/log/thingsboard/thingsboard.log
echo "尝试强行执行jar..."
nohup /bin/bash /usr/share/thingsboard/bin/thingsboard.jar >/dev/null 2>&1 &
fi
else
# 回退到service命令
sudo service thingsboard start
fi

# 初始化数据库
init_thingsboard
}

# 配置Nginx
configure_nginx() {
echo "备份默认Nginx配置..."

# 备份主配置文件
local nginx_conf="/etc/nginx/nginx.conf"
if [ -f "$nginx_conf" ]; then
sudo mv "$nginx_conf" "${nginx_conf}_bak"
echo "已备份 $nginx_conf${nginx_conf}_bak"
fi

# 备份默认站点配置
local default_conf=""
case $OS_NAME in
ubuntu)
default_conf="/etc/nginx/sites-enabled/default"
;;
centos|rhel|alinux)
default_conf="/etc/nginx/conf.d/default.conf"
if [ ! -f "$default_conf" ]; then
default_conf="/etc/nginx/nginx.conf.default"
fi
;;
esac

if [ -f "$default_conf" ]; then
sudo mv "$default_conf" "${default_conf}_bak"
echo "已备份 $default_conf${default_conf}_bak"
fi

# 获取前端基础目录
local basedir=$(get_config 'frontend_basedir')
if [ -z "$basedir" ]; then
echo "警告:前端基础目录未配置,跳过Nginx配置"
return
fi

# 创建基础目录
sudo mkdir -p "$basedir"

# 复制前端资源并替换URL
local iot_gateway_url=$(get_config 'frontend_iot_gateway_url')
local xxx_url=$(get_config 'frontend_xxx_url')

# 复制iot_blockly_frontend
local src_dir1="$SCRIPT_DIR/iot_gateway/iot_blockly_frontend"
local dest_dir1="$basedir/iot_blockly_frontend"
if [ -d "$src_dir1" ]; then
sudo cp -r "$src_dir1" "$basedir/"
# 替换URL
sudo find "$dest_dir1" -type f -exec sed -i "s|IOT_GATEWAY_URL|${iot_gateway_url}|g" {} \;
else
echo "警告:前端资源目录 $src_dir1 不存在"
fi

# 复制iot_xxx_frontend
local src_dir2="$SCRIPT_DIR/ruoyi-admin/iot_xxx_frontend"
local dest_dir2="$basedir/iot_xxx_frontend"
if [ -d "$src_dir2" ]; then
sudo cp -r "$src_dir2" "$basedir/"
# 替换URL
sudo find "$dest_dir2" -type f -exec sed -i "s|xxx_URL|${xxx_url}|g" {} \;
else
echo "警告:前端资源目录 $src_dir2 不存在"
fi

# 创建Nginx配置文件目录
sudo mkdir -p /etc/nginx/conf.d

# 确定Nginx运行时使用的用户
local nginx_user
if [ "$OS_NAME" = "ubuntu" ]; then
nginx_user="www-data" # Ubuntu默认使用www-data
else
nginx_user="nginx" # CentOS使用nginx
fi

# 创建主配置文件(总是覆盖)
echo "创建新的Nginx主配置..."
sudo tee /etc/nginx/nginx.conf > /dev/null <<EOF
user $nginx_user; # 动态设置用户
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
include /etc/nginx/conf.d/*.conf;
}
EOF

# 创建Nginx配置文件
local tb_conf="/etc/nginx/conf.d/tb.conf"
local xxx_conf="/etc/nginx/conf.d/xxx.conf"

# 获取配置参数
local thingsboard_port=$(get_config 'port_thingsboard_port')
local iot_gateway_port=$(get_config 'port_iot_gateway_port')
local xxx_backend_port=$(get_config 'port_xxx_backend_port')
local tb_ssl_cert=$(get_config 'nginx_thingsboard_ssl_certificate')
local tb_ssl_key=$(get_config 'nginx_thingsboard_ssl_certificate_key')
local xxx_ssl_cert=$(get_config 'nginx_xxx_ssl_certificate')
local xxx_ssl_key=$(get_config 'nginx_xxx_ssl_certificate_key')

# 创建ThingsBoard配置
sudo tee "$tb_conf" > /dev/null <<EOF
server {
listen 80;
server_name _;
$([ -n "$tb_ssl_cert" ] && echo "return 301 https://\$host:9443\$request_uri;")
}

$([ -n "$tb_ssl_cert" ] && echo "
server {
listen 9443 ssl;
server_name _;

ssl_certificate $tb_ssl_cert;
ssl_certificate_key $tb_ssl_key;

client_max_body_size 1024M;

location / {
proxy_pass http://localhost:$thingsboard_port;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;

# WebSocket 关键配置
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
")
EOF

# 创建xxx配置
sudo tee "$xxx_conf" > /dev/null <<EOF
$([ -n "$xxx_ssl_cert" ] && echo "
server {
listen 80;
server_name _;
return 301 https://\$host\$request_uri;
}
")

server {
listen $([ -n "$xxx_ssl_cert" ] && echo "443 ssl" || echo "80");
server_name _;

$([ -n "$xxx_ssl_cert" ] && echo "
ssl_certificate $xxx_ssl_cert;
ssl_certificate_key $xxx_ssl_key;")

# 精确匹配 /block
location = /block {
rewrite ^/block/(.*)$ /\$1 break;
root $basedir/iot_blockly_frontend;
index index.html;
try_files \$uri \$uri/ /index.html;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}

# 匹配 /block/ 下的所有路径
location /block/ {
rewrite ^/block/(.*)$ /\$1 break;
root $basedir/iot_blockly_frontend;
index index.html;
try_files \$uri \$uri/ /index.html;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}

location / {
root $basedir/iot_xxx_frontend;
index index.html;
try_files \$uri \$uri/ /index.html;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}

# 新增的特定路由,需要放在通用/gateway路由之前
location /gateway/exec {
rewrite ^/gateway/exec/(.*)$ /exec/\$1 break;
proxy_pass http://localhost:$xxx_backend_port/;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}

location /gateway {
rewrite ^/gateway/(.*)$ /\$1 break;
proxy_pass http://localhost:$iot_gateway_port;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}

location /prod-api {
rewrite ^/prod-api/(.*)$ /\$1 break;
proxy_pass http://localhost:$xxx_backend_port;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF

# 测试并重启Nginx
echo "测试Nginx配置..."
sudo nginx -t && sudo systemctl restart nginx
if [ $? -eq 0 ]; then
echo "Nginx 配置应用成功"
else
echo "错误:Nginx 配置测试失败,请检查日志"
exit 1
fi
}

# 主函数
main() {
detect_os
echo "检测到操作系统: $OS_NAME $OS_VERSION"

# 安装基础
install_base

# 安装 Java
if [ "$(get_config 'common_install_java')" = "yes" ]; then
# 先检查 java 命令是否存在
if ! command -v java &> /dev/null; then
echo "Java 未安装,开始安装..."
install_java
else
# 如果 java 命令存在,再检查版本
if ! java -version 2>&1 | grep -q "17"; then
echo "已安装的 Java 版本不是 17,开始安装 JDK 17..."
install_java
else
echo "JDK 17 已安装"
fi
fi

# 验证安装
if command -v java &> /dev/null; then
echo "Java 安装验证:"
java -version
else
echo "错误:Java 安装后仍然不可用"
exit 1
fi
fi

# 处理 MySQL
if [ "$(get_config 'mysql_install')" = "yes" ]; then
host=$(get_config 'mysql_host')
port=$(get_config 'mysql_port')
user=$(get_config 'mysql_user')
password=$(get_config 'mysql_password')

if check_db_connection "mysql" $host $port $user $password; then
echo "MySQL 连接成功,跳过安装"
else
echo "MySQL 连接失败,开始安装..."
install_mysql
echo "MySQL 已自动配置用户:$DB_USER"
fi

# 新增:导入 xxx.sql 到 MySQL
echo "处理 xxx 数据库导入..."
import_xxx_sql $host $port $user $password "$SQL_FILE"

# 新增:更新 sys_menu 表
thingsboard_url=$(get_config 'frontend_thingsboard_url')
update_sys_menu $host $port $user $password "$thingsboard_url"
fi

# 安装 Nginx
if [ "$(get_config 'common_install_nginx')" = "yes" ]; then
if ! command -v nginx &> /dev/null; then
install_nginx
nginx -v
else
echo "Nginx 已安装"
fi

# 配置Nginx
configure_nginx
fi

# 处理 PostgreSQL - 特别处理CentOS 7的版本问题
if [ "$(get_config 'postgresql_install')" = "yes" ]; then
host=$(get_config 'postgresql_host')
port=$(get_config 'postgresql_port')
user=$(get_config 'postgresql_user')
password=$(get_config 'postgresql_password')

if check_db_connection "postgresql" $host $port $user $password; then
echo "PostgreSQL 连接成功"

# 确保thingsboard数据库存在
ensure_postgresql_db $host $port $user $password "thingsboard"

# 使用配置的主机和端口
PG_HOST=$host
PG_PORT=$port

# 检查PostgreSQL版本
PG_VERSION=$(PGPASSWORD="$password" psql -h $host -p $port -U $user -d postgres -tAc "SHOW server_version_num")
if [ "$PG_VERSION" -lt 110000 ]; then
echo "警告:当前PostgreSQL版本($PG_VERSION)低于11.0,建议升级到11+版本"
fi
else
echo "PostgreSQL 连接失败,开始安装..."
install_postgresql
echo "PostgreSQL 已自动配置用户:$PG_USER"
echo "已创建数据库: thingsboard"

# 使用本地安装的主机和端口
PG_HOST="localhost"
PG_PORT="5432"

# 验证PostgreSQL版本
sudo -u postgres psql -c "SHOW server_version"
fi
fi

# 新增:安装Redis
if [ "$(get_config 'redis_install')" = "yes" ]; then
# 检查Redis是否已安装
if command -v redis-server &> /dev/null; then
echo "Redis 已安装"
else
echo "开始安装Redis..."
install_redis
echo "Redis 已安装并启动"
fi
fi

# 安装 thingsboard
if [ "$(get_config 'common_install_thingsboard')" = "yes" ]; then
install_thingsboard
echo "ThingsBoard 已安装"

# 配置数据库连接
configure_thingsboard

# 配置内存设置
configure_thingsboard_memory

# 等待数据库可用
wait_for_db "postgresql" $PG_HOST $PG_PORT $PG_USER $PG_PASSWORD

# 执行安装脚本并启动服务
install_and_start_thingsboard
fi

# 显示部署信息
echo -e "\n\033[32m部署完成!\033[0m"

}

# 执行主函数
main

Docker Composer

需要改造代码,通过读取环境变量来动态配置

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
services:
mysql:
image: ${MYSQL_IMAGE:-mysql:8.0}
container_name: xxx_mysql
ports:
- "${MYSQL_PORT:-3306}:3306"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-MyApp@1234}
MYSQL_USER: ${MYSQL_USER:-myapp}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-MyApp@1234}
MYSQL_DATABASE: xxx
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/initdb.d:/docker-entrypoint-initdb.d
restart: always
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u${MYSQL_USER}", "-p${MYSQL_PASSWORD}"]
interval: 30s
timeout: 30s
retries: 10
start_period: 180s

postgres:
image: ${POSTGRES_IMAGE:-postgres:16}
container_name: xxx_postgres
ports:
- "${POSTGRES_PORT:-5432}:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER:-myapp}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-MyApp@5678}
POSTGRES_DB: thingsboard
volumes:
- ./postgres/data:/var/lib/postgresql/data
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d thingsboard"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s

redis:
image: ${REDIS_IMAGE:-redis:7}
container_name: xxx_redis
ports:
- "${REDIS_PORT:-6379}:6379"
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
command: >
bash -c "if [ -z \"$$REDIS_PASSWORD\" ]; then
redis-server;
else
redis-server --requirepass $$REDIS_PASSWORD;
fi"
volumes:
- ./redis/data:/data
restart: always
healthcheck:
test: >
bash -c "if [ -z \"$$REDIS_PASSWORD\" ]; then
redis-cli ping;
else
redis-cli -a $$REDIS_PASSWORD ping;
fi"
interval: 10s
timeout: 5s
retries: 10
start_period: 30s

thingsboard:
image: ${THINGSBOARD_IMAGE:-thingsboard/tb-node:4.0.1.1}
container_name: xxx_thingsboard
ports:
- "${THINGSBOARD_PORT}:8080"
- "7070:7070"
- "1883:1883"
- "8883:8883"
- "5683-5688:5683-5688/udp"
environment:
DATABASE_TS_TYPE: sql
SPRING_DATASOURCE_URL: jdbc:postgresql://${TB_POSTGRESQL_HOST}:${TB_POSTGRESQL_PORT}/thingsboard
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
HTTP_BIND_PORT: 8080
# JAVA_OPTS: "-Xmx1024m -Xms1024m"
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "grep ':075B' /proc/net/tcp6 || exit 1"]
interval: 5s
timeout: 3s
start_period: 300s
retries: 120

iot-gateway:
image: ${IOT_GATEWAY_IMAGE}
container_name: xxx_iot_gateway
ports:
- "${IOT_GATEWAY_PORT}:8081"
environment:
IOT_GATEWAY_PORT: 8081
xxx_URL: ${xxx_URL}
THINGSBOARD_URL: ${THINGSBOARD_URL}
TB_POSTGRESQL_URL: ${TB_POSTGRESQL_HOST}
TB_POSTGRESQL_PORT: ${TB_POSTGRESQL_PORT}
TB_POSTGRESQL_USERNAME: ${POSTGRES_USER}
TB_POSTGRESQL_PASSWORD: ${POSTGRES_PASSWORD}
depends_on:
thingsboard:
condition: service_healthy
restart: always
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8081/healthcheck/check || exit 1"]
interval: 10s
timeout: 60s
start_period: 600s
retries: 99999

xxx-admin:
image: ${xxx_ADMIN_IMAGE}
container_name: xxx_admin
ports:
- "${xxx_BACKEND_PORT}:8001"
environment:
xxx_BACKEND_PORT: 8001
IOT_GATEWAY_URL: ${IOT_GATEWAY_URL}
xxx_MYSQL_HOST: ${MYSQL_HOST}
xxx_MYSQL_PORT: ${MYSQL_PORT}
xxx_MYSQL_USERNAME: ${MYSQL_USER}
xxx_MYSQL_PASSWORD: ${MYSQL_PASSWORD}
xxx_REDIS_HOST: ${REDIS_HOST}
xxx_REDIS_PORT: ${REDIS_PORT}
xxx_REDIS_DATABASE: ${REDIS_DATABASE}
xxx_REDIS_PASSWORD: ${REDIS_PASSWORD}
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8001/healthcheck/check || exit 1"]
interval: 10s
timeout: 60s
start_period: 600s
retries: 99999

nginx:
image: ${NGINX_IMAGE}
container_name: xxx_nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/webroot:/home/webroot
depends_on:
thingsboard:
condition: service_healthy
iot-gateway:
condition: service_healthy
xxx-admin:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
interval: 30s
timeout: 10s
retries: 10
start_period: 60s