如何在OpenShift在线上运行mosquitto MQTT经纪人 [英] How to run mosquitto mqtt broker on openshift online

查看:120
本文介绍了如何在OpenShift在线上运行mosquitto MQTT经纪人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在 mosquitto .com/"rel =" nofollow noreferrer>免费帐户中的openshift在线版本?

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:

  • "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:

  • 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_TLSWITH_TLS_PSKWITH_THREADINGWITH_BRIDGEWITH_SRVWITH_UUIDWITH_DOCSWITH_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之间的脱节.
  • 安装libwebsocketslibwebsockets-devel软件包.
  • 运行make来构建蚊子.
  • 假设您要将mosquitto安装到../mosrun目录.创建目录.运行make prefix= DESTDIR=$(pwd)/../mosrun install.
  • 删除../mosrun下除sbin以外的所有文件夹. cd ../mosrun/sbincp /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 websocketshttp_dir simplewebconnection_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 port 8000 and that is routed to internal port 8080 on an virtual IP address specified by OPENSHIFT_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 from DOCSDIR. This seems to be a minor bug in mosquitto because if the WITH_DOCS is turned off it should not try to install from DOCSDIR.
  • Turn on WITH_WEBSOCKETS in config.mk.
  • Modify the file src/webockets.c. In the function mosq_websockets_init() at about line 625, add a line of info.iface = listener->host;, below the line which is info.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 to 0.0.0.0 for any IP address. This seems to be a disconnection between mosquitto and libwebosockets.
  • Install libwebsockets and libwebsockets-devel packages.
  • Run make to build mosquitto.
  • Lets assume you want to install mosquitto to ../mosrun directory. Create the directory. Run make prefix= DESTDIR=$(pwd)/../mosrun install.
  • Delete all folders under ../mosrun except sbin. cd ../mosrun/sbin and cp /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 your mosrun/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, and connection_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.jsmosquitto.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帖子对指导您完成构建蚊子的步骤非常有帮助:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