启动后端
大约 8 分钟quickstartcode
一、 后端运行
- 导入git私服的 BladeX-Links 工程并点击
maven
刷新按钮下载依赖- 后端核心依赖工程:blade-tool
- 如需拓展开发核心依赖工程,开发完毕后在
blade-tool
工程根目录执行mvn clean install
命令便可刷新依赖 - 物联网平台底层基于BladeX架构开发,运行方式两者基本一致,在此之前推荐先查阅框架相关资料
- 特别详细的步骤,请看框架手册
- 前往
BladeX-Links
工程下的blade-server
模块的application.yml
配置文件,修改密钥保持与blade-broker
一致- 具体路径如下:
BladeX-Links/blade-service/blade-server/src/main/resources/application.yml
- 需要修改的配置如下
(展示的为默认配置,实际情况请修改为自行设置的签名)
:
#blade配置 blade: auth: #使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2验签,需和前端保持一致 public-key: 041cb889cccf335fcde7******************************3f5ac2b3542bbb903d84c07636550e8fe599aae4aef53a91cb77cbb1 #使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2解密,前端无需配置 private-key: 73e345f2edfdf84b6***************88be564defa94c18515a7ccde602463 token: #注意需要和blade-broker服务的sign-key保持一致 #使用 @org.springblade.test.SignKeyGenerator 获取 sign-key: 6klRvnw*************0TB4m51ZSh
- 具体路径如下:
BladeX-Links-UI/src/config/website.js
- 需要修改的配置如下
(展示的为默认配置,实际情况请修改为自行设置的签名)
:
auth: { // 使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2验签,需和后端保持一致 publicKey: '041cb889cccf335fcde7******************************3f5ac2b3542bbb903d84c07636550e8fe599aae4aef53a91cb77cbb1', }
- 具体路径如下:
- 前往
BladeX-Links
工程下的blade-server
模块的application-dev.yml
配置文件,修改数据库、redis、influxdb、minio等配置- 具体路径如下:
BladeX-Links/blade-service/blade-server/src/main/resources/application-dev.yml
- 需要修改的配置如下
(展示的为默认配置,实际情况请修改为自行设置的ip、端口、用户名、密码等配置)
:
#数据源配置 spring: data: redis: ##redis 单机环境配置 host: 127.0.0.1 port: 6379 password: database: 0 ssl: enabled: false datasource: url: jdbc:mysql://localhost:3306/bladex_iot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8 username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver #时序库 influxdb: url: http://127.0.0.1:8086 username: admin password: links database: links enable-batch: false #oss配置 oss: enabled: true name: minio tenant-mode: true endpoint: http://127.0.0.1:9000 access-key: bladexadmin secret-key: bladexadmin bucket-name: bladex #iot配置 blade: iot: # 外网ip或者域名 mqtt-ip: 127.0.0.1 # 外网可用的端口 mqtt-port: 1883 # broker服务ip或域名 broker-ip: ${blade.iot.mqtt-ip} # broker服务端口 broker-port: 8888
- 具体路径如下:
- 前往
BladeX-Links
工程下的blade-broker
模块的application.yml
配置文件,修改密钥保持与blade-server
一致- 具体路径如下:
BladeX-Links/blade-service/blade-broker/src/main/resources/application.yml
- 需要修改的配置如下
(展示的为默认配置,实际情况请修改为自行设置的签名)
:
#blade配置 blade: token: #使用 @org.springblade.test.SignKeyGenerator 获取 sign-key: 6klRvnw*************0TB4m51ZSh
- 具体路径如下:
- 前往
BladeX-Links
工程下的blade-broker
模块的application-dev.yml
配置文件,修改mqtt、database、redis、influxdb、minio等配置- 具体路径如下:
BladeX-Links/blade-service/blade-broker/src/main/resources/application-dev.yml
- 需要修改的配置如下
(展示的为默认配置,实际情况请修改为自行设置的ip、端口、用户名、密码等配置)
:
#数据源配置 spring: data: redis: ##redis 单机环境配置 host: 127.0.0.1 port: 6379 password: database: 0 ssl: enabled: false datasource: url: jdbc:mysql://localhost:3306/bladex_iot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8 username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver influxdb: url: http://127.0.0.1:8086 username: admin password: links database: links enable-batch: false #blade配置 blade: iot: # 外网ip或者域名 mqtt-ip: 127.0.0.1 # 外网可用的端口 mqtt-port: 1883 mqtt: server: enabled: true # 是否开启服务端,默认:true port: 1883 # 端口,默认:1883 name: BladeX-Mqtt-Server # 名称,默认:Mica-Mqtt-Server heartbeat-timeout: 120000 # 心跳超时,单位毫秒,默认: 1000 * 120 read-buffer-size: 8KB # 接收数据的 buffer size,默认:8k max-bytes-in-message: 10MB # 消息解析最大 bytes 长度,默认:10M auth: enable: false # 是否开启 mqtt 认证 debug: true # 如果开启 prometheus 指标收集建议关闭 stat-enable: true # 开启指标收集,debug 和 prometheus 开启时需要打开,默认开启,关闭节省内存 web-port: 8083 # http、websocket 端口,默认:8083 websocket-enable: true # 是否开启 websocket,默认: true http-enable: false # 是否开启 http api,默认: false ssl: # mqtt tcp ssl 认证 enabled: false # 是否开启 ssl 认证,2.1.0 开始支持双向认证 keystore-path: # 必须参数:ssl keystore 目录,支持 classpath:/ 路径。 keystore-pass: # 必选参数:ssl keystore 密码 truststore-path: # 可选参数:ssl 双向认证 truststore 目录,支持 classpath:/ 路径。 truststore-pass: # 可选参数:ssl 双向认证 truststore 密码 client-auth: none # 是否需要客户端认证(双向认证),默认:NONE(不需要)
- 具体路径如下:
- 启动
BladeX-Links
工程下的blade-broker
模块的BrokerApplication
启动类,看到如下日志,则说明启动成功____ _ _ __ __ _ _ _ | _ \| | | | \ \ / / | | (_) | | | |_) | | __ _ __| | ___ \ V / | | _ _ __ | | _____ | _ <| |/ _` |/ _` |/ _ \ > < | | | | '_ \| |/ / __| | |_) | | (_| | (_| | __// . \ | |___| | | | | <\__ \ |____/|_|\__,_|\__,_|\___/_/ \_\ |_____|_|_| |_|_|\_\___/ :: SpringBlade :: blade-broker:dev :: Running SpringBoot 3.2.4 :: 2024-06-03 00:26:26.238 INFO 21536 --- [kground-preinit] o.h.validator.internal.util.Version : HV000001: Hibernate Validator 8.0.1.Final 2024-06-03 00:26:26.265 INFO 21536 --- [ main] o.s.mqtt.broker.BrokerApplication : Starting BrokerApplication using Java 17.0.10 with PID 21536 (/Users/chill/Workspaces/product/BladeX-IOT/blade-broker/target/classes started by chill in /Users/chill/Workspaces/product/BladeX-IOT) 2024-06-03 00:26:26.265 DEBUG 21536 --- [ main] o.s.mqtt.broker.BrokerApplication : Running with Spring Boot v3.2.4, Spring v6.1.5 2024-06-03 00:26:26.266 INFO 21536 --- [ main] o.s.mqtt.broker.BrokerApplication : The following 1 profile is active: "dev" 2024-06-03 00:26:26.887 INFO 21536 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode 2024-06-03 00:26:26.888 INFO 21536 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode. 2024-06-03 00:26:26.904 INFO 21536 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9 ms. Found 0 Redis repository interfaces. 2024-06-03 00:26:26.956 WARN 21536 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'mqttAccountMapper' and 'org.springblade.mqtt.broker.auth.mapper.MqttAccountMapper' mapperInterface. Bean already defined with the same name! 2024-06-03 00:26:26.956 WARN 21536 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'mqttAuthLogMapper' and 'org.springblade.mqtt.broker.auth.mapper.MqttAuthLogMapper' mapperInterface. Bean already defined with the same name! 2024-06-03 00:26:26.957 WARN 21536 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'deviceMapper' and 'org.springblade.mqtt.broker.device.mapper.DeviceMapper' mapperInterface. Bean already defined with the same name! 2024-06-03 00:26:26.998 INFO 21536 --- [ main] s.c.l.p.BladePropertySourcePostProcessor : BladePropertySourcePostProcessor init. 2024-06-03 00:26:27.021 INFO 21536 --- [ main] s.c.l.p.BladePropertySourcePostProcessor : BladePropertySourcePostProcessor process @BladePropertySource bean. 2024-06-03 00:26:27.336 WARN 21536 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used 2024-06-03 00:26:27.343 INFO 21536 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext 2024-06-03 00:26:27.343 INFO 21536 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1057 ms 2024-06-03 00:26:27.503 INFO 21536 --- [ main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource 2024-06-03 00:26:27.541 INFO 21536 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 2024-06-03 00:26:28.647 INFO 21536 --- [ main] n.d.i.m.core.server.MqttServerCreator : Mica mqtt http api enable:false websocket enable:true 2024-06-03 00:26:29.059 INFO 21536 --- [ main] o.s.core.boot.config.RetryConfiguration : configServerRetryInterceptor: Changing backOffOptions to initial: 1000, multiplier: 1.2, maxInterval: 5000 2024-06-03 00:26:29.072 INFO 21536 --- [ main] o.s.core.log.logger.BladeLogger : blade-broker: BladeLogger init success! 2024-06-03 00:26:29.459 INFO 21536 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator' 2024-06-03 00:26:29.633 INFO 21536 --- [ main] io.undertow : starting server: Undertow - 2.3.12.Final 2024-06-03 00:26:29.636 INFO 21536 --- [ main] org.xnio : XNIO version 3.8.8.Final 2024-06-03 00:26:29.640 INFO 21536 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.8.8.Final 2024-06-03 00:26:29.651 INFO 21536 --- [ main] org.jboss.threads : JBoss Threads version 3.5.0.Final 2024-06-03 00:26:29.668 INFO 21536 --- [ main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port 8888 (http) 2024-06-03 00:26:29.670 INFO 21536 --- [ Thread-1] org.tio.utils.timer.TimingWheelThread : Starting 2024-06-03 00:26:29.670 INFO 21536 --- [sync-executor-1] o.s.core.launch.StartEventListener : ---[BLADE-BROKER]---启动完成,当前使用的端口:[8888],环境变量:[dev]--- 2024-06-03 00:26:29.672 INFO 21536 --- [ main] org.tio.server.TioServer : |----------------------------------------------------------------------------------------| | TioConfig name | BladeX-Mqtt-Server | | Mica net version | 1.0.0 | | Started at | 2024-06-03 00:26:29 | | Listen on | 0.0.0.0:1883 | | Main Class | org.springblade.mqtt.broker.BrokerApplication | | Jvm start time | 4318ms | | Tio start time | 2ms | | Pid | 21536 | |----------------------------------------------------------------------------------------| 2024-06-03 00:26:29.673 INFO 21536 --- [ main] org.tio.server.TioServer : |----------------------------------------------------------------------------------------| | TioConfig name | BladeX-Mqtt-Server-HTTP/Websocket | | Mica net version | 1.0.0 | | Started at | 2024-06-03 00:26:29 | | Listen on | 0.0.0.0:8083 | | Main Class | org.springblade.mqtt.broker.BrokerApplication | | Jvm start time | 4319ms | | Tio start time | 1ms | | Pid | 21536 | |----------------------------------------------------------------------------------------| 2024-06-03 00:26:29.684 INFO 21536 --- [ main] o.s.mqtt.broker.BrokerApplication : Started BrokerApplication in 3.669 seconds (process running for 4.348) 2024-06-03 00:26:29.957 INFO 21536 --- [-192.168.31.254] io.undertow.servlet : Initializing Spring DispatcherServlet 'dispatcherServlet' 2024-06-03 00:26:29.958 INFO 21536 --- [-192.168.31.254] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2024-06-03 00:26:29.958 INFO 21536 --- [-192.168.31.254] o.s.web.servlet.DispatcherServlet : Completed initialization in 0 ms
- 启动
BladeX-Links
工程下的blade-server
模块的ServerApplication
启动类,看到如下日志,则说明启动成功____ _ _ __ __ _ _ _ | _ \| | | | \ \ / / | | (_) | | | |_) | | __ _ __| | ___ \ V / | | _ _ __ | | _____ | _ <| |/ _` |/ _` |/ _ \ > < | | | | '_ \| |/ / __| | |_) | | (_| | (_| | __// . \ | |___| | | | | <\__ \ |____/|_|\__,_|\__,_|\___/_/ \_\ |_____|_|_| |_|_|\_\___/ :: SpringBlade :: blade-server:dev :: Running SpringBoot 3.2.4 :: 2024-06-03 00:26:26.462 INFO 21541 --- [kground-preinit] o.h.validator.internal.util.Version : HV000001: Hibernate Validator 8.0.1.Final 2024-06-03 00:26:26.493 INFO 21541 --- [ main] org.springblade.ServerApplication : Starting ServerApplication using Java 17.0.10 with PID 21541 (/Users/chill/Workspaces/product/BladeX-IOT/blade-server/target/classes started by chill in /Users/chill/Workspaces/product/BladeX-IOT) 2024-06-03 00:26:26.493 DEBUG 21541 --- [ main] org.springblade.ServerApplication : Running with Spring Boot v3.2.4, Spring v6.1.5 2024-06-03 00:26:26.493 INFO 21541 --- [ main] org.springblade.ServerApplication : The following 1 profile is active: "dev" 2024-06-03 00:26:27.153 INFO 21541 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode 2024-06-03 00:26:27.154 INFO 21541 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode. 2024-06-03 00:26:27.192 INFO 21541 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 32 ms. Found 0 Redis repository interfaces. 2024-06-03 00:26:27.237 WARN 21541 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[org.springblade]' package. Please check your configuration. 2024-06-03 00:26:27.298 INFO 21541 --- [ main] s.c.l.p.BladePropertySourcePostProcessor : BladePropertySourcePostProcessor init. 2024-06-03 00:26:27.320 INFO 21541 --- [ main] s.c.l.p.BladePropertySourcePostProcessor : BladePropertySourcePostProcessor process @BladePropertySource bean. 2024-06-03 00:26:27.637 WARN 21541 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used 2024-06-03 00:26:27.643 INFO 21541 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext 2024-06-03 00:26:27.643 INFO 21541 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1133 ms 2024-06-03 00:26:27.813 INFO 21541 --- [ main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource 2024-06-03 00:26:27.847 INFO 21541 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 2024-06-03 00:26:30.954 INFO 21541 --- [ main] o.s.core.boot.config.RetryConfiguration : configServerRetryInterceptor: Changing backOffOptions to initial: 1000, multiplier: 1.2, maxInterval: 5000 2024-06-03 00:26:30.962 INFO 21541 --- [ main] o.s.core.log.logger.BladeLogger : blade-server: BladeLogger init success! 2024-06-03 00:26:31.395 INFO 21541 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator' 2024-06-03 00:26:31.866 INFO 21541 --- [ main] io.undertow : starting server: Undertow - 2.3.12.Final 2024-06-03 00:26:31.869 INFO 21541 --- [ main] org.xnio : XNIO version 3.8.8.Final 2024-06-03 00:26:31.872 INFO 21541 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.8.8.Final 2024-06-03 00:26:31.882 INFO 21541 --- [ main] org.jboss.threads : JBoss Threads version 3.5.0.Final 2024-06-03 00:26:31.899 INFO 21541 --- [ main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port 80 (http) 2024-06-03 00:26:31.901 INFO 21541 --- [sync-executor-1] o.s.core.launch.StartEventListener : ---[BLADE-SERVER]---启动完成,当前使用的端口:[80],环境变量:[dev]--- 2024-06-03 00:26:31.910 INFO 21541 --- [ main] org.springblade.ServerApplication : Started ServerApplication in 5.638 seconds (process running for 5.923) 2024-06-03 00:26:32.271 INFO 21541 --- [-192.168.31.254] io.undertow.servlet : Initializing Spring DispatcherServlet 'dispatcherServlet' 2024-06-03 00:26:32.271 INFO 21541 --- [-192.168.31.254] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2024-06-03 00:26:32.273 INFO 21541 --- [-192.168.31.254] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
二、注意事项
生产安全必看
- 上线后必须修改admin密码,防止被人恶意登录影响系统安全。
- 必须修改各数据库、redis的端口密码,防止被恶意程序扫描到。
- 熟读Blade安全手册,解决系统的安全隐患:点击查看