跳到主要内容

配置文件

提示

默认直接启动即可,无需配置即可正常使用

提示

dotnet应用可以在 启动指令中 添加urls参数,指定启动端口,也可配置 appsettings.json 文件

  "urls": "http://*:5000"

一、配置文件

ThingsGateway 默认使用 Sqlite 数据库,方便部署,也可以通过配置 Database.json 文件,修改数据库配置

其他日志配置等内容查看对应描述,按需修改

二、详细配置文件

1. AdminLog.json

{
"AdminLog": {
"OperateLogDaysAgo": 30 //操作日志保留天数
}
}

2. App.json

{
"$schema": "null",

"AllowedHosts": "*",

"Startway": "", // 启动方式:DOTNET: (直接启动) ;WindowsService:(windows服务) PM2, Systemctl等不需要配置。对应文件夹下的命令文件

"AppSettings": {
"InjectSpecificationDocument": false, // 是否开启Swagger
"ExternalAssemblies": [ "Plugins" ], // 插件目录

// nuget动态加载的程序集
"SupportPackageNamePrefixs": [
"ThingsGateway.Admin.Application",
"ThingsGateway.Admin.Razor",
"ThingsGateway.Common",
"ThingsGateway.AspNetCore",
"ThingsGateway.DB",
"ThingsGateway.Gateway.Application",
"ThingsGateway.Gateway.Razor",

"ThingsGateway.Foundation.Razor",
"ThingsGateway.Debug.Razor",
"ThingsGateway.Razor"
]
},

"DynamicApiControllerSettings": {
//"DefaultRoutePrefix": "api", // 默认路由前缀
"CamelCaseSeparator": "", // 驼峰命名分隔符
"SplitCamelCase": false, // 切割骆驼(驼峰)/帕斯卡命名
"LowercaseRoute": false, // 小写路由格式
"AsLowerCamelCase": true, // 小驼峰命名(首字母小写)
"KeepVerb": false, // 保留动作方法请求谓词
"KeepName": false // 保持原有名称不处理
},
"FriendlyExceptionSettings": {
"DefaultErrorMessage": "系统异常,请联系管理员",
"ThrowBah": true, // 是否将 Oops.Oh 默认抛出为业务异常
"LogError": true // 是否输出异常日志
},
"CorsAccessorSettings": {
"PolicyName": "ThingsGateway",
"WithExposedHeaders": [ "Content-Disposition", "X-Pagination", "access-token", "x-access-token" ], // 如果前端不代理且是axios请求
"SignalRSupport": true // 启用 SignalR 跨域支持
}
}

3. BootstrapBlazor.json

{


//BootstrapBlazor配置
"BootstrapBlazorOptions": {


"ToastPlacement": "TopCenter",
"ToastDelay": 3000,
"MessageDelay": 3000,
"SwalDelay": 3000,
"EnableErrorLogger": true,
"FallbackCulture": "zh-CN",
"SupportedCultures": [
"zh-CN",
"en-US"
],
"DefaultCultureInfo": "zh-CN", //修改默认语言
"TableSettings": {
"CheckboxColumnWidth": 36
},
"IgnoreLocalizerMissing": true,
"StepSettings": {
"Short": 1,
"Int": 1,
"Long": 1,
"Float": 0.1,
"Double": 0.01,
"Decimal": 0.01
}
}

}

4. Cache.json

{
"Cache": {
"CacheType": "Memory", // 可选:Memory 或 Redis

"MemoryCacheOptions": {
"Expire": 3600,
"Capacity": 100000,
"Period": 60
},

"RedisCacheOptions": {
"InstanceName": "ThingsGateway",
"Configuration": "server=127.0.0.1:6379;db=0;timeout=3000",
"Server": "127.0.0.1:6379",
"Db": 3,
"UserName": "",
"Password": "",
"Timeout": 3000,
"Prefix": "ThingsGateway:",
"Expire": 3600
}
}
}

5. ChannelThread.json

{
"ChannelThread": {
"CheckInterval": 1800000, //检查间隔
"MaxChannelCount": 50000, //最大通道数量
"MaxDeviceCount": 50000, //最大设备数量
"MaxVariableCount": 10000000 //最大变量数量
}
}

6. Common.json

{
"Debug": true,
"LogLevel": "Info",
"LogPath": "Logs/XTrace",
"LogFileMaxMegabytes": "5",
"LogFileBackups": "10",
"LogFileFormat": "{0:yyyy_MM_dd}.log"
}

