Centos7.2 搭建emqttd集群,添加自启动服务

关闭防火墙(可选):
systemctl stop firewalld.service

1.安装依赖库
> sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

2.获取源码包
> wget http://www.erlang.org/download/otp_src_R13B04.tar.gz

3.解压、编译、安装
> tar xfvz otp_src_R13B04.tar.gz
> cd otp_src_R13B04/
> ./configure --with-ssl
> make install

4.可能遇到的错误
http://blog.csdn.net/laughing_cui/article/details/53322790

5.emqttd程序包下载
Debian http://emqtt.com/downloads/latest/debian
Ubuntu http://emqtt.com/downloads/latest/ubuntu
CentOS http://emqtt.com/downloads/latest/centos
FreeBSD http://emqtt.com/downloads/latest/freebsd
Mac OS X http://emqtt.com/downloads/latest/macosx
Windows http://emqtt.com/downloads/latest/windows

6.Linux服务器安装(以Centos为例)
wget http://emqtt.com/docs/v2/install.html#linux
1、解压缩包(可以官网下载)
> unzip emqttd-centos64-1.1-beta-20160601.zip

2、控制台调试模式启动,检查emqttd是否可正常启动:
> vim /opt/emqttd/etc/emq.conf
修改node.name = emqttd@172.30.60.3
> cd /opt/emqttd
> ./bin/emqttd console
emqttd消息服务器如启动正常,控制台输出:
starting emqttd on node 'emqttd@127.0.0.1'
emqttd ctl is starting...[done]
emqttd trace is starting...[done]
emqttd pubsub is starting...[done]
emqttd stats is starting...[done]
emqttd metrics is starting...[done]
emqttd retainer is starting...[done]
emqttd pooler is starting...[done]
emqttd client manager is starting...[done]
emqttd session manager is starting...[done]
emqttd session supervisor is starting...[done]
emqttd broker is starting...[done]
emqttd alarm is starting...[done]
emqttd mod supervisor is starting...[done]
emqttd bridge supervisor is starting...[done]
emqttd access control is starting...[done]
emqttd system monitor is starting...[done]
http listen on 0.0.0.0:18083 with 4 acceptors.
mqtt listen on 0.0.0.0:1883 with 16 acceptors.
mqtts listen on 0.0.0.0:8883 with 4 acceptors.
http listen on 0.0.0.0:8083 with 4 acceptors.
Erlang MQTT Broker 1.1 is running now
Eshell V6.4 (abort with ^G)
(emqttd@127.0.0.1)1>

CTRL+c关闭控制台。守护进程模式启动:
> ./bin/emqttd start

emqttd消息服务器进程状态查询:
> ./bin/emqttd_ctl status

正常运行状态,查询命令返回:
Node 'emqttd@127.0.0.1' is started
emqttd 1.1 is running

部署好EMQ之后,访问URL地址:http://172.30.60.3:18083 ,缺省用户名/密码: admin/public

停止服务器:
> ./bin/emqttd stop

 


节点加入集群(有两种集群添加方式:IP(推荐)和主机域名):

主机域名举例:
首先修改主机名,加入主机名.域名
vim /etc/hosts
例如:
127.0.0.1 s1 s1.emqtt.io
172.30.60.30 s1 s1.emqtt.io(第一台)
172.30.60.37 s2 s2.emqtt.io(第二台)
172.30.60.22 s3 s3.emqtt.io(第三台)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

然后修改配置文件emq.conf
node.name=emq@主机名.域名

然后启动emqttd
emqttd>bin/emqttd start

最后节点加入集群
emqttd>./bin/emqttd_ctl cluster join emqttd@s1.emqtt.io

查看集群状态
emqttd>./bin/emqttd_ctl cluster status

节点退出集群:
./bin/emqttd_ctl cluster leave
或emqttd@s1.emqtt.io节点上,从集群删除emqttd@s2.emqtt.io节点:
./bin/emqttd_ctl cluster remove emqttd@s2.emqtt.io

 

emqttd开机自启动:
在此目录下面新建文件emqttd.service
vim /usr/lib/systemd/system/emqttd.service

加入配置文件
[Unit]
Description=emqttdapi
After=network.target
[Service]
Type=forking
Environment=HOME=/opt/emqttd
ExecStart=/opt/emqttd/bin/emqttd start
ExecReload=/opt/emqttd/bin/emqttd reboot
ExecStop=/opt/emqttd/bin/emqttd stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

最后执行命令
systemctl enable emqttd.service

集群间需要开端口:监听端口、配置文件emq.conf里面的端口区间、4369端口

(可参考官方文档)

posted @ 2018-02-10 10:41  愤怒的小鸟强  阅读(3926)  评论(0编辑  收藏  举报