1.下载源码:
git clone https://gitee.com/chenyanjun_data/iot.git
2.环境搭建:
1.前端:
NodeJS:
1.删除旧版nodejs与npm
sudo apt remove nodejs
sudo apt remove npm
2.下载安装新版
wget https://nodejs.org/dist/latest-v16.x/node-v16.20.2-linux-x64.tar.gz
tar -zxvf node-v16.20.2-linux-x64.tar.gz
mv node-v16.20.2-linux-x64 node
mv node /opt
ln -s /opt/node/npm /usr/local/bin
ln -s /opt/node/node /usr/local/bin
npm install
npm run build:prod
2.MQTX:
1.下载安装包
wget https://www.emqx.com/zh/downloads/broker/v4.0.0/emqx-ubuntu18.04-v4.0.0_amd64.deb
2.安装
apt install ./emqx-ubuntu18.04-v4.0.0_amd64.deb
3.修改配置信息
WebHook:系统使用EMQX的WebHook插件,实现设备上下线和IP定位功能
vim /etc/emqx/plugins/emqx_web_hook.conf
web.hook.api.url = http://127.0.0.1:8080/iot/tool/mqtt/webhook
## Encode message payload field
##
## Value: base64 | base62
##
## Default: undefined
## web.hook.encode_payload = base64
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"}
HTTP认证:使用EMQX的HTTP认证插件,实现自定义认证逻辑
vim /etc/emqx/plugins/emqx_auth_http.conf
##--------------------------------------------------------------------
## HTTP Auth/ACL Plugin
##--------------------------------------------------------------------
##------------------------------------------------------------------------------
## SSL options
## Path to the file containing PEM-encoded CA certificates. The CA certificates
## are used during server authentication and when building the client certificate chain.
##
## Value: File
## auth.http.ssl.cacertfile = /etc/emqx/certs/ca.pem
## The path to a file containing the client's certificate.
##
## Value: File
## auth.http.ssl.certfile = /etc/emqx/certs/client-cert.pem
## Path to a file containing the client's private PEM-encoded key.
##
## Value: File
## auth.http.ssl.keyfile = /etc/emqx/certs/client-key.pem
##--------------------------------------------------------------------
## HTTP Request Headers
##
## Example: auth.http.header.Accept-Encoding = *
##
## Value: String
## auth.http.header.Accept = */*
##--------------------------------------------------------------------
## Authentication request.
##
## Variables:
## - %u: username
## - %c: clientid
## - %a: ipaddress
## - %r: protocol
## - %P: password
## - %p: sockport of server accepted
## - %C: common name of client TLS cert
## - %d: subject of client TLS cert
##
## Value: URL
#auth.http.auth_req = http://wl1805cyj.xyz:8080/iot/tool/mqtt/auth
auth.http.auth_req = http://127.0.0.1:8080/iot/tool/mqtt/auth
## Value: post | get | put
auth.http.auth_req.method = post
## Value: Params
auth.http.auth_req.params = clientid=%c,username=%u,password=%P
##--------------------------------------------------------------------
## Superuser request.
##
## Variables:
## - %u: username
## - %c: clientid
## - %a: ipaddress
## - %r: protocol
## - %P: password
## - %p: sockport of server accepted
## - %C: common name of client TLS cert
## - %d: subject of client TLS cert
##
## Value: URL
#auth.http.super_req = http://127.0.0.1:8991/mqtt/superuser
## Value: post | get | put
#auth.http.super_req.method = post
## Value: Params
#auth.http.super_req.params = clientid=%c,username=%u
##--------------------------------------------------------------------
## ACL request.
##
## Variables:
## - %A: 1 | 2, 1 = sub, 2 = pub
## - %u: username
## - %c: clientid
## - %a: ipaddress
## - %r: protocol
## - %m: mountpoint
## - %t: topic
##
## Value: URL
#auth.http.acl_req = http://127.0.0.1:8991/mqtt/acl
## Value: post | get | put
#auth.http.acl_req.method = get
## Value: Params
#auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t,mountpoint=%m
##------------------------------------------------------------------------------
## Http Reqeust options
## Time-out time for the http request, 0 is never timeout.
##
## Value: Duration
## -h: hour, e.g. '2h' for 2 hours
## -m: minute, e.g. '5m' for 5 minutes
## -s: second, e.g. '30s' for 30 seconds
##
## Default: 0
## auth.http.request.timeout = 0
## Connection time-out time, used during the initial request
## when the client is connecting to the server
##
## Value: Duration
##
## Default is same with the timeout option
## auth.http.request.connect_timout = 0
## Re-send http reuqest times
##
## Value: integer
##
## Default: 3
auth.http.request.retry_times = 3
## The interval for re-sending the http request
##
## Value: Duration
##
## Default: 1s
auth.http.request.retry_interval = 1s
## The 'Exponential Backoff' mechanism for re-sending request. The actually
## re-send time interval is `interval * backoff ^ times`
##
## Value: float
##
## Default: 2.0
auth.http.request.retry_backoff = 2.0
关闭匿名认证:匿名认证不安全,同时会影响认证流程,需要关闭
vim /etc/emqx/emqx.conf
## Value: true | false
allow_anonymous = false
4.运行
systemctl start emqx
3.Nginx
1.Nginx安装
sudo apt-get install nginx
2.Nginx修改配置
vim /etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root /opt/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
location /api/v4/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8081/api/v4/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3.将前端dist文件复制到/opt/下
4.Nginx运行
systemctl start nginx.service
4.Redis安装
wget https://packages.redis.io/redis-stack/redis-stack-server-7.2.0-v7.bionic.x86_64.tar.gz?_gl=1*s2liqh*_ga*NTgxMjcyMDkyLjE3MDYzMzExOTg.*_ga_8BKGRQKRPV*MTcwNjMzMTE5OC4xLjEuMTcwNjMzMTQzMi40OS4wLjA.*_gcl_au*MTM2MjgyNjk2OS4xNzA2MzMxMTk4
解压后 ./redis-server
5.后端运行
java -jar wumei-admin.java
评论