如何在OpenShift在线上运行mosquitto MQTT经纪人 [英] How to run mosquitto mqtt broker on openshift online
问题描述
有人在
Has anybody successfully run mosquitto on the openshift online version in a free account?
有两个相关的SO问题,但不能真正解决所有问题:
There are two SO questions relevant but not really solve all the questions:
- 如何在Openshift中连接到我的MQTT代理" .它运行JBoss Fuse,并且需要服务器上的SNI功能或客户端上的端口转发.
- 如何通过Openshift访问套接字" 一个>.作者提到了运行蚊子,但是没有关于如何运行的详细信息.
- "How to connect to my MQTT Broker in Openshift". It runs JBoss Fuse and needs either the SNI feature on the server or the port-forwarding on the client.
- "How can I access socket through Openshift". The author mentions running mosquitto but there is no details as to how.
到目前为止已完成的工作:
Stuffs that have been done so far:
- 我已经运行了python websocket服务器,因此可以验证openshift确实可以通过DIY盒很好地支持websocket.
- 我还编译了mosquitto并使用不在github .
- I have run a python websocket server thus to have verified openshift does support websocket nicely though the DIY cartridge.
- I have also compiled mosquitto and run it locally with a sample off github.
从此处开始将mosquitto置于openshift上的确切步骤是什么?
What is the exact steps to put mosquitto to run on the openshift from here?
推荐答案
最后,尽管使用了最简单的配置,但我还是将其用于openshift.这是关键步骤:
Finally I got it working on openshift, though with a simplest configuration. Here is the key steps:
- 使用openshift
DIY
盒式磁带获得Websocket支持,该支持公开外部端口8000
,并路由到OPENSHIFT_DIY_IP
指定的虚拟IP地址上的内部端口8080
. - 编译mosquitto,并在
config.mk
中关闭以下所有功能,以避免为openshift安装大量软件包:WITH_TLS
,WITH_TLS_PSK
,WITH_THREADING
,WITH_BRIDGE
,WITH_SRV
,WITH_UUID
,WITH_DOCS
,WITH_SOCKS
. - 修改mosquitto的
Makefile
,以注释掉从DOCSDIR
安装的命令.这似乎是mosquitto中的一个小错误,因为如果WITH_DOCS
已关闭,则不应尝试从DOCSDIR
安装. - 打开
config.mk
中的WITH_WEBSOCKETS
. - 修改文件
src/webockets.c
.在函数mosq_websockets_init()
的第625行左右,在info.user = user;
的行下方添加info.iface = listener->host;
的行.这是为了使蚊子能够绑定到openshift DIY设备中的虚拟IP地址.默认情况下,mosquitto仅允许您绑定任何IP地址的0.0.0.0
.这似乎是mosquitto和libwebosockets之间的脱节. - 安装
libwebsockets
和libwebsockets-devel
软件包. - 运行
make
来构建蚊子. - 假设您要将mosquitto安装到
../mosrun
目录.创建目录.运行make prefix= DESTDIR=$(pwd)/../mosrun install
. - 删除
../mosrun
下除sbin
以外的所有文件夹.cd ../mosrun/sbin
和cp /usr/lib/libwebsockets.so.7 .
.调整库存libwebsockets lib的源路径. - 从
https://github.com/jpmens/simple-mqtt-websocket-example
中获取所有文件.将它们放入您的mosrun/sbin/simpleweb
目录. - 修改
mosrun/sbin/simpleweb/config.js
以使用您的openshift DIY域名和端口8000.这是javascript从浏览器连接到您的DIY服务器的位置. - 创建一个包含四行的mosquitto配置文件
mosrun/sbin/mosquitto.conf
:listener 8080 <OPENSHIFT_DIY_IP>
,protocol websockets
,http_dir simpleweb
和connection_messages
.使用实际的DIY虚拟IP地址代替<OPENSHIFT_DIY_OP>
. - 将整棵树复制到您的openshift DIY齿轮上.
- 使用浏览器从浏览器浏览到您的DIY域,这样您将看到默认的服务器页面.
- 修改openshift
.openshift/action_hooks/start
和.../stop
脚本以注释掉现有命令.推动开档.现在,您应该无法连接到默认服务器,但是设备正在运行. - 进入您的蚊子
mosrun/sbin
目录. - 运行
LD_LIBRARY_PATH=. ./mosquitto -c mosquitto.conf -v
启动蚊子. - 浏览到您的
diy-yourdomain.rhcloud.com:8000/index.html
.您将看到从jpmen的github存储库复制的mqtt websockets测试页.
- Use an openshift
DIY
cartridge to get the websocket support which exposes external port8000
and that is routed to internal port8080
on an virtual IP address specified byOPENSHIFT_DIY_IP
. - Compile mosquitto with all the following features turned off in
config.mk
just to avoid installing lot of packages to openshift:WITH_TLS
,WITH_TLS_PSK
,WITH_THREADING
,WITH_BRIDGE
,WITH_SRV
,WITH_UUID
,WITH_DOCS
,WITH_SOCKS
. - Modify the
Makefile
of mosquitto to comment out the command to install fromDOCSDIR
. This seems to be a minor bug in mosquitto because if theWITH_DOCS
is turned off it should not try to install fromDOCSDIR
. - Turn on
WITH_WEBSOCKETS
inconfig.mk
. - Modify the file
src/webockets.c
. In the functionmosq_websockets_init()
at about line 625, add a line ofinfo.iface = listener->host;
, below the line which isinfo.user = user;
. This is to make mosquitto able to bind to the virtual IP address in the openshift DIY gear. By default mosquitto only allow you to bind to0.0.0.0
for any IP address. This seems to be a disconnection between mosquitto and libwebosockets. - Install
libwebsockets
andlibwebsockets-devel
packages. - Run
make
to build mosquitto. - Lets assume you want to install mosquitto to
../mosrun
directory. Create the directory. Runmake prefix= DESTDIR=$(pwd)/../mosrun install
. - Delete all folders under
../mosrun
exceptsbin
.cd ../mosrun/sbin
andcp /usr/lib/libwebsockets.so.7 .
. Adjust the source path of your stock libwebsockets lib. - Grab all the files from
https://github.com/jpmens/simple-mqtt-websocket-example
. Put them into yourmosrun/sbin/simpleweb
directory. - Modify
mosrun/sbin/simpleweb/config.js
to use your openshift DIY domain name, and port 8000. This is where the javascript connects to your DIY server from a browser. - Create a mosquitto configuration file
mosrun/sbin/mosquitto.conf
which contains four lines:listener 8080 <OPENSHIFT_DIY_IP>
,protocol websockets
,http_dir simpleweb
, andconnection_messages
. Use your actual DIY virtual IP address in place of<OPENSHIFT_DIY_OP>
. - Copy the whole tree to your openshift DIY gear.
- Browse with a browser to your DIY domain from a browser so you'll see the default server page.
- Modify openshift
.openshift/action_hooks/start
and.../stop
scripts to comment out the existing commands. Push to openshift. Now you should not be able to connect to the default server but the gear is running. - Go into your mosquitto
mosrun/sbin
directory. - Run
LD_LIBRARY_PATH=. ./mosquitto -c mosquitto.conf -v
to start mosquitto. - Browse to your
diy-yourdomain.rhcloud.com:8000/index.html
. You shall see the mqtt websockets test page copied from jpmen's github repo.
下一步是将树移动到DIY git树中.修改启动和停止钩子,以启动和停止您的蚊子而不是默认服务器.还有一个在openshift齿轮上运行的脚本,用于根据实际openshift环境变量创建config.js
和mosquitto.conf
.
The next step would be to move the tree into DIY git tree. Modify the start and stop hooks to start and stop your mosquitto instead of the default server. And a script running on the openshift gear to create the config.js
and mosquitto.conf
from the actual openshift environment variables.
Tow帖子对指导您完成构建蚊子的步骤非常有帮助:杰里米·古奇(Jeremy Gooch)的博客.
Tow posts are very helpful to guide you through the steps of building mosquitto: the blog by jpman, and the blog by Jeremy Gooch.
这篇关于如何在OpenShift在线上运行mosquitto MQTT经纪人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!