7. Database.json

{


// 数据库连接字符串参考地址:https://www.connectionstrings.com/

//数据库配置
"SqlOrm": [
{
"ConfigId": "DB_Admin", //ID
//"ConnectionString": "server=localhost;Database=test;Uid=root;Pwd=111111;AllowLoadLocalInfile=true;", //连接字符串
//"DatabaseType": "MySql", //数据库类型
"ConnectionString": "Data Source=./DB/Admin.db;", //连接字符串
"DatabaseType": "Sqlite", //数据库类型
"IsAutoCloseConnection": true, //是否自动释放
"InitDatabase": true, //是否初始化数据库,适用于codefirst
"InitTable": true, //是否初始化表,适用于codefirst
"InitSeedData": true, //是否初始化种子数据
"IsUpdateSeedData": false, //是否更新种子数据
"IsShowSql": false //是否控制台显示Sql语句
},
{
"ConfigId": "DB_Log", //ID
//"ConnectionString": "server=localhost;Database=test;Uid=root;Pwd=111111;AllowLoadLocalInfile=true;", //连接字符串
//"DatabaseType": "MySql", //数据库类型
"ConnectionString": "Data Source=./DB/Log.db", //连接字符串
"DatabaseType": "Sqlite", //数据库类型
"IsAutoCloseConnection": true, //是否自动释放
"InitDatabase": true, //是否初始化数据库,适用于codefirst
"InitTable": true, //是否初始化表,适用于codefirst
"InitSeedData": true, //是否初始化种子数据
"IsUpdateSeedData": false, //是否更新种子数据
"IsShowSql": false //是否控制台显示Sql语句
},
{
"ConfigId": "DB_TokenCache", //ID
//"ConnectionString": "server=localhost;Database=test;Uid=root;Pwd=111111;AllowLoadLocalInfile=true;", //连接字符串
//"DatabaseType": "MySql", //数据库类型
"ConnectionString": "Data Source=./DB/TokenCache.db", //连接字符串
"DatabaseType": "Sqlite", //数据库类型
"IsAutoCloseConnection": true, //是否自动释放
"InitDatabase": true, //是否初始化数据库,适用于codefirst
"InitTable": true, //是否初始化表,适用于codefirst
"InitSeedData": true, //是否初始化种子数据
"IsUpdateSeedData": false, //是否更新种子数据
"IsShowSql": false //是否控制台显示Sql语句
},
{
"ConfigId": "DB_HardwareInfo", //ID
//"ConnectionString": "server=localhost;Database=test;Uid=root;Pwd=111111;AllowLoadLocalInfile=true;", //连接字符串
//"DatabaseType": "MySql", //数据库类型
"ConnectionString": "Data Source=./DB/HardwareInfo.db", //连接字符串
"DatabaseType": "Sqlite", //数据库类型
"IsAutoCloseConnection": true, //是否自动释放
"InitDatabase": true, //是否初始化数据库,适用于codefirst
"InitTable": true, //是否初始化表,适用于codefirst
"InitSeedData": true, //是否初始化种子数据
"IsUpdateSeedData": false, //是否更新种子数据
"IsShowSql": false //是否控制台显示Sql语句
},
{
"ConfigId": "DB_Custom", //ID
//"ConnectionString": "server=localhost;Database=test;Uid=root;Pwd=111111;AllowLoadLocalInfile=true;", //连接字符串
//"DatabaseType": "MySql", //数据库类型
"ConnectionString": "Data Source=./DB/ThingsGateway.db", //连接字符串
"DatabaseType": "Sqlite", //数据库类型
"IsAutoCloseConnection": true, //是否自动释放
"InitDatabase": true, //是否初始化数据库,适用于codefirst
"InitTable": true, //是否初始化表,适用于codefirst
"InitSeedData": true, //是否初始化种子数据
"IsUpdateSeedData": false, //是否更新种子数据
"IsShowSql": false //是否控制台显示Sql语句
}

]
}

8. Email.json

{


"Email": {
"Host": "smtp.163.com", // 主机
"Port": 465, // 端口 465、994、25
"EnableSsl": true, // 启用SSL
"DefaultFromEmail": "xxx@163.com", // 默认发件者邮箱
"DefaultToEmail": "xxx@qq.com", // 默认接收人邮箱
"UserName": "xxx@163.com", // 邮箱账号
"Password": "", // 邮箱授权码
"DefaultFromName": "ThingsGateway" // 默认邮件标题
}
}

9. GatewayLog.json

