瀏覽代碼

feat(deploy): 容器网络架构改造 + 配置纳入版本控制

网络架构:
- iot-platform: host -> bridge (新增 -p 8887:8887 端口映射)
- taos-explorer: bridge (新增 /mnt/taos-explorer-data 数据持久化)
- tdengine-operator: 保持 host 网络

配置更新:
- TDengine URL: 127.0.0.1 -> 172.21.185.173 (宿主机内网 IP)
- Redis host: localhost -> ${REDIS_HOST:localhost} 环境变量
- taos.cfg fqdn: 127.0.0.1 -> 172.21.185.173
- explorer.toml cluster: localhost -> 172.21.185.173

部署脚本:
- REMOTE_DIR: /opt/iot-platform -> /mnt/iot-platform
- 日志目录: /opt/iot-platform/logs -> /mnt/iot-platform/logs
- 去掉自动回滚逻辑,保留容器用于排查
- 新增 -p 8887:8887 端口映射

新增服务器配置文件到仓库:
- deploy/Dockerfile
- deploy/start-container.sh
- deploy/config/taos.cfg
- deploy/config/explorer.toml
- deploy/config/tdengine-explorer.conf
- .env (移除 .gitignore 忽略)
mqy20260511
humanleft 2 週之前
父節點
當前提交
a5b7e0823f

+ 24
- 0
.env 查看文件

@@ -0,0 +1,24 @@
1
+# IoT 平台环境变量配置
2
+# 启动前自动加载:./start.sh start
3
+# 或手动加载:source .env
4
+
5
+# MySQL 数据库(主从共用)
6
+MYSQL_USERNAME=root
7
+MYSQL_PASSWORD="Zhu059300()__"
8
+
9
+# Redis
10
+REDIS_PASSWORD=
11
+
12
+# MQTT Broker
13
+MQTT_USERNAME=NjniyrEO
14
+MQTT_PASSWORD=2b577892f4824d466dbc323a1ee4dfe1902c55bb
15
+
16
+# TDengine 时序数据库
17
+TDENGINE_USERNAME=root
18
+TDENGINE_PASSWORD=taosdata
19
+
20
+# Druid 监控(生产环境建议设为 false 关闭)
21
+DRUID_STAT_ENABLED=true
22
+DRUID_USERNAME=ruoyi
23
+DRUID_PASSWORD=123456
24
+REDIS_HOST=172.21.185.173

+ 2
- 1
.gitignore 查看文件

@@ -50,5 +50,6 @@ nbdist/
50 50
 .claude/
51 51
 
52 52
 # Environment variables
53
-.env
53
+# .env is now tracked in git per user request
54
+# .env
54 55
 !.env.example

+ 24
- 0
deploy/.env 查看文件

@@ -0,0 +1,24 @@
1
+# IoT 平台环境变量配置
2
+# 启动前自动加载:./start.sh start
3
+# 或手动加载:source .env
4
+
5
+# MySQL 数据库(主从共用)
6
+MYSQL_USERNAME=root
7
+MYSQL_PASSWORD="Zhu059300()__"
8
+
9
+# Redis
10
+REDIS_PASSWORD=
11
+
12
+# MQTT Broker
13
+MQTT_USERNAME=NjniyrEO
14
+MQTT_PASSWORD=2b577892f4824d466dbc323a1ee4dfe1902c55bb
15
+
16
+# TDengine 时序数据库
17
+TDENGINE_USERNAME=root
18
+TDENGINE_PASSWORD=taosdata
19
+
20
+# Druid 监控(生产环境建议设为 false 关闭)
21
+DRUID_STAT_ENABLED=true
22
+DRUID_USERNAME=ruoyi
23
+DRUID_PASSWORD=123456
24
+REDIS_HOST=172.21.185.173

+ 15
- 0
deploy/Dockerfile 查看文件

@@ -0,0 +1,15 @@
1
+FROM tdengine/tdengine:3.3.6.13
2
+
3
+ENV DEBIAN_FRONTEND=noninteractive
4
+RUN apt-get update && apt-get install -y --no-install-recommends openjdk-8-jre-headless && rm -rf /var/lib/apt/lists/*
5
+
6
+WORKDIR /opt/iot-platform
7
+
8
+COPY iot-platform.jar .
9
+COPY .env .
10
+COPY start-container.sh .
11
+RUN chmod +x start-container.sh
12
+
13
+EXPOSE 8887
14
+
15
+ENTRYPOINT ["./start-container.sh"]

+ 117
- 0
deploy/config/explorer.toml 查看文件

@@ -0,0 +1,117 @@
1
+# This is a automacically generated configuration file for Explorer in [TOML](https://toml.io/) format.
2
+#
3
+# Here is a full list of available options.
4
+
5
+# Explorer server port to listen on.
6
+# Default is 6060.
7
+#
8
+port = 6060
9
+
10
+# IPv4 listen address.
11
+# Default is 0.0.0.0
12
+addr = "0.0.0.0"
13
+
14
+# IPv6 listen address.
15
+
16
+# ipv6 = "::1"
17
+
18
+# explorer server instance id
19
+# 
20
+# The instanceId of each instance is unique on the host
21
+# instanceId = 1
22
+
23
+# Explorer server log level.
24
+# Default is "info"
25
+# 
26
+# Deprecated: use log.level instead
27
+log_level = "info"
28
+
29
+# All data files are stored in this directory
30
+# data_dir = "/var/lib/taos/explorer" # Default for Linux
31
+# data_dir = "C:\\TDengine\\data\\explorer" # Default for Windows
32
+
33
+# REST API endpoint to connect to the cluster.
34
+# This configuration is also the target for data migration tasks.
35
+# 
36
+# Default is "http://localhost:6041" - the default endpoint for REST API.
37
+#
38
+cluster = "http://172.21.185.173:6041"
39
+
40
+# native endpoint to connect to the cluster.
41
+# Default is disabled. To enable it, set it to the native API URL like "taos://localhost:6030" and uncomment it.
42
+# If you enable it, you will get more performance for data migration tasks.
43
+# If modify this config item, you must relogin to clear the cache in browser local storage.
44
+#
45
+# cluster_native = "taos://localhost:6030"
46
+
47
+# API endpoint for data replication/backup/data sources. No default option.
48
+#   Set it to API URL like "http://localhost:6050".
49
+#
50
+x_api = "http://localhost:6050"
51
+
52
+# Please set it to same as the "grpc" parameter used by taosX Service; 
53
+# If "grpc" parameter is not set explicitly in taosX service, please set it to the default grpc address of taosX
54
+grpc = "http://localhost:6055"
55
+
56
+# CORS configuration switch, it allows cross-origin access
57
+cors = true
58
+
59
+# cloud open api.
60
+# cloud_open_api = "https://pre.ali.cloud.taosdata.com/openapi"
61
+
62
+# Enable ssl
63
+# If the following two files exist, enable ssl protocol
64
+#
65
+[ssl]
66
+
67
+# SSL certificate
68
+#
69
+# certificate = "/path/to/ca.file" # on linux/macOS
70
+# certificate = "C:\\path\\to\\ca.file" # on windows
71
+
72
+# SSL certificate key
73
+#
74
+# certificate_key = "/path/to/key.file" # on linux/macOS
75
+# certificate_key = "C:\\path\\to\\key.file" # on windows
76
+
77
+# log configuration
78
+[log]
79
+# All log files are stored in this directory
80
+# 
81
+# path = "/var/log/taos" # on linux/macOS
82
+# path = "C:\\TDengine\\log" # on windows
83
+
84
+# log filter level
85
+#
86
+# level = "info"
87
+
88
+# Compress archived log files or not
89
+# 
90
+# compress = false
91
+
92
+# The number of log files retained by the current explorer server instance in the `path` directory
93
+# 
94
+# rotationCount = 30
95
+
96
+# Rotate when the log file reaches this size
97
+# 
98
+# rotationSize = "1GB"
99
+
100
+# Log downgrade when the remaining disk space reaches this size, only logging `ERROR` level logs
101
+# 
102
+# reservedDiskSize = "1GB"
103
+
104
+# The number of days log files are retained
105
+#
106
+# keepDays = 30
107
+
108
+# integrated with Grafana
109
+[grafana]
110
+# The token of the Grafana server, which is used to access the Grafana server.
111
+#token = ""
112
+
113
+# The URL of the Grafana dashboard, which is used to display the monitoring data of the TDengine cluster.
114
+# You can configure multiple Grafana dashboards.
115
+[grafana.dashboards]
116
+#TDengine3 = "http://localhost:3000/d/000000001/tdengine3"
117
+#taosX = "http://localhost:3000/d/000000002/taosx"

+ 2
- 0
deploy/config/taos.cfg 查看文件

@@ -0,0 +1,2 @@
1
+fqdn 172.21.185.173
2
+serverPort 6031

+ 16
- 0
deploy/config/tdengine-explorer.conf 查看文件

@@ -0,0 +1,16 @@
1
+server {
2
+    listen 172.21.185.173:6060;
3
+    server_name 47.104.204.180;
4
+
5
+    location / {
6
+        proxy_pass http://127.0.0.1:6060;
7
+        proxy_set_header Host $host;
8
+        proxy_set_header X-Real-IP $remote_addr;
9
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
10
+        proxy_read_timeout 300s;
11
+
12
+        proxy_http_version 1.1;
13
+        proxy_set_header Upgrade $http_upgrade;
14
+        proxy_set_header Connection "upgrade";
15
+    }
16
+}

+ 10
- 38
deploy/deploy.sh 查看文件

@@ -15,7 +15,7 @@ set -e
15 15
 # 配置
16 16
 SERVER_HOST="${SERVER_HOST:-47.104.204.180}"
17 17
 SERVER_USER="${SERVER_USER:-root}"
18
-REMOTE_DIR="${REMOTE_DIR:-/opt/iot-platform}"
18
+REMOTE_DIR="${REMOTE_DIR:-/mnt/iot-platform}"
19 19
 APP_NAME="iot-platform"
20 20
 LOCAL_JAR=""
21 21
 DO_BUILD=false
@@ -133,9 +133,10 @@ echo -e "${YELLOW}[5/6] 启动容器...${NC}"
133 133
 ssh "${SERVER_USER}@${SERVER_HOST}" "
134 134
     podman run -d \
135 135
         --name ${APP_NAME} \
136
-        --network host \
136
+        --network bridge \
137 137
         --restart unless-stopped \
138
-        -v ${REMOTE_DIR}/logs:/opt/iot-platform/logs \
138
+        -p 8887:8887 \
139
+        -v /mnt/iot-platform/logs:/opt/iot-platform/logs \
139 140
         localhost/${APP_NAME}:latest >/dev/null 2>&1
140 141
 "
141 142
 sleep 5
@@ -163,40 +164,11 @@ if ssh "${SERVER_USER}@${SERVER_HOST}" "bash ${REMOTE_DIR}/bin/health-check.sh l
163 164
     exit 0
164 165
 else
165 166
     echo -e "${RED}[6/6] 健康检查失败!${NC}"
166
-
167
-    if [ "$NO_ROLLBACK" = true ]; then
168
-        echo -e "${YELLOW}[no-rollback] 已启用不回滚模式,保留新版本用于排查${NC}"
169
-        echo -e "${YELLOW}排查命令:${NC}"
170
-        echo "  ssh ${SERVER_USER}@${SERVER_HOST} 'podman logs -f ${APP_NAME}'"
171
-        echo "  ssh ${SERVER_USER}@${SERVER_HOST} 'podman ps | grep ${APP_NAME}'"
172
-        exit 1
173
-    fi
174
-
175
-    echo -e "${YELLOW}[rollback] 执行回滚...${NC}"
176
-    ssh "${SERVER_USER}@${SERVER_HOST}" "podman stop ${APP_NAME} >/dev/null 2>&1 && podman rm ${APP_NAME} >/dev/null 2>&1 || true"
177
-
178
-    if ssh "${SERVER_USER}@${SERVER_HOST}" "test -f ${REMOTE_DIR}/backup/${BACKUP_NAME}"; then
179
-        echo -e "${YELLOW}[rollback] 恢复旧版本...${NC}"
180
-        ssh "${SERVER_USER}@${SERVER_HOST}" "
181
-            cp ${REMOTE_DIR}/backup/${BACKUP_NAME} ${REMOTE_DIR}/${APP_NAME}.jar
182
-            cd ${REMOTE_DIR} && podman build -t ${APP_NAME}:latest . >/dev/null 2>&1
183
-            podman run -d \
184
-                --name ${APP_NAME} \
185
-                --network host \
186
-                --restart unless-stopped \
187
-                -v ${REMOTE_DIR}/logs:/opt/iot-platform/logs \
188
-                localhost/${APP_NAME}:latest >/dev/null 2>&1
189
-        "
190
-        sleep 5
191
-
192
-        if ssh "${SERVER_USER}@${SERVER_HOST}" "bash ${REMOTE_DIR}/bin/health-check.sh localhost 8887 60"; then
193
-            echo -e "${GREEN}[rollback] 回滚成功,旧版本已恢复${NC}"
194
-        else
195
-            echo -e "${RED}[rollback] 回滚后健康检查仍失败,请手动排查!${NC}"
196
-        fi
197
-    else
198
-        echo -e "${RED}[rollback] 无备份可回滚,请手动修复!${NC}"
199
-    fi
200
-
167
+    echo -e "${YELLOW}保留容器用于排查,不自动回滚${NC}"
168
+    echo ""
169
+    echo "排查命令:"
170
+    echo "  ssh ${SERVER_USER}@${SERVER_HOST} 'podman logs -f ${APP_NAME}'"
171
+    echo "  ssh ${SERVER_USER}@${SERVER_HOST} 'podman ps | grep ${APP_NAME}'"
172
+    echo "  ssh ${SERVER_USER}@${SERVER_HOST} 'curl -s http://localhost:8887/actuator/health'"
201 173
     exit 1
202 174
 fi

+ 7
- 0
deploy/start-container.sh 查看文件

@@ -0,0 +1,7 @@
1
+#!/bin/bash
2
+set -a
3
+source /opt/iot-platform/.env
4
+set +a
5
+
6
+cd /opt/iot-platform
7
+exec java -server -Duser.timezone=Asia/Shanghai -Dfile.encoding=UTF-8 -Xms1g -Xmx2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/iot-platform/logs/heapdump.hprof -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -jar iot-platform.jar --spring.profiles.include=online

+ 1
- 1
iot-platform/src/main/java/com/iot/platform/config/IotProperties.java 查看文件

@@ -115,7 +115,7 @@ public class IotProperties {
115 115
      * TDengine配置
116 116
      */
117 117
     public static class TDengine {
118
-        private String url = "jdbc:TAOS://127.0.0.1:6031/";
118
+        private String url = "jdbc:TAOS://172.21.185.173:6031/";
119 119
         private String username = "";
120 120
         private String password = "";
121 121
 

+ 2
- 2
iot-platform/src/main/resources/application.yml 查看文件

@@ -29,7 +29,7 @@ spring:
29 29
     restart:
30 30
       enabled: false
31 31
   redis:
32
-    host: localhost
32
+    host: ${REDIS_HOST:localhost}
33 33
     port: 6379
34 34
     database: 0
35 35
     password: ${REDIS_PASSWORD:}
@@ -70,6 +70,6 @@ iot:
70 70
     password: ${MQTT_PASSWORD:}
71 71
     charge-station-topic: ${MQTT_CHARGE_STATION_TOPIC:station/ChargeStation/device/+/post/json}
72 72
   tdengine:
73
-    url: jdbc:TAOS://127.0.0.1:6031/
73
+    url: jdbc:TAOS://172.21.185.173:6031/
74 74
     username: ${TDENGINE_USERNAME:}
75 75
     password: ${TDENGINE_PASSWORD:}

Loading…
取消
儲存