關閉防火牆(可選):
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端口
(可參考官方文檔)