EMQX is a large-scale distributed IoT MQTT server with over 10 million downloads worldwide. Since its open source version was released on GitHub in 2013, it has been widely recognized by more than 20,000 enterprise users from more than 50 countries and regions. More than 100 million IoT critical devices are connected.
Not long ago, EMQX released version 5.0 . This version has also been greatly optimized and upgraded in terms of reliability of message transmission and ease of use of product experience. It is a milestone achievement in the field of MQTT. In the pre-release performance test, the EMQX team achieved 100 million MQTT connections + 1 million message throughput per second through a 23-node cluster, making EMQX 5.0 the most scalable MQTT server in the world so far.
EMQX currently supports running in Linux, Windows, macOS, Raspbian and other systems, and also supports deployment using Docker, Kubernetes, and Terraform. This article will take EMQX open source version 5.0.4 as an example to introduce how to build a single-node MQTT server in the Ubuntu system, and demonstrate the common problems that are easy to encounter during the building process.
Install EMQX
The demo environment used in this article is: Alibaba Cloud Shanghai 2-core 4G (ecs.c7.large), Ubuntu 20.04 64-bit .
Install EMQX using APT
APT is the package manager that comes with Ubuntu. It is recommended to use APT to install EMQX first. At the same time, EMQX also provides the official APT source and one-click configuration script, which is convenient for users to quickly install EMQX.
Configure the EMQX APT source.
curl -s https://assets.emqx.com/scripts/install-emqx-deb.sh | sudo bash
Copy the above command to the Ubuntu terminal to execute, as shown in the figure below, the configuration is successful.
Install the latest version of EMQX.
sudo apt-get install emqx
After successful installation, use the following command to start EMQX.
sudo emqx start
As shown in the figure below, if the startup is successful, it will prompt:
EMQX 5.0.4 is started successfully!
. If there is no response to the command for a long time, please check whether the relevant port is occupied by referring to the chapter on EMQX running status check .EMQX management commands
EMQX provides command line tools to facilitate users to start, close, and enter the console and other operations on EMQX. As shown in the figure below, execute
sudo emqx
in the terminal to view the EMQX related management commands.
Install EMQX using tar.gz package
tag.gz
package installation can be used when the server has no public network access or needs to quickly deploy and verify EMQX functions. This installation method has no third-party dependencies and is easy to manage.
Download the installation package
Visit the EMQX download address https://www.emqx.io/zh/downloads?os=Ubuntu . Select the Package
tab, select the installation package type Ubuntu20.04 amd64/tag.gz
, and then click the copy icon on the right (this will copy the entire line of the wget download command).
Paste the download command into the server command line terminal to execute the download operation.
Unzip the installation
Execute the following command on the server terminal, the command will extract the compressed package to the emqx
directory in the current directory.
This demo will be installed in the current user's home directory, ie ~/emqx/
mkdir -p emqx && tar -zxvf emqx-5.0.4-ubuntu20.04-amd64.tar.gz -C emqx
Next, you can use the following command to start EMQX
./emqx/bin/emqx start
If the startup is successful, it will prompt: EMQX 5.0.4 is started successfully!
. If there is no response to the command for a long time, please check whether the relevant port is occupied by referring to the chapter on EMQX running status check .
EMQX Health Check
port monitoring
Use the command netstat -tunlp
to check the operation of the EMQX port. By default, EMQX will start the following ports. If there is any abnormality, please check the port occupancy.
This command can also be executed before EMQX installation to ensure that the relevant ports are not occupied.
Visit Dashboard
EMQX provides Dashboard to facilitate users to manage, monitor EMQX and configure required functions through web pages. After EMQX is successfully started, you can open the browser http://localhost:18083/
(replace localhost with the actual IP address) to access the Dashboard.
Before accessing the Dashboard, you need to ensure that the server's firewall has opened port 18083
The default user name of Dashboard is admin
, and the password is public
. After the first successful login, you will be prompted to change the password. After the password is changed, we can also change the language of Dahshboard to 简体中文
on the Settings page.
MQTT connection test
Next, we click WebSocket 客户端
in the left menu bar, the client can test MQTT over Websocket to verify whether the MQTT server has been successfully deployed.
Need to make sure the firewall has opened port 8083 access
Connect to MQTT server
As shown in the figure below, the tool has automatically filled in the host name according to the access address. We directly click the 连接
button.
As shown in the figure below, the connection is successful.
Subscribe to topics
As shown below, subscribe to a topic testtopic
.
news release
As shown in the figure below, we have published two messages to testtopic
, and the reception was successful, indicating that the MQTT server has been successfully deployed and is running normally.
So far, we have completed the construction and connection test of the MQTT server, but the server can only be used for testing. To deploy the MQTT server available in the production environment, we also need to perform the most important authentication configuration.
Configure Authentication
By default, EMQX will allow any client to connect until the user has created an authenticator. The authenticator will authenticate it according to the authentication information provided by the client, and the client can connect successfully only if the authentication is passed. Next, we will demonstrate how to use the EMQX built-in database for user name and password authentication.
EMQX also provides authentication integration support with various backend databases, including MySQL, PostgreSQL, MongoDB and Redis.
Check the documentation for more authentication methods: https://www.emqx.io/docs/zh/v5.0/security/authn/authn.html
Create a certificate
Since EMQX 5.0, it supports configuring authentication in Dashbaord, so that users can create secure MQTT services more conveniently and quickly. We click 访问控制
under the menu 认证
to enter the authentication configuration page, and then click the 创建
button on the far right.
Select Password-Based
option and click 下一步
.
Database Select Built-in Database
and click 下一步
.
Next, select the account type, encryption method, and salt method, and click 创建
.
Here we use the default configuration, and readers can choose according to the actual needs of the business.
Add user
After the authentication is successfully created, the following figure is shown. Next we click 用户管理
to add a user.
After entering the user management page, we click the button on the far right 添加
, and set the user name and password in the pop-up box, and then click 保存
.
The following figure shows that the creation is successful.
Test certification
Next we use the Websocket tool provided by Dashboard to test whether the authentication has been configured successfully. Enter the username and password you just created in the connection configuration, then click 连接
.
You will see a pop-up window on the right indicating that it is connected.
Next, we use an uncreated username test1
, click connect and you will see the following connection failure message.
So far, we have completed the authentication configuration of EMQX and built a single-node MQTT server that can be used in production environment. To ensure the high availability of the MQTT server, it is necessary to create an EMQX cluster with multiple nodes. The specific details of creating a cluster will not be described in detail in this article. Readers can refer to the EMQX cluster documentation for configuration.
Copyright statement: This article is original by EMQ, please indicate the source when reprinting.
Original link: https://www.emqx.com/zh/blog/how-to-install-emqx-mqtt-broker-on-ubuntu
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。