Install EMQX MQTT Broker on Rocky Linux 8|AlmaLinux 8

MQTT broker is a lightweight message exchange protocol that makes use of the publish-subscribe pattern. That is to say, the MQTT broker receives the message published by clients, filters them according to topics, and distributes them to the subscribers. EMQX is an open-source, elastic MQTT message broker written in Erlang.
EMQX is suitable for massive clients with fast and low message latency routing. It is highly preferred due to the following:
- Distributed cluster: fast and low-latency message routing, and single-cluster supports tens of thousands of routes.
 - Stable to host large-scale MQTT client connections with a single server node supporting 2 million connections.
 - Comprehensive IoT protocol support that includes MQTT, MQTT-SN, CoAP, LwM2M, and other TCP/UDP based proprietary protocol.
 - Higly extensible: supports customized plugins, such as authentication and other functions.
 
The features for EMQX are:
- HTTP message publishing interface support
 - MQTT/WebSocket/SSL support
 - TCP/SSL connection support
 - Client online status query and subscription support
 - Support manual, mcast, dns, etcd, k8s and other cluster discovery methods
 - Redis, MySQL, PostgreSQL, MongoDB, HTTP authentication integration
 - Suppoprts several authentication methods such as LDAP, password e..t.c
 - Full MQTT V3.1/V3.1.1 and V5.0 protocol specification support
 - MQTT Broker bridge support
 - CoAP protocol support
 - MQTT-SN protocol support
 - Configure nodes by partition
 - Connection and message rate limit
 - Automatic network partition healing
 - Multi-server node cluster (Cluster)
 - Access control (ACL) based on client ID, IP address, user name
 
This guide offers an in-depth illustration of how to install EMQX MQTT Broker on Rocky Linux 8|AlmaLinux 8|CentOS Stream 8. The installation methods covered in this guide include:
- Using script automated way
 - Installing from YUM repository
 - Running in a Docker container
 
Getting Started.
Before we dive into the nub, it is highly recommended that you update the system packages to their latest stable versions.
sudo yum update -y
You will also need some other packages installed with the below command:
sudo yum install curl vim
Install EMQX MQTT Broker on Rocky Linux 8|AlmaLinux 8|CentOS Stream 8
This guide takes a deep dive into demonstrating each of the outlined installation methods.
Method 1 – One-click installation of shell script
There is an automated way to install EMQX on Linux systems. This makes it so easy to install EMQX MQTT Broker on Rocky Linux 8|AlmaLinux 8|CentOS Stream 8.
Download and run the script with the command:
curl https://repos.emqx.io/install_emqx.sh | sudo bash
Sample Output:
Adding repo from: https://repos.emqx.io/emqx-ce/redhat/centos/8/emqx-ce.repo
emqx-stable                                     1.0 MB/s | 819 kB     00:00    
Dependencies resolved.
================================================================================
 Package      Architecture   Version               Repository              Size
================================================================================
Installing:
 emqx         x86_64         4.3.5-1.el8           emqx-ce-stable          22 M
Transaction Summary
================================================================================
....
Running transaction
  Preparing        :                                                        1/1 
  Running scriptlet: emqx-4.3.5-1.el8.x86_64                                1/1 
  Installing       : emqx-4.3.5-1.el8.x86_64                                1/1 
  Running scriptlet: emqx-4.3.5-1.el8.x86_64                                1/1 
Created symlink /etc/systemd/system/multi-user.target.wants/emqx.service → /usr/lib/systemd/system/emqx.service.
  Verifying        : emqx-4.3.5-1.el8.x86_64                                1/1 
Installed products updated.
Installed:
  emqx-4.3.5-1.el8.x86_64                                                       
