一、EMQX门户登陆
EMQX 安装后进入门户登陆,使用默认密码 admin public 登陆成功后会提示进行密码重置,再实际使用过程中,不会说安装成功后,再手动去修改默认账号密码,有时候可能就会直接使用默认密码不会去修改,这样会导致密码安全问题。
二、EMQX安装
1.EMQX 门户密码操作命令:
admins 命令使用
admins add <Username> <Password> <Description> # Add dashboard user
admins passwd <Username> <Password> # Reset dashboard user password
admins del <Username> # Delete dashboard user
门户账号添加
/emqx_ctl admins add admin Abc12345
密码重置
./emqx_ctl admins passwd admin Abc12345
门户用户删除
./emqx_ctl admins del admin
2. 在emqx 安装脚本更新
在原先服务安装脚本中,新增两点考量
1) 服务一键安装后,进行门户账号密码重置
2) 在卸载脚本时需要考虑将现有的账号数据进行清除,使服务可以重复卸载安装
2.1 整体脚本服务目录结构
2.2 eqmx 服务文件。emqx.service
[Unit]
Description=EMQ X Broker
After=network.target
[Service]
User=root
Group=root
ProtectProc=invisible
Type=forking
ExecStart=START_PATH start
ExecStop=STOP_PATH stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
2.3 安装与卸载脚本
install.sh
#!/bin/bash
#
int='\033[94m
_______ _____ ______ ________ ___ ___
|\ ___ \ |\ _ \ _ \|\ __ \ |\ \ / /|
\ \ __/|\ \ \\\__\ \ \ \ \|\ \ \ \ \/ / /
\ \ \_|/_\ \ \\|__| \ \ \ \\\ \ \ \ / /
\ \ \_|\ \ \ \ \ \ \ \ \\\ \ / \/
\ \_______\ \__\ \ \__\ \_____ \ / /\ \
\|_______|\|__| \|__|\|___| \__Y__/ /\ __\
\|__|__|/ \|__|
\033[0m'
echo -e "$int"
# Get current directory
CurDir=$(cd `dirname $0`;pwd)
echo "CurDir :$CurDir"
echo " home $HOME"
chmod 777 -R $CurDir
START_PATH="$CurDir/bin/emqx"
STOP_PATH="$CurDir/bin/emqx"
cp -r $CurDir/conf/emqx.service $CurDir/emqx.service
sed -i "s%START_PATH%$START_PATH%g" $CurDir/emqx.service
sed -i "s%STOP_PATH%$STOP_PATH%g" $CurDir/emqx.service
# service copy
cp -rf $CurDir/emqx.service /usr/lib/systemd/system/emqx.service
echo emqx server is is add to service and setup to boot up
#开放端口号
firewall-cmd --zone=public --add-port=1883/tcp --permanent
firewall-cmd --reload
systemctl daemon-reload
#添加开机启动
systemctl enable emqx.service
systemctl start emqx.service
# 初始化密码,首次运行EMQX会提示设置密码
$CurDir/bin/emqx_ctl admins passwd admin Abc12345
if [ $? -eq 0 ]; then
echo emqx is install success
exit 0
else
echo emqx is install fail
exit 1
fi
uninstall.sh
#!/bin/bash
#
int='\033[94m
_______ _____ ______ ________ ___ ___
|\ ___ \ |\ _ \ _ \|\ __ \ |\ \ / /|
\ \ __/|\ \ \\\__\ \ \ \ \|\ \ \ \ \/ / /
\ \ \_|/_\ \ \\|__| \ \ \ \\\ \ \ \ / /
\ \ \_|\ \ \ \ \ \ \ \ \\\ \ / \/
\ \_______\ \__\ \ \__\ \_____ \ / /\ \
\|_______|\|__| \|__|\|___| \__Y__/ /\ __\
\|__|__|/ \|__|
\033[0m'
echo -e "$int"
SERVICE_NAME=emqx
systemctl --no-pager status $SERVICE_NAME
if [ "$?" -ne 0 ]
then
echo " $SERVICE_NAME not install"
else
CurDir=$(cd `dirname $0`; pwd)
#delete service
PROXY_FILE="/usr/lib/systemd/system/${SERVICE_NAME}.service"
if [ ! -f $PROXY_FILE ]; then
echo "$SERVICE_NAME file is not exist in /usr/lib/systemd/system"
else
systemctl stop $SERVICE_NAME
systemctl disable $SERVICE_NAME
rm -rf $PROXY_FILE
systemctl daemon-reexec
if [[ "$OS_NAME" == "CentOS" || $CentOSVH -ge 7 ]];then
systemctl daemon-reload
fi
# 清除默认账号数据
rm -rf $CurDir/data/mnesia/*
echo "$SERVICE_NAME is deleted from service"
fi
echo " "
echo -e "\e[1;32m $SERVICE_NAME Service uninstalled succeed.\e[0m"
echo " "
fi
安装后服务状态查询
systemctl status emqx