How to run mosquitto mqtt broker on openshift online

喜你入骨 提交于 2019-12-04 02:24:00

问题


Has anybody successfully run mosquitto on the openshift online version in a free account?

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.

What is the exact steps to put mosquitto to run on the openshift from here?


回答1:


Finally I got it working on openshift, though with a simplest configuration. Here is the key steps:

  • 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.

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 posts are very helpful to guide you through the steps of building mosquitto: the blog by jpman, and the blog by Jeremy Gooch.



来源:https://stackoverflow.com/questions/37383603/how-to-run-mosquitto-mqtt-broker-on-openshift-online

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!