Complete!
EMQ X install success
Start and enable the service.
sudo systemctl start emqx && sudo systemctl enable emqx
Check the status of the service.
$ systemctl status emqx
● emqx.service - emqx daemon
   Loaded: loaded (/usr/lib/systemd/system/emqx.service; enabled; vendor preset>
   Active: active (running) since Sun 2022-03-06 04:20:10 EST; 4s ago
 Main PID: 3044 (run_erl)
    Tasks: 36 (limit: 23544)
   Memory: 116.1M
   CGroup: /system.slice/emqx.service
           ├─3044 /usr/lib/emqx/erts-11.1.8/bin/run_erl -daemon //var/lib/emqx/>
           ├─3073 emqx -P 2097152 -Q 1048576 -e 256000 -spp true -A 4 -IOt 4 -S>
           ├─3352 erl_child_setup 1048576
           ├─3402 sh -s disksup
           ├─3403 /usr/lib/emqx/lib/os_mon-2.6.1/priv/bin/memsup
           ├─3404 /usr/lib/emqx/lib/os_mon-2.6.1/priv/bin/cpu_sup
           ├─3437 inet_gethost 4
           └─3438 inet_gethost 4
Method 2 – Install EMQX from YUM repository
The EMQX package can as well be installed from the YUM package manager. Begin by installing dependencies.
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Once installed, set up the EMQX repository
sudo yum-config-manager --add-repo https://repos.emqx.io/emqx-ce/redhat/centos/8/emqx-ce.repo
Now install the latest version of EMQX from the repository.
sudo yum install emqx
Sample Output:
Dependencies resolved.
================================================================================
 Package      Architecture   Version               Repository              Size
================================================================================
Installing:
 emqx         x86_64         4.3.5-1.el8           emqx-ce-stable          22 M
Transaction Summary
================================================================================
Install  1 Package
Total download size: 22 M
Installed size: 39 M
Is this ok [y/N]: y
You can as well install a specific version of EMQX. First list the available versions.
$ yum list emqx --showduplicates | sort -r
Installed Packages
emqx.x86_64                     4.3.5-1.el8                      emqx-ce-stable 
emqx.x86_64                     4.3.5-1.el8                      @emqx-ce-stable
emqx.x86_64                     4.3.4-1.el8                      emqx-ce-stable 
.... 
Proceed and install the desired version say 4.3.4
sudo yum install emqx-<version>
Once installed, start and enable the service.
sudo systemctl start emqx && sudo systemctl enable emqx
Check the status of the service.
$ systemctl status emqx
● emqx.service - emqx daemon
   Loaded: loaded (/usr/lib/systemd/system/emqx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-03-06 04:24:27 EST; 7s ago
 Main PID: 32792 (run_erl)
    Tasks: 32 (limit: 36433)
   Memory: 110.8M
   CGroup: /system.slice/emqx.service
           ├─32792 /usr/lib/emqx/erts-11.1.8/bin/run_erl -daemon //var/lib/emqx/emqx_erl_pipes/[email protected]/ /var/log/emqx exec "/usr/bin>
           ├─32814 emqx -P 2097152 -Q 1048576 -e 256000 -spp true -A 4 -IOt 4 -SDio 8 -- -root /usr/lib/emqx -progname usr/bin/emqx -- -hom>
           ├─33067 erl_child_setup 1048576
           ├─33106 sh -s disksup
           ├─33107 /usr/lib/emqx/lib/os_mon-2.6.1/priv/bin/memsup
           ├─33108 /usr/lib/emqx/lib/os_mon-2.6.1/priv/bin/cpu_sup
           ├─33137 inet_gethost 4
           └─33138 inet_gethost 4
Method 3 – Run EMQX in a Docker container
Running EMQX in a docker container is the simplest method of all. For those who want to avoid the tussle of installing dependencies, this is the way to go.
Before you proceed, ensure that Docker is installed on your system. This can be done with the aid of the below guide:
Once Docker is installed, add your system user to the docker group.
sudo usermod -aG docker $USER
newgrp docker
Start and enable docker.
sudo systemctl start docker && sudo systemctl enable docker
Now pull the EMQX image. There are two ways how you can pull the EMQX image.
- From Docker Hub.
 
docker pull emqx/emqx
View the pulled docker image
$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
emqx/emqx    latest    445050b808a9   41 hours ago   193MB
wget -O emqx-docker.zip https://www.emqx.com/en/downloads/broker/v<VERSION-URL>.zip
unzip emqx-docker.zip
docker load < emqx-docker-vVERSION-*
With the image, you can run EMQX in a Docker container. First, create a persistent data path.
sudo mkdir -p /emqx-data/emqx.lic
Set SELinux in permissive mode.
sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
Run EMQX in a docker container using the below command:
docker run -d \
  --name emqx \
  -p 1883:1883 \
  -p 8081:8081 \
  -p 8083:8083 \
  -p 8883:8883 \
  -p 8084:8084 \
  -p 18083:18083 \
  -v /emqx-data/emqx.lic:/opt/emqx/etc/emqx.lic \
  emqx/emqx
Remember to tag the correct image name. Here I have used the emqx/emqx:v4.0.0 docker image
Check the status of the container.
$ docker ps
CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS         PORTS                                                                                                                                                                                                                                                                                              NAMES
b8ed3f30ee24   emqx/emqx:v4.0.0   "/usr/bin/docker-ent…"   7 seconds ago   Up 5 seconds   4369/tcp, 5369/tcp, 6369/tcp, 0.0.0.0:1883->1883/tcp, :::1883->1883/tcp, 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp, 0.0.0.0:8083-8084->8083-8084/tcp, :::8083-8084->8083-8084/tcp, 8080/tcp, 0.0.0.0:8883->8883/tcp, :::8883->8883/tcp, 0.0.0.0:18083->18083/tcp, :::18083->18083/tcp, 11883/tcp   emqx
Manage the container using the commands:
##Stop EMQX
docker stop emqx
##Start EMQX
docker start emqx
Alternatively using Docker-compose, you can also set up a simple static EMQX cluster. Create the docker-compose.yml file
vim docker-compose.yml
Add the below lines to the file:
version: '3'
services:
  emqx1:
    image: emqx/emqx
    environment:
    - "EMQX_NAME=emqx"
    - "EMQX_HOST=node1.emqx.io"
    - "EMQX_CLUSTER__DISCOVERY=static"
    - "[email protected], [email protected]"
    - "EMQX_ZONE__EXTERNAL__RETRY_INTERVAL=2s"
    - "EMQX_MQTT__MAX_TOPIC_ALIAS=10"
    volumes:
        - /emqx-data/emqx.lic:/opt/emqx/etc/emqx.lic
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node1.emqx.io
  emqx2:
    image: emqx/emqx
    environment:
    - "EMQX_NAME=emqx"
    - "EMQX_HOST=node2.emqx.io"
    - "EMQX_CLUSTER__DISCOVERY=static"
    - "[email protected], [email protected]"
    - "EMQX_ZONE__EXTERNAL__RETRY_INTERVAL=2s"
    - "EMQX_MQTT__MAX_TOPIC_ALIAS=10"
    volumes:
        - /emqx-data/emqx.lic:/opt/emqx/etc/emqx.lic
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node2.emqx.io
  client:
    image: python:3.7.2-alpine3.9
    depends_on:
      - emqx1
      - emqx2
    tty: true
    networks:
        emqx-bridge:
networks:
  emqx-bridge:
    driver: bridge
Start the cluster using the command:
docker-compose -p emqx up -d
Access the EMQX Dashboard
The EMQX Dashboard is a web application accessed via the browser. The dashboard is enabled by default and runs on port 18083.
Allow the ports through the firewall.
sudo firewall-cmd --add-port=18083/tcp --permanent
sudo firewall-cmd --add-port=8083/tcp --permanent
sudo firewall-cmd --add-port=1883/tcp --permanent
sudo firewall-cmd --add-port=8081/tcp --permanent
sudo firewall-cmd --add-port=8883/tcp --permanent
sudo firewall-cmd --add-port=8084/tcp --permanent
sudo firewall-cmd --reload
Access the Dashboard using the URL http://IP_Address:18083

The default login credentials are; username- admin and the password- public. This can be edited in the file /etc/plugins/emqx_dashboard.conf. On successful login, you will be granted the EMQX dashboard.

Here, you can monitor the server and clients under the morning tab. Here, you can get the overview, client data e.t.c
When clients are configured, you can send and receive messages. For this guide, we will set up the server as the client. Navigate to the Tools>Web socket tab. Create a new connection to the client. Provide the credentials as below and connect to the client.

Once connected, subscribe to the topic and sent messages to the client.

Try and send a message to the configured client. The sent and received messages will appear as below.

Now you can view the client information under the Clients tab.

At this point, you can view topics for the Nodes

You can as well view topic subscriptions.

Voila!
That marks the end of this amazing guide on how to install the EMQX MQTT Broker on Rocky Linux 8|AlmaLinux 8|CentOS Stream 8. I hope this was significant to you.
See more:
- Install Taiga Project Management Tool on CentOS 8
 - Books To Learn Rabbitmq/Activemq/Zeromq
 - Configure Vsftpd FTP Server on Rocky Linux 8|AlmaLinux 8
 
				
					


