Emqttd1:192.168.88.61  Emqttd2:192.168.88.62  Emqttd3:192.168.88.63  Redis:192.168.88.64  Haproxy:192.168.88.65

系统优化配置:

ulimit  -n  1048576

sysctl  -w fs.file-max=2097152

sysctl  -w fs.nr_open=2097152

sysctl  -w net.core.somaxconn=65535

一、解压、安装、修改配置:

$ unzip emqttd-centos6.8-v2.2.0.zip

$ cd emqttd

$ vi etc/emq.conf

  #node.name

  node.name = emqttd@192.168.88.61

  ## Cookie for distributed node

  node.cookie = emq_dist_cookie_533d99ckd9ji475

  ## Erlang Process Limit

  node.process_limit = 2000000

  ## Sets the maximum number of simultaneously existing ports for this system

  node.max_ports = 1000000

  ## Size of acceptor pool

  mqtt.listener.tcp.acceptors = 64

  ## Maximum number of concurrent clients

  mqtt.listener.tcp.max_clients = 1000000

  ## Rate Limit. Format is 'burst,rate', Unit is KB/Sec

  ## mqtt.listener.tcp.rate_limit = 100,10

  ## TCP Socket Options

  mqtt.listener.tcp.backlog = 262144

  ## Distributed node port range

  node.dist_listen_min = 6000

  node.dist_listen_max = 6999

如果需要启用防火墙,则上面两行去掉注释,注意下面的防火墙端口设置,要打开该段端口。

端口:1883:MQTT协议tcp端口,8883:MQTT(SSL) tcp端口,8083:MTQQ(websocket)、HTTP API端口,18083:dashboard管理控制WEB端口,4369:集群处理epmd端口,6000-6999由上面配置文件定义的epmd需要的端口范围。

启动:

$ cd emqttd

直接进入控制台模式

  $ ./bin/emqttd console

  $ ./bin/emqttd start     (启动)

  $ ./bin/emqttd_ctl status (查看状态)

  $ ./bin/emqttd stop       (停止)

查看各台的启动状态:

http:192.168.88.61:8083/status

http:192.168.88.61:18083/     user/password:admin/public

二、把节点加入集群:

在各个节点上执行(重复执行也没关系):

$ ./bin/emqttd_ctl cluster join emqttd@192.168.88.61/62/63

$ ./bin/emqttd_ctl cluster status

Cluster status: [{running_nodes,['node3@192.168.88.63',

'node1@192.168.88.61',

'node2@192.168.88.62']}]

把节点退出集群:

本机退出集群:

$ ./bin/emqttd_ctl cluster leave

把某节点退出集群:

$ ./bin/emqttd_clt cluster remove emqttd@192.168.88.61

三、测试:

下载安装MTQQ协议的客户端:https://mosquitto.org/download/

$ sudo rpm -ivh libmosquitto1-1.4.10-1.1.x86_64.rpm

$ sudo rpm -ivh mosquitto-clients-1.4.10-1.1.x86_64.rpm

订阅:

$ mosquitto_sub -h 192.168.88.62 -p 1883 -t test_topic_1 -q 1 -c -i 1111

带用户名和密码:

$ mosquitto_sub -h 192.168.88.62 -p 1883 -t test_topic_1 -q 1 -c -i 1111 -u user -P 123456

发布:另开一个ssh或者另外机器上执行:

$ mosquitto_pub -h 192.168.88.62 -p 1883 -t test_topic_1 -q 1 -m "hello mqtt 7"

带用户名和密码:

$ mosquitto_pub -h 192.168.88.62 -p 1883 -t test_topic_1 -q 1 -m "hello mqtt 7" -u user -P 123456

参数:

-h: 连接到哪台broker。

-p: 连接端口。

-t: topic名字,topic类似文件系统的组织方式,以"/"分隔符来分层,订阅者订阅时可以使用通配符"+"和"#",发布者不能使用通配符。

