关于java:1wumeismart系统运行

6次阅读

共计 4642 个字符,预计需要花费 12 分钟才能阅读完成。

一、零碎运行环境

JDK >= 1.8 (举荐 1.8 版本)
Mysql >= 5.7.0 (举荐 5.7 版本)
Redis >= 3.0
Maven >= 3.0
Node >= 12
EMQX =4.0

运行环境很重要,低于该版本运行不了。JDK 版本高于 1.8 短少局部依赖,要独自装置。EMQX 装置后须要配置 HTTP 认证和 WebHook。

二、后端运行

1. 创立 wumei-smart 数据库,导入我的项目中的 springboot/sql/wumei.sql 数据库脚本。(Linux 中装置 mysql,配置大小写敏感,在 /etc/my.cnf 增加 lower_case_table_names=1 重启 MYSQL 服务。)
2. 开发工具 IDEA 关上 springboot 文件夹,会主动装置 Maven 依赖,期待装置实现,速度取决于网络。
3. 批改数据库连贯,文件位于: springboot/wumei-admin/src/main/resources/application-druid.yml

# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主库数据源
            master:
                url: 数据库地址
                username: 数据库账号
                password: 数据库明码 

4. 服务配置,文件位于:springboot/wumei-admin/src/main/resources/application.yml。留神配置文件的格局,缩进肯定要对齐。

  ## 文件上传门路 示例(Windows 配置 D:/wumei-smart/uploadPath,Linux 配置 /var/wumei-smart/java/uploadPath)profile: /var/wumei-smart/java/uploadPath
 
  ## redis 配置
  redis:
    # 地址
    host: localhost
    # 端口,默认为 6379
    port: 6379
    # 数据库索引
    database: 0
    # 明码
    password: wumei-smart
  
  ## EMQX 配置
  mqtt:
    username: wumei-smart                    # 账号(设施简略认证的用户名)password: wumei-smart                    # 明码 (设施简略认证的明码)
    host-url: tcp://localhost:1883           # EMQX 的部署地址
  

5. 日志门路配置,文件位于:springboot/wumei-admin/src/main/resources/logback.xml

# 示例(Windows 配置 D:/wumei-smart/logs,Linux 配置 /var/wumei-smart/java/logs)<property name="log.path" value="/var/wumei-smart/java/logs" />

6. 运行我的项目 WumeiSmartApplication.java,呈现下图示意启动胜利。

                               _                            _   
                              (_)                          | |             
__      ___   _ _ __ ___   ___ _   ___ _ __ ___   __ _ _ __| |_            
\ \ /\ / / | | | '_ ` _ \ / _ \ | / __|'_ ` _ \ / _` | '__| __|     
 \ V  V /| |_| | | | | | |  __/ | \__ \ | | | | | (_| | |  | |_         
  \_/\_/  \__,_|_| |_| |_|\___|_| |___/_| |_| |_|\__,_|_|   \__|     

 ---------- 开源生存物联网平台 ----------
 =========wumei-smart 启动胜利 =========

三、前端运行

开发工具 Visual Studio Code 关上我的项目中 vue 目录
1. 批改根目录的 vue.config.js 文件中的后端接口地址和 Emqx 装置地址,本地不必批改。

    proxy: {[process.env.VUE_APP_BASE_API]: {
        target: `http://localhost:8080`,  // 后端接口地址
        changeOrigin: true,
        pathRewrite: {['^' + process.env.VUE_APP_BASE_API]: ''
        }
      },
      ['/api/v4']: {
        target: `http://localhost:8081`,   // Emqx 装置地址
        changeOrigin: true,
      },
    },
    

2. 批改 wumei-smart\vue\src\views\iot\device\mqtt-client.vue 文件的 mqtt 连贯地址,Emqx 装置在本地不必批改。

    // 配置 Mqtt 连贯地址,例如:ws://localhost:8083/mqtt
    let url = "ws://" + window.location.hostname + ":8083/mqtt";
    console.log("mqtt 地址:", url);
    this.client = mqtt.connect(url, options);

3. 批改实现后,开始装置依赖,能够通过从新指定 registry 来解决 npm 装置速度慢的问题。

# 装置依赖
npm install
# 强烈建议不要用间接应用 cnpm 装置,会有各种诡异的 bug
npm install --registry=https://registry.npm.taobao.org

# 本地开发 启动我的项目
npm run dev
  1. 关上浏览器,输出:http://localhost:80 默认账户 / 明码 admin/admin123。若能正确展现登录页面,并能胜利登录,菜单及页面展现失常,则表明环境搭建胜利。

四、EMQX 配置

HTTP 认证

零碎应用 EMQX 的 HTTP 认证插件,实现自定义认证逻辑。配置文件位于:etc/plugins/emqx_auth_http.conf

## 批改认证申请中的申请地址,其余放弃默认
auth.http.auth_req = http://localhost:8080/iot/tool/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P

## 正文超级用户的申请地址、申请形式和参数
# auth.http.super_req = http://127.0.0.1:8991/mqtt/superuser 
# auth.http.super_req.method = post                                                                    
# auth.http.super_req.params = clientid=%c,username=%u

## 正文 ACL 鉴权的申请地址、申请办法和参数                                    
# auth.http.acl_req = http://127.0.0.1:8991/mqtt/acl                                                             
# auth.http.acl_req.method = get                                                                                  
# auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t,mountpoint=%m

认证申请地址为后端接口 http://localhost:8080/iot/tool/mqtt/auth,后端运行在本地应用 localhost 或本机 IP,端口默认 8080,如果做了批改或者代理,须要对应批改。超级用户认证和 ACL 鉴权用不到,然而须要正文掉,不然会占用 5 秒左右的认证工夫。

WebHook

零碎应用 EMQX 的 WebHook 插件,实现设施高低线和 IP 定位性能。配置文件位于:etc/plugins/emqx_web_hook.conf

## 批改 webhook 地址
web.hook.api.url = http://localhost:8080/iot/tool/mqtt/webhook

# web.hook.rule.client.connect.1       = {"action": "on_client_connect"}
# web.hook.rule.client.connack.1       = {"action": "on_client_connack"}
web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
# web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
# web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
# web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
# web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
# web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
# web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
# web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
# web.hook.rule.message.acked.1        = {"action": "on_message_acked"}

WebHook 地址为后端接口 http://localhost:8080/iot/tool/mqtt/webhook,后端运行在本地应用 localhost 或本机 IP,端口默认 8080,如果做了批改或者代理,须要对应批改。启用 web.hook.rule.client.connected.1web.hook.rule.client.disconnected.1 其余项正文掉,节俭后端资源。

敞开匿名认证

匿名认证不平安,倡议敞开。EMQX 同时应用多个认证形式,也会升高认证速度。配置文件位于:etc/emqx.conf,文件比拟大,大略位于第 447 行。

## Value: true | false
allow_anonymous = false

启用 Http 认证和 WebHook 插件

在 EMQX 启动时就默认启动插件,间接在 data/loaded_plugins 增加须要启动的插件名称 {emqx_auth_http,true}. {emqx_web_hook,true}.。装置形式不同配置文件可能在 /var/lib/emqx/loaded_plugins 地位。emqx 所有配置批改完后,重启 emqx。

{emqx_management,true}.
{emqx_recon,true}.
{emqx_retainer,true}.
{emqx_dashboard,true}.
{emqx_rule_engine,true}.
{emqx_bridge_mqtt,false}.
{emqx_auth_http,true}.
{emqx_web_hook,true}.

物美智能官网

正文完
 0