{
"GatewayLog": {
"RpcLogDaysAgo": 30,
"BackendLogDaysAgo": 30
}
}

10. HardwareInfo.json

{
"HardwareInfo": {
"HistoryInterval": 300000, //历史更新间隔ms
"DaysAgo": 1, //保留1天数据
"Enable": true //启用硬件信息获取
}
}

11. JWT.json

{


"JWTSettings": {
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
"IssuerSigningKey": "12133c3f546eda35168c3aa3c2a1340fbe703f0996c6d123ea11dc2dc70adc0a", // 密钥,string 类型,必须是复杂密钥,长度大于16
"ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true
"ValidIssuer": "ThingsGateway", // 签发方,string 类型
"ValidateAudience": true, // 是否验证签收方,bool 类型,默认true
"ValidAudience": "ThingsGateway", // 签收方,string 类型
"ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true
//"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟,最大支持 13 年
"ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认5秒
"Algorithm": "HS256", // 加密算法,string 类型,默认 HS256
"RequireExpirationTime": true // 验证过期时间,设置 false 将永不过期
}
}

12. Logging.json

{


"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"EventLog": {
"LogLevel": {
"Default": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
} //windows事件输出日志等级
},
"Console": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
} //控制台输出日志等级
},
"BackendLog": {
"LogLevel": {
"Default": "Warning"
}
}
},

"Monitor": {
"GlobalEnabled": false, // 启用全局拦截日志
"IncludeOfMethods": [], // 拦截特定方法,当GlobalEnabled=false有效
"ExcludeOfMethods": [], // 排除特定方法,当GlobalEnabled=true有效
"BahLogLevel": "Information", // Oops.Oh 和 Oops.Bah 业务日志输出级别
"WithReturnValue": true, // 是否包含返回值,默认true
"ReturnValueThreshold": 500, // 返回值字符串阈值,默认0全量输出
"JsonBehavior": "None", // 是否输出Json,默认None(OnlyJson、All)
"JsonIndented": false, // 是否格式化Json
"UseUtcTimestamp": false // 时间格式UTC、LOCAL
},


//日志配置
"LogJob": {
"DaysAgo": 10 //清理10天前日志
}

}

13. Management.json

{
"$schema": "null",

"RemoteClientManagement": {
"Enable": false,
"Name": "ThingsGateway",
"ServerUri": "management.thingsgateway.cn:8299",
"VerifyToken": "ThingsGateway",
"HeartbeatInterval": 3000
},

"RemoteServerManagement": {
"Enable": false,
"Name": "ThingsGateway",
"ServerUri": "0.0.0.0:8399",
"VerifyToken": "ThingsGateway",
"HeartbeatInterval": 3000
}
}

14. RpcLog.json

{
"RpcLog": {
"SuccessLog": true //是否记录成功日志
}
}

15. Swagger.json

{
"$schema": "null",

//swagger设置
"SpecificationDocumentSettings": {
"DocumentTitle": "ThingsGateway",
"DocExpansionState": "None",
"GroupOpenApiInfos": [
{
"Group": "ThingsGateway.OpenApi", //分组唯一标识,string 类型,必填
"Order": 99, //分组排序,int 类型,数字越大排前面,默认 0
"Title": "ThingsGateway物联网关接口", //配置分组标题,string 类型
"Description": "物联网关Swagger",
"Version": "1.0.0", //配置分组版本,默认 1.0
"TermsOfService": "https://gitee.com/diego2098/ThingsGateway", //配置相关链接地址,Uri 类型
"Contact": {
//配置联系方式
"Name": "Diego",
"Url": "https://gitee.com/diego2098/ThingsGateway",
"Email": "2248356998@qq.com"
},
"License": {
//配置协议,OpenApiLicense 类型
"Name": "Apache-2.0",
"Url": "https://gitee.com/diego2098/ThingsGateway/blob/master/LICENSE.txt"
}
}

],
"EnableEnumSchemaFilter": true
}

}

16. Tenant.json

{
//多租户
"Tenant": {
"Enable": false
}
}

17. UpgradeServer.json

{
"UpgradeServer": {
"UpgradeServerIP": "127.0.0.1",
"UpgradeServerPort": 15789,
"Enable": false,
"Id": "123456789"
}
}

18. WebApi.json

内建WEBAPI,不需要启用

{
"WebApi": {
"Enable": false,
"ServerUri": "127.0.0.1:8999",
"UserName": "Admin",
"Password": "111111"
}
}