CentOS 7 As MQTT Server

by AmruthKumarSala in Circuits > Linux

3207 Views, 2 Favorites, 0 Comments

CentOS 7 As MQTT Server

centos 7.png
CDR-3021-1M1-480x480.png
frc.png
internet-42584_960_720.png
APC-BR1500GI-image.png

An important aspect of an "Industrial Internet of Things (IIoT)" is to have the data captured from different sensors, posted to an MQTT server for further analysis. The data will also help application developers build machine learning algorithms that would help automate different tasks in the industry.

A prerequisite for the IT Infrastructure Administrator can be to have some hands-on installing and managing Linux servers. CentOS Minimal installation comes only with a Character User Interface and Linux commands will definitely help the install, configure and manage the server with MQTT protocol.

Supplies

To conduct CentOS 7.0 installation, we will need the following:

  1. Physical/Virtual machine
  2. With a redundant power supply
  3. A redundant network interface card
  4. Dedicated Internet connectivity.
  5. This class of servers will also need to be backed by an Uninterrupted Power Supply.
  6. It is also suggested that the installation of the CentOS server be performed with minimal packages.

Note: The minimal installation will help reduce resources utilization due to additional and unnecessary networking services that will start in the case of an OS installation with a fully functional GUI.

CentOS 7.0 - Network Configuration

01.png
02.png
03.png
04.png
05.png
06.png
07.png
08.png
09.png
10.png
11.png

The reader of this article may ignore this step if they are trying to make use of an existing server with CentOS 7 operating system installed on it.

The foremost configuration (In the case of a new machine) is to have the machine's network interface configured. The attached screenshots will help us understand the process of manually configuring an IP address. For this demonstration, I am using a new VM, hence this article will also include the basic network configuration required to let the machine be accessed by the IIoT device (A smart switch integrated with AM2305 Digital Temperature & Humidity Sensor)

It is also to be noted that IT Infrastructure Administrator needs to get all the details of the IP address from his/her ISP, in case the server is planned to be deployed for access via a Public IP address. Following is the step by step procedure:

  1. Power on the VM from its remote console configured in VMware Workstation
  2. Let the machine (VM) completely boot and prompt for user credentials.
  3. Enter root (administrator) credentials to access the system.
  4. Check the "NetworkManager" service and the IP address.
    • systemctl status NetworkManager
    • ip addr
  5. Edit the Network Interface configuration file (/etc/sysconfig/network-scripts/ifcfg-ens160) & make necessary changes to the configuration file (IP address details assigned by your ISP):
    • BOOTPROTO=static
    • Remove all the configuration lines starting with IPV6_
    • ONBOOT=yes
    • IPADDR= (***)
    • NETMASK= (***)
    • GATEWAY= (***)
    • DNS1= (***)
    • DNS2= (***)
  6. Restart the "network" service for changes to be applied: "systemctl restart network"
  7. Check if the IP address is properly assigned: "ip addr"
  8. Check if the machine is able to communicate to the Internet by executing "ping google.com -c 4"
  9. Install the net-tools package using yum package manager. "yum install net-tools -y"
  10. Stop & disable the "NetworkManager" service. Check for its status.
    • systemctl stop NetworkManager
    • systemctl disable NetworkManager
    • systemctl status NetworkManager

***: Assigned by ISP, or Network Administrator

Required Packages and SSH Access

12.png
13.png
14.png
15.png
16.png

There are a few packages that will help the future configurations of MQTT and the following are the few packages that are useful:

  1. net-tools: yum install net-tools -y
  2. Access the machine via SSH using tools such as PuTTY.
  3. EPEL Release: yum install epel-release -y
  4. Install Mosquitto: yum install mosquito -y

There is one more step before we move to the next phase of explanation, which is to start the "mosquito" service and enable it

  1. systemctl start mosquitto
  2. systemctl status mosquitto
  3. systemctl enable mosquitto

Testing Mosquitto Installation

17.png
18.png
19.png

Now that the mosquitto service is started & enabled, it is time we test for its functionality on the localhost. To conduct this test, we will need two SSH terminals one to execute: "mosquitto_sub" and the other to execute "mosquitto_pub" commands

Securing "mosquitto"

20.png
21.png
22.png
23.png
24.png
25.png
26.png

Security remains a top priority to any IT Infrastructure Administrator and it is very much advisable to have an authorized user to have to give access to allow data logged onto the server.

Allow Data Via Firewall Port: 1883 and Service: Mqtt

27.png
28.png
29.png
30.png

Allow port "1883" and service "mqtt" to pass through the firewall and test it with third-party tools such as "MQTT Explorer"

  1. firewall-cmd --zone=public --permanent --add-port=1883/tcp
  2. firewall-cmd --zone=public --permanent --add-service=mqtt
  3. firewall-cmd --reload
  4. firewall-cmd --zone=public --permanent --list-ports

For successful capture of data to third-party tools such as "MQTT Explorer", CentOS 7 machine may be required to be configured with "httpd" service. In such a case the IT Infrastructure Administrator is advised to let the connected port and service pass through the firewall.

I now intend to move to the next levels by porting this application to production environments.

I wish to collaboratively work and readers of this article can either reach me on amruth@smaragdine.work (or) ping me on WhatsApp on +91 9398472594 to collaboratively work.