-q: qos级别,默认为0,共三个值:0:至多一次,不保证到达订阅者;1:至少一次,保证到达订阅者,但不保证不重复;2:正好一次,保证到达,又保证不重复;非钱类的应用使用qos1就可以了。

-c: 如果订阅者退出,在broker保留所有订阅的消息,一旦重新连接上,则把所有消息发给订阅者,就是持久性订阅(clean_sess=false)。

-i: 设置client id,在即时通信时可以设置为用户id或者用户名等具有唯一性的字段。

-r: 发布方使用的参数,保留消息(每个topic只保留最后一个这种消息,之前的会覆盖 ),即使该消息被一个订阅者读取了,还会一直保留在broker,如果有新的订阅者订阅该topic,则马上会收到该消息,类似qq里面的公告性消息,这类信息的删除,发送一个payload为空的null消息即可:$ mosquitto_pub -h 192.168.88.62 -p 1883 -t test_topic_1 -q 1 -r -n  -u user -P 123456。

-m: 该topic的一条消息内容。

四、Redis 插件认证(先要安装redis)

Redis 认证。MQTT 用户记录存储在 Redis Hash, 键值: “mqtt_user:<Username>”

vi etc/plugins/emq_auth_redis.conf 设置 ‘super_cmd’、’auth_cmd’、’password_hash’:

## Redis Serverauth.redis.server = 127.0.0.1:6379

## Redis Pool Sizeauth.redis.pool = 8

## Redis Databaseauth.redis.database = 0

## Redis Password## auth.redis.password =

## Variables: %u = username, %c = clientid

## Authentication Query Commandauth.redis.auth_cmd = HGET mqtt_user:%u password

## Password hash: plain, md5, sha, sha256, pbkdf2auth.redis.password_hash = sha256

## Superuser Query Commandauth.redis.super_cmd = HGET mqtt_user:%u is_superuser

启用 Redis 认证插件:

./bin/emqttd_ctl plugins load emq_auth_redis

五、MySQL 插件认证

通过 MySQL 数据库表认证,可创建如下的 ‘mqtt_user’ 表:

CREATE TABLE `mqtt_user` (

`id` int(11) unsigned NOT NULL AUTO_INCREMENT,

`username` varchar(100) DEFAULT NULL,

`password` varchar(100) DEFAULT NULL,

`salt` varchar(20) DEFAULT NULL,

`is_superuser` tinyint(1) DEFAULT 0,

`created` datetime DEFAULT NULL,

PRIMARY KEY (`id`),

UNIQUE KEY `mqtt_username` (`username`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;

vi etc/plugins/emq_auth_mysql.conf 配置 ‘super_query’, ‘auth_query’, ‘password_hash’:

## Mysql Serverauth.mysql.server = 127.0.0.1:3306

## Mysql Pool Sizeauth.mysql.pool = 8

## Mysql Username## auth.mysql.username =

## Mysql Password## auth.mysql.password =

## Mysql Databaseauth.mysql.database = mqtt

## Variables: %u = username, %c = clientid

## Authentication Query: select password onlyauth.mysql.auth_query = select password from mqtt_user where username = '%u' limit 1

## Password hash: plain, md5, sha, sha256, pbkdf2auth.mysql.password_hash = sha256

## %% Superuser Queryauth.mysql.super_query = select is_superuser from mqtt_user where username = '%u' limit 1

注解

如果系统已有MQTT认证表,可通过配置’auth_query’查询语句集成。

启用 MySQL 认证插件:

./bin/emqttd_ctl plugins load emq_auth_mysql

六、使用Haproxy来实现负载分担:

因为emq的topic和消息在集群的各台服务器上一致,所以数据不能以增加机器的方式扩容,只能增加每台的内存,和客户端的连接则可以以增加机器方式扩容。

软件安装

[root@cacti src]# tar xzvf haproxy-1.4.24.tar.gz

[root@cacti haproxy-1.4.24]# make TARGET=linux26 PREFIX=/usr/local/haproxy

[root@cacti haproxy-1.4.24]# make install PREFIX=/usr/local/haproxy

配置文件:vi haproxy.cfg

global

log 127.0.0.1 local3

maxconn 20480

chroot /usr/local/haproxy

uid 1004

gid 1004

daemon

quiet

nbproc 1

pidfile /var/run/haproxy.pid

defaults

log global

mode http

maxconn 20480

option httplog

option httpclose

option forwardfor

option dontlognull

option redispatch

retries 3

balance roundrobin

contimeout 5000

clitimeout 50000

srvtimeout 50000

listen emq_emqttd *:1883

mode tcp

balance source

log global

timeout connect         25s

timeout client          0

timeout server          0

option tcpka

option tcplog

#option tcp-check

server emq1 192.168.88.61:1883 check inter 25000 port 1883 rise 2 fall 2 weight 25

server emq2 192.168.88.62:1883 check inter 25000 port 1883 rise 2 fall 2 weight 25

server emq3 192.168.88.63:1883 check inter 25000 port 1883 rise 2 fall 2 weight 25

listen status 192.168.88.65:8080

stats enable

stats uri /stats

stats auth admin:123456

stats realm (Haproxy\ statistic)

创建haproxy启动脚本:

#!/bin/bash

#

# haproxy

#

# chkconfig: 35 85 15

# description: HAProxy is a free, very fast and reliable solution \

# offering high availability, load balancing, and \

# proxying for TCP and HTTP-based applications

# processname: haproxy

# config: /etc/haproxy.cfg

# pidfile: /var/run/haproxy.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

config="/etc/haproxy.cfg"

exec="/usr/local/haproxy/sbin/haproxy"

prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/haproxy

check() {

$exec -c -V -f $config

}

start() {

$exec -c -q -f $config

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Starting $prog: "

# start it up here, usually something like "daemon $exec"

daemon $exec -D -f $config -p /var/run/$prog.pid

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

# stop it here, often "killproc $prog"

killproc $prog

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

$exec -c -q -f $config

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

stop

start

}

reload() {

$exec -c -q -f $config

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Reloading $prog: "

$exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)

retval=$?

echo

return $retval

}

force_reload() {

restart

}

fdr_status() {

status $prog

}

case "$1" in

start|stop|restart|reload)

$1

;;

force-reload)

force_reload

;;

checkconfig)

check

;;

status)

fdr_status

;;

condrestart|try-restart)

[ ! -f $lockfile ] || restart

;;

*)

echo $"Usage: $0 {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}"

exit 2

esac

启动

[root@cacti etc]# /etc/init.d/haproxy start

Starting haproxy: [ OK ]

[root@cacti etc]# ps -ef | grep haproxy

100 2305 1 0 17:55 ? 00:00:00 /usr/local/sbin/haproxy -D -f /etc/haproxy.cfg -p /var/run/haproxy.pid

root 2308 774 0 17:55 pts/0 00:00:00 grep haproxy

如果没写启动脚本,可以用下方式启动:

/usr/local/haproxy/sbin/haproxy –f /usr/local/haproxy/etc/haproxy.cft

转载于:https://www.cnblogs.com/longfeng/p/8611117.html

