前言
博主之前寫了一篇《在Windows下搭建MQTT服務器》,這次要嘗試在Ubuntu下搭建MQTT服務器。實際上,下載好源碼包後,後面的都和那篇文章差不多了。
開發環境
- 虛擬機 Ubuntu 14.04.5 LTS
- Apache-Apollo-1.7.1
準備工作
由於搭建Apollo環境變量需要有JAVA_HOME
,這個時候需要安裝JDK,可以參考這篇文章:《Ubuntu安裝JDK1.8.0並配置環境變量》。
下載及解壓
首先是下載Apache-Apollo,下載頁面:http://www.apache.org/dyn/closer.cgi?path=activemq/activemq-apollo/1.7.1/apache-apollo-1.7.1-unix-distro.tar.gz
或者輸入下面命令:
wget http://apache.fayea.com/activemq/activemq-apollo/1.7.1/apache-apollo-1.7.1-unix-distro.tar.gz
解壓源碼包:
tar -zxvf apache-apollo-1.7.1-unix-distro.tar.gz
配置
進入apache-apollo-1.7.1/bin目錄
cd apache-apollo-1.7.1/bin/
輸入./apollo
可以查看幫助
pi@raspberry-pi:~/Downloads/apache-apollo-1.7.1/bin$ ./apollo
usage: apollo [--log <log_level>] <command> [<args>]
The most commonly used apollo commands are:
create creates a new broker instance
disk-benchmark Benchmarks your disk's speed
help Display help information
version Displays the broker version
See 'apollo help <command>' for more information on a specific command.
創建一個Broker示例:/apollo create mybroker
。MQTT服務器都是叫Broker。
pi@raspberry-pi:~/Downloads/apache-apollo-1.7.1/bin$ ./apollo create mybroker
Creating apollo instance at: mybroker
Generating ssl keystore...
You can now start the broker by executing:
"/home/***/Downloads/apache-apollo-1.7.1/bin/mybroker/bin/apollo-broker" run
Or you can setup the broker as system service and run it in the background:
sudo ln -s "/home/***/Downloads/apache-apollo-1.7.1/bin/mybroker/bin/apollo-broker-service" /etc/init.d/
/etc/init.d/apollo-broker-service start
後面會有提示怎麼啓動服務器,以及創建一個service。
啓動Apollo :
pi@raspberry-pi:~/Downloads/apache-apollo-1.7.1/bin$ ./mybroker/bin/apollo-broker run
之後查看打印信息即可知道MQTT要連接的端口和管理頁面端口。
結束。