How to run mosquitto mqtt broker on openshift onli

2020-03-31 07:07发布

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:

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?

2条回答
够拽才男人
2楼-- · 2020-03-31 07:54

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.

查看更多
叛逆
3楼-- · 2020-03-31 08:04

In case anyone else runs across this post; I have a non-websocket Mosquitto running on OpenShift v3.11: https://github.com/john2exonets/OpenShift-MQTT-Mosquitto

查看更多
登录 后发表回答