emqttd 2.2安装和测试使用相关推荐

  1. my SQL下载安装,环境配置,以及密码忘记的解决,以及navicat for mysql下载,安装,测试连接...

    一.下载 在百度上搜索"mysql-5.6.24-winx64下载" 二.安装 选择安装路径,我的路径"C:\Soft\mysql-5.6.24-winx64" ...

  2. http_load安装与测试参数分析

    http_load安装与测试参数分析 http_load以并行复用的方式运行,用以测试 web 服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把客户机搞死. ...

  3. nginx 没有sbin目录_CentOS7下Nginx+ModSecurity配置、安装、测试教程

    " 最近在工作上遇到一点问题,问了大佬.百度,都没有很好地解决:经过大量搜索查阅以及试验,终于将问题解决.于是写下这篇文章以提醒自己,也可供读者参考." 环境:CentOS-7-x ...

  4. AutoBench+Httperf的安装、测试

    首先安装Httperf.主要是Httperf网路上给出的url均无法访问,因此在GitHub上找的源码工程,进行安装. 接下来介绍安装步骤,从Github下载下来的httperf包是zip. unzi ...

  5. 安装并测试nvenc linux sdk

    2019独角兽企业重金招聘Python工程师标准>>> nvidia在cuda之后推出一种官方生成更好视频处理技术nvenc. 网上相关资料很少, 也不知道这个东西到底怎么样,自己测 ...

  6. appium for mac 安装与测试ios说明

    一.安装 安装dmg,可以自己下载appium-1.4.0.dmg或者找rtx我要,文件过大不能添加附件. Appium提供了一个doctor,运行appium-doctor 如果有问题,Fix it ...

  7. Faste R-CNN的安装及测试

    一.拉取源码 下载 fast-rcnn 因下载解压后 caffe-fast-rcnn是空文件夹,故需要单独下 caffe-fast-rcnn-bcd9b4eadc7d8fbc433aeefd564e8 ...

  8. Faster R-CNN的安装及测试(Python版本和Matlab版本)

    rbg的Python版本 一.拉取源码 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 拉取完成后,在/h ...

  9. Eclipse JPBC library安装及测试

    Eclipse JPBC library安装及测试 资源下载路径: 安装配置: JPBC库是一个功能很强大的数学库,用于生成椭圆曲线,双线性等,但网上参考资料很少,重复度极高,该分栏用于安装,JPBC ...

最新文章

  1. 用linux构建路由器
  2. 教你50招提升ASP.NET性能(十五):解决性能问题时不要低估UI的价值
  3. 为什么刹车热了会失灵_网曝比亚迪汉“刹车失灵”,比亚迪称:是IPB模块仪表显示问题...
  4. 深度学习之基于DCGAN实现手写数字生成
  5. instanceof关键字
  6. 如何使用Hibernate将PostgreSQL枚举映射到JPA实体属性
  7. python实现胶囊网络_胶囊网络 -- Capsule Networks
  8. clob mybatis_spring + mybatis 存取clob
  9. series、dataframe转为tensor格式数据
  10. 单点登录解决方案-CAS
  11. 深入C++的new(2011-11-15 15:08 )
  12. 计算机图标制作教程,电脑主题ICO图标制作方法 详细教程你一学就会
  13. 【Spring练习】Spring+SpringMVC+JdbcTemplate简单练习用户管理
  14. 史上最全微信域名防封API原理及实现方案
  15. 数字信号常用典型序列(1)
  16. 伊斯坦布尔之旅第一天:蓝色清真寺和圣索菲亚博物馆
  17. 隐藏和isa :进化返祖以及白马非马(c++)
  18. RTKLIB基础函数等
  19. springboot利用官方SDK(wechatpay-apache-httpclient)接入微信支付V3
  20. BUCT c语言程序设计基础第三篇10~20道题(上)

热门文章

  1. Python数据结构20:动态规划:找零兑换问题的动态规划解法并显示使用的硬币组合
  2. 【转】2023年Java学习路线图-黑马程序员
  3. JQuery获取选中的元素(单选框复选框)及其他等
  4. c#字符型转化为asc_C#中使用强制类型实现字符串和ASCII码之间的转换
  5. 如何查询计算机com口使用
  6. 数据仓库数据存储与处理
  7. OWASP A4 使用已知漏洞的插件
  8. xls打开显示无法在计算机上运行,电脑无法运行Excel提示不是有效Win32应用程序修复方法...
  9. Excel 2010 VBA 入门 031 批量生成上标
  10. GitLab——提交合并请求