前言
博主之前写了一篇《在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
可以查看帮助
***@***-virtual-machine:~/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。
***@***-virtual-machine:~/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 :
***@***-virtual-machine:~/Downloads/apache-apollo-1.7.1/bin$ ./mybroker/bin/apollo-broker run
之后查看打印信息即可知道MQTT要连接的端口和管理页面端口。
结束。
本文首发于CSDN:http://blog.csdn.net/yannanxiu/article/details/70504586