Centos7.2 搭建emqttd集羣,添加自啓動服務

關閉防火牆(可選):
systemctl stop firewalld.servicehtml

1.安裝依賴庫
> sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-develnode

2.獲取源碼包
> wget http://www.erlang.org/download/otp_src_R13B04.tar.gzlinux

3.解壓、編譯、安裝
> tar xfvz otp_src_R13B04.tar.gz
> cd otp_src_R13B04/
> ./configure --with-ssl
> make installc++

4.可能遇到的錯誤
http://blog.csdn.net/laughing_cui/article/details/53322790shell

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/windowsmacos

6.Linux服務器安裝(以Centos爲例)
wget http://emqtt.com/docs/v2/install.html#linux
一、解壓縮包(能夠官網下載)
> unzip emqttd-centos64-1.1-beta-20160601.zipubuntu

二、控制檯調試模式啓動,檢查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>vim

CTRL+c關閉控制檯。守護進程模式啓動:
> ./bin/emqttd startwindows

emqttd消息服務器進程狀態查詢:
> ./bin/emqttd_ctl statuscentos

正常運行狀態,查詢命令返回:
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端口

(可參考官方文檔)

相關文章
相關標籤/搜索