一、零碎运行环境

JDK >= 1.8 (举荐1.8版本)Mysql >= 5.7.0 (举荐5.7版本)Redis >= 3.0Maven >= 3.0Node >= 12EMQX =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 装置,会有各种诡异的 bugnpm 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/authauth.http.auth_req.method = postauth.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 | falseallow_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}.

物美智能官网