by Ranjith Kumar DSM | Jul 09, 2018 | MQTT Broker | 0 comments
Docker is one of the leading container applications that is used most widely for running a well managed deployment environment. Docker MQTT Broker will help you have more control over your IoT production environment. Most than 60% of the servers are using either Ubuntu / Debian for their hosting
We recommend MySQL to be run on a physical machine than a container for the data persistence purpose. Follow the below instructions to set up the MySQL. You have to install the MySQL Server first.
$ sudo apt-get update
$ sudo apt-get install -y mysql-server-5.7
Modify the MySQL configuration. By default the mysql runs at 127.0.0.1 and allows only the local application to connect to it. You have to change it as 0.0.0.0 for application running on containers and other machines to access the MySQL.
$ gedit /etc/mysql/my.cnf
bind-address = 0.0.0.0
Restart the MySQL for the changes to take effect.
$ sudo service mysql restart
Providing data access. The root user of MySQL has access only form the local machine to read and write data into the databases. We need to allow the root user to access data from the container. Connect to the MySQL console from the localhost and then execute the following queries.
$ mysql -u root -p
Enter password: <provide your password here>
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES
Your MySQL server is all set to connect from any container that runs on your Ubuntu server.
Docker needs to be installed in your ubuntu to create the docker image of the MQTT Broker and also run the dockerized MQTT Broker. To install the Docker, run the following command.
$ apt-get install docker.io
Download the Linux version of the MQTT Broker and Extract it from your /home/ubuntu folder. If you are extracting the archive from some other folder, make sure you use the right reference folder
We will be creating a docker image in the name of mqttroute. Create a directory for creating the docker file.
$ mkdir /home/ubuntu/mqttroute
Copy files of the MQTT Broker to the mqttroute folder.
$ cp -rf /home/ubuntu/Bevywise/MQTTRoute/* /home/ubuntu/mqttroute/
Modify the configuration of the MQTT Broker for MySQL connections
$ cd /home/ubuntu/mqttroute/
$ gedit conf/data_store.conf
DB_SERVER = MYSQL
DBHOST=<mysql host ip>
MYSQL_USER= <your mysql user>
MYSQL_PASSWORD = <mysql db password>
Create the mount folder where the docker images will be mounted.
$sudo mkdir /bin/mqtt
Create the docker file
$ gedit Dockerfile
COPY . /bin/mqtt
CMD [“sh”, “/bin/mqtt/bin/runbroker.sh”]
Build the docker image
# docker build -t mqttroute .
# docker images
root@ubuntu # docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mqtt latest 45f7ee9a1ec7 7 seconds ago 81.15 MB
ubuntu latest 7feff7652c69 4 weeks ago 81.15 MB
Start using the docker command. The following command will run the MQTT Broker as a daemon process. If you are planning to run MQTT Broker in a secure mode, you can refer to our previous blog on ssl certificate creation and placement of the files inside the MQTT Broker.
$ docker run – –restart=always -d -p 8080:8080 -p 1883:1883 -p 10433:10433 mqttroute
Download now to set up your own Docker MQTT Broker.
Feel free to contact support for any questions or feedback.
Must Read Other Related Post
Please take a moment to fill this form