主题
配置文件说明
TopStack 配置参数统一保存在安装目录下的 config.yml
配置文件中。
全局配置
yaml
version: "3"
instanceID: standalone
standalone: true
# 是否启用多项目管理
enableMultiProject: false
# 是否启用项目子用户
enableProjectUsers: true
# 是否支持项目域名
supportDomain: false
# 默认用户的应用模块
apps:
- iot # 设备互联
- alert # 告警中心
- visual # 可视化
- logic # 逻辑开发
- asset # 资产维护管理
rpc:
client:
addr: localhost:6000
server:
addr: :6000
iot:
processSize: 1000
logic:
serviceHistoryLimit: -1
checkPointChange: false
log: false
alert:
# 活动告警判定模式:1 未确认的告警 0 未解除的告警
activeMode: 0
Web 服务配置
yaml
web:
debug: false
port: 8000
tls: false # 是否启用 https
sessionTimeout: 60 # 用户会话超时时间 60 分钟
staticPath: custom
enableMultiSession: true
clientMaxBodySize: 50 # 上传文件最大尺寸,单位MB
如果启用了 https,软件启动时会自动创建自签名证书,如果用户希望使用正式证书,可以替换以下两个文件:
- 证书文件(PEM格式):tls/cert.cer
- 私钥文件(PEM格式):tls/cert.key
如果使用 Nginx 代替请不要开启 https,Nginx 代理需要支持 WebSocket,参考配置如下:
nginx
location / {
proxy_pass http://localhost:8000/; # 原软件 Web 访问地址
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 100m; # 允许最大文件上传大小
}
Nats 配置
yaml
# nats 客户端配置
nats:
addr: nats://127.0.0.1:4222
username:
passowrd:
# 内置 nats server
natsServer:
enable: true # 是否启用
confPath: ./nats.conf # nats server 配置文件
# nats 转发,用于平台之间转发数据
natsTransport:
projectID: iotopo # 转发的项目标识
addr: nats://10.34.220.24:4222 # 目标平台 nats 地址
username:
passowrd:
token:
reconnectWait: 10 # 重连间隔(秒)
Redis 客户端
yaml
redis:
addr: 127.0.0.1:6379
# 集群模式地址
#addrs:
# - host1:6379
# - host2:6379
# - host3:6379
username:
password:
db: 0
关系型数据库
平台默认采用的是 SQLite 数据库,SQLite 数据文件保存在 db 目录下。
TIP
1万以上测点,建议修改为其它数据库类型。
数据库全局配置:
yaml
db:
showSQL: false # 是否在控制台打印 SQL 语句
databaseName: topstack
autoCreateAdmin: false
autoCreateDatabase: false # 是否自动创建数据库,如果没有创建数据库权限,请不要开启该选项
pool:
maxOpenConns: 10 # 最大连接数
maxIdleConns: 5 # 最大空闲连接数
connMaxLifetime: 60 # 连接的最大生命周期(分钟)
connMaxIdleTime: 30 # 连接的最大空闲时间(分钟)
databaseType: sqlite # 数据库类型:mysql sqlite postgres dm
sqlite:
databasePath: ./db
SQLite
yaml
db:
databaseType: sqlite
sqlite:
databasePath: ./db
PostgreSQL 或 KingBase
yaml
db:
databaseType: postgres
postgres:
schema: public
host: localhost
port: 5432
user: postgres
password: postgres
MySQL
yaml
db:
databaseType: mysql
mysql:
addr: localhost:3306
user: root
passwd: root
达梦数据库
yaml
db:
databaseType: dm
dm:
addr: 127.0.0.1:5236
user: SYSDBA
passwd: SYSDBA
时序数据库
时序数据库用于保存以下数据:
- 测点历史数据
- 统计指标数据
- 设备绩效指标数据
时序数据库默认使用的是 InfluxDB 数据库 V1.x,用户可修改环境变量配置切换为其它时序数据库。
InfluxDB 配置
yaml
tsdb:
type: InfluxDB
address: http://localhost:8086
username:
password:
# influxdb v1.x 时区设置
timezone: Local
IoTDB 配置
yaml
tsdb:
type: IoTDB
# 多个地址可以用“,”分隔
address: localhost:6667
username:
password:
poolMaxSize: 100 # 连接池最大连接数
poolConnTimeout: 60000 # 连接池连接超时,毫秒
getSessionTimeout: 60000 # 连接池会话超时,毫秒
# 时间精度,可选值:s(秒) ms(毫秒) us(微秒) ns(纳秒)
# 需要与 iotdb 数据库配置项 timestamp_precision 保持一致
precision: ms
TDEngine
yaml
tsdb:
type: TDEngine
address: http://h1.taos.com:6041
username: root
password: taosdata
OpenGemini
yaml
tsdb:
type: OpenGemini
address: localhost:8086 # 多个地址可以用“,”分隔
username:
password:
token:
timezone: Local # Local 表示系统默认时区
precision: ms # 时间精度,可选值:s(秒) ms(毫秒) us(微秒) ns(纳秒)
日志存储
yaml
logger:
fileLog: false # 是否将日志输出到文件
level: info # debug info warn error
# 日志存储引擎配置
storage:
type: InfluxDB
address: localhost:8086
username:
password:
token:
database: _iotopo_log
retention: 3 # 日志保存天数
系统报文日志和部分服务日志需要写入日志数据库,支持存储到 InfluxDB、OpenGemini、Elastic 数据库。
InfluxDB
yaml
# 日志存储配置 InfluxDB
logger:
storage:
type: InfluxDB # 日志数据库 InfluxDB OpenGemini Elastic
address: localhost:8086
username:
password:
database: _iotopo_log
retention: 3 # 日志保存天数
OpenGemini
yaml
# 日志存储配置 OpenGemini
logger:
storage:
type: OpenGemini
address: localhost:8086
username:
password:
token:
database: _iotopo_log
retention: 3 # 日志保存天数
Elastic
yaml
# 日志存储配置 Elastic
logger:
storage:
type: Elastic
address: http://localhost:9200
username:
password:
database: _iotopo_log
retention: 3 # 日志保存天数
对象存储
Topstack 默认未启用对象存储,所有组态图资源保存在本地的 storage 目录下。如果希望采用集群方式运行,请启用对象存储。
yaml
storage:
type: fs # 对象存储类型:fs obs minio oss
fs:
path: ./storage
minio:
endpoint:
accessKey:
secretKey:
ssl: false
bucketName: topstack # 存储桶名称
MQTT 服务
Topstack 提供内置了 MQTT Broker 服务,如果用户自己部署了其它 MQTT Broker 可以修改配置文件关闭内置的 MQTT Broker。
yaml
mqttServer:
enable: true # 是否启用内置的 mqtt server
port: 1883
# 是否启用持久化,确保服务器重启后能够恢复之前的会话状态
persist: false
# 是否启用 SSL
tls: false
# 服务器域名(用于生成自签名证书)
dnsNames:
- localhost
- mqtt.iotopo.com
# 服务器IP(用于生成自签名证书)
ipAddresses:
- 127.0.0.1
# 用户列表定义
users:
iotopo: # username
password: iotopo
myuser1:
password: myuser1_pass
myuser2:
password: myuser2_pass
disallow: true # 禁用该账号
# 如果客户端提供的 username 不在用户列表中,则按下列规则进行认证
auth:
# 禁止 192.168.1.100 访问
- remote: 192.168.1.100:*
allow: false
# 允许 192.168.1.101 访问
- remote: 192.168.1.101:*
allow: true
# 允许 192.168.1.102 访问,且需要指定的用户名和密码
- remote: 192.168.1.102:*
username: user1
password: user1_pass
allow: true
# 允许 127.0.0.1 访问,且不需要用户名密码
- remote: 127.0.0.1:*
allow: true
# 允许 localhost 访问,且不需要用户名密码
- remote: localhost:*
allow: true
启用 SSL
IMPORTANT
MQTT over SSL/TLS 是一种通过 SSL/TLS 加密传输 MQTT 消息的安全方法,用于在客户端和 MQTT 服务器之间传输数据,保证客户端和服务器之间传递的所有数据都是加密且安全的。
如果启用 SSL,需要将 tls 设置为 true。MQTT 服务目前支持的证书签名算法有 RSA 和 ECC。
启用 SSL 后,程序在首次启动时会自动生成默认的自签名证书,证书文件保存在 mqtt/certs/
目录下。
证书文件列表:
- 根证书:
ca.crt
。 - 服务端证书私钥:
server.key
。 - 服务端证书:
server.crt
。 - 客户端证书私钥:
client.key
。 - 客户端证书:
client.crt
。
如果不希望使用自动生成的证书,用户可以使用 openssl 自己生成证书。
- 在 Linux 操作系统中创建一个文件夹存放生成的证书。
shell
mkdir /home/rsa_certs
cd /home/rsa_certs
- 执行以下命令生成设备端和服务端的根证书文件
ca.crt
。
shell
openssl req \
-new \
-newkey rsa:2048 \
-days 365 \
-nodes \
-x509 \
-subj "/C=CN/O=Iotopo IOT/CN=IoT CA" \
-keyout ca.key \
-out ca.crt
根据根证书文件
ca.crt
,自定义服务端证书。(1)执行以下命令生成服务端密钥文件
server.key
。
shell
openssl genrsa -out server.key 2048
(2)执行命令touch openssl.cnf
新建文件openssl.cnf
。
(3)执行命令vi openssl.cnf
进入文件,填入以下内容后按Esc键,输入:wq
保存。
shell
[policy_match]
countryName = cn
stateOrProvinceName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
commonName = Server
[req_ext]
subjectAltName = @alt_names
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.mqtt.iotopo.com
DNS.2 = *.igw.iotopo.com
(4)执行以下命令生成服务端请求文件server.csr
。
shell
openssl req -new -key server.key -config openssl.cnf -out server.csr
(5)执行以下命令生成服务端证书文件server.crt
。
shell
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -extensions v3_req -extfile openssl.cnf
(6)执行以下命令验证服务端证书。
shell
openssl verify -CAfile ca.crt server.crt
- 根据根证书文件
ca.crt
,自定义客户端证书。
(1)执行以下命令生成客户端密钥文件client.key
。
shell
openssl genrsa -out client.key 2048
(2)执行以下命令生成客户端证书请求文件client.csr
。本示例设置CN为Client_123
。
shell
openssl req -new -key client.key -out client.csr -subj "/CN=Client_123"
(3)执行以下命令生成设备端证书文件client.crt
。
shell
openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
(4)执行以下命令验证设备端证书。
shell
openssl verify -CAfile ca.crt client.crt
邮件服务
用于通过邮箱找加密码,发送邮件通知等。
yaml
smtp:
host: smtp.feishu.cn
port: 465
user: youaccount@iotopo.com # 邮箱账号
password: xxxxxxxxx # 邮箱密码
name: 图扑物联 # 邮件签名
ssl: true # 是否启用 SSL
skipVerify: true # 是否跳过服务器端证书检查
短信服务
用于发送短信验证码,发送短信通知。
yaml
sms:
type: iotopo # 短信平台
appKey: xxxxxxxxxxxxxx
appSecret: xxxxxxxxxxxxxx
设备互联设置
yaml
iot:
dtuServer:
enable: true
# 服务端口
port: 9018
# 注册ID长度
idLength: 16