Skip to content

Commit

Permalink
doc: wrote readme
Browse files Browse the repository at this point in the history
  • Loading branch information
opatiny committed Jun 18, 2020
1 parent f4aa383 commit db19c4d
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
## mqtt
# bioreactor-docker

The goal of this project is to create a fast setup of a docker mqtt broker in javascript.
This project is the dockerization of [Hackuarium/nodered-bioreactor-gui](https://github.com/Hackuarium/nodered-bioreactor-gui).

In this project we are using 4 diffent docker images:
* node-red
* mosca
* mongo
* influxdb
### Install docker

## setup a new server
```bash
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-\$(uname -m) -o /usr/local/bin/docker-compose
```

This documentation is for a CentOS 7.x
## Starting the project

### Install docker
Once you cloned the project, you can simply go to the folder and run:

curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
```bash
docker-compose up
```

### Install iptables
## Stopping the project

Add the following rule in iptables:
`-A INPUT -p tcp -m tcp -m multiport --dports http,https,1883 -j ACCEPT`
You might want to do this if you pull some changes from the cloud, then start again.

### Using an apache proxy
```bash
docker-compose down
```

Using an apache proxy allows to play with the hostname.
## Docker images

vi /etc/httpd/conf.d/mqtt.conf
```
<VirtualHost *:80>
ServerName mqtt.beemos.org
ProxyRequests off
ProxyPreserveHost on
ProxyPass "/comms" "ws://localhost:1880/comms"
ProxyPassReverse "/comms" "ws://localhost:1880/comms"
ProxyPass "/" "http://localhost:1880/"
ProxyPassReverse "/" "http://localhost:1880/"
</VirtualHost>
```
We had to install three different docker images in the project:

### Starting the server
- Node-red
- Mosquitto
- InfluxDB

`docker-compose up -d`
The images are installed (or built) thanks to the configuration in the `docker-compose.yml` file. The images were found on [Docker Hub](https://hub.docker.com/).

## Testing
### Node-Red

Source image: `nodered/node-red`

The node-red image has to be built because we add some packages to it (all the dependencies of the `nodered-bioreactor-gui). All the packages are added in the file`node-red/Dockerfile`.

## Some other tools
### Mosquitto

Source image: `eclipse-mosquitto`

Node-red will save all the data in the folder `node-red/data`
### InfluxDB

Using GRAFANA for output: https://www.hackster.io/naresh-krish/visualizing-lora-node-data-with-node-red-and-grafana-8960d3
Source image: `influxdb`

http://localhost:1880/
The node-red graphical interface of the bioreactor requires some influxDB databases to be already existing. We create these databases, as well as the continuous queries in the file `influxdb/init/startup.iql`.

The UI
The data of the database is in `influxdb/db/`.

http://localhost:1880/ui/
Connect to influxdb for debug:

mosquitto_pub --retain -t "random" -m $RANDOM
```bash
docker-compose exec influxdb bash
```

Add continously data:
`while true; do mosquitto_pub --retain -t "random" -m $RANDOM; sleep 2; done`
## Deployment machine

## Mosquitto
## Docker folder

Test MQTT server using mosquitto
Docker is in `/usr/local/docker`. This is where the project is cloned.

mosquitto_pub --retain -m "Test" -t "abcd/efgh"
## Proxy

mosquitto_sub -h "localhost" -t "abcd/efgh"
**Apache** was used.

There is only one port accessible from the internet: HTTPS - port 443. Many services, which work on various ports, run behind this one entry point. This is why you have to configure a proxy, which will redirect queries to the correct services. In our case, we want to redirect [https://bioreactor.hackuarium.org]() to [http://localhost:1880]().

## Connect to influxdb for debug
The proxy config file is: `etc/httpd/conf.d`.

`docker-compose exec influxdb bash`
`influx -username user -password user`
The code underneath is what should be used as the configuration of port 443:

`show databases`
`use data`
`select * from random`
```
<VirtualHost *:443>
Use SSLConf bioreactor.hackuarium.org
ServerName bioreactor.hackuarium.org
## Problems with Fedora 31
ProxyRequests Off
ProxyPreserveHost On
https://github.com/docker/for-linux/issues/219
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://localhost:1880/$1 [P,L]
$ sudo dnf install -y grubby
$ sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
$ sudo reboot
ProxyPass / http://localhost:1880/
ProxyPassReverse / http://localhost:1880/
</VirtualHost>
```

0 comments on commit db19c4d

Please sign in to comment.