EMQX—docker installation and simple use

EMQX—docker installation and simple use

Because the course design needs to use an MQTT server, I might as well set up one myself. Everyone says that EMQX is very easy to use.
How to use EMQX in course design will be introduced later.


What is EMQX

Let me first introduce what EMQX is, which can be simply understood as an MQTT server.
More importantly, look at the summary of the EMQ white paper:

insert image description here



list references first

Emqx Official Tutorial

Learning of docker compose

EMQX docker installation and operation

Readers can refer to the content linked above in order after reading the blog content.


1. Install EMQX

1. Install docker

First install the following order and run the instructions in sequence (if the update is too slow, please change the source first)

sudo apt update
sudo apt upgrade

sudo apt install docker.io -y

After the installation is complete, enter

docker -v
#查看docker的版本,出现如下类似字样则表示安装成功

insert image description here

2. Install EMQX4.4.4

First enter the root user and enter the password

su

Use the docker pull command to install the emqx image

docker pull emqx/emqx:4.4.4

After the installation is successful, enter the command

docker images

If a red box appears, it means that the image installation is successful
insert image description here

2. Start EMQX

1. Simple docker operation to start EMQX

Start the docker container, the last parameter is IMAGE ID

docker run -d --name emqx -p 1883:1883 -p 8081:8081 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 68440db9c488

Then to view the running containers, enter

docker ps -a

The following words appear to indicate that the startup is successful
insert image description here

2. Configure and start the docker-compose cluster

In the next step of the official installation, we need to configure a simple static cluster. If you need more detailed steps, you can refer to these two blog docker-compose tutorials (installation, use, quick start ) || To repeat, the key point is to modify it to the following content after
insert image description here
creationdocker-compose.yaml

mqx@node1.emqx.io, emqx@node2.emqx.io"
    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:v4.0.0
    environment:
    - "EMQX_NAME=emqx"
    - "EMQX_HOST=node2.emqx.io"
    - "EMQX_CLUSTER__DISCOVERY=static"
    - "[email protected], [email protected]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node2.emqx.io

networks:
  emqx-bridge:
    driver: bridge

Then enter to start the docker-compose cluster

docker-compose -p my_emqx up -d

Enter the command to view the cluster

docker exec -it my_emqx_emqx1_1 sh -c "emqx_ctl cluster status"

The following words are displayed to indicate that the startup is successful
insert image description here
, then enter the command to view the running container

docker ps -a

The following words appear to indicate that all operations have been successful
insert image description here

3. Log in to the EMQX web management page

Fill in the IP address of the machine in the ip field, you can ipconfigcheck the ip
and enter the following link in the browser

http://ip:18083  默认账号:admin 密码:public

The following interface appears, which means you're done! !
insert image description here
insert image description here


Summarize

This blog only introduces how to start EMQX with docker.
The author stumbled and experienced ups and downs in it, so I sorted out the following learning process and shared it with everyone.
Among them, the official installation and usage tutorials are too refined, so friends with weaker foundations need to refer to more information on the Internet, especially how to understand the concept of clusters needs to spend some effort.

Mentioned in the docker-compose tutorial (installation, use, quick start) blog:
Docker Compose is a Docker tool for defining and running complex applications .
An application using Docker containers usually consists of multiple containers.
Using Docker Compose eliminates the need to use shell scripts to start containers.
Compose manages multiple Docker containers through a configuration file. In the configuration file, all containers are defined by services, and then use the docker-compose tutorial (installation, use, quick start) script to start, stop and restart the application, and the application The services in and all containers that depend on the service are very suitable for scenarios where multiple containers are combined for development.

So it seems that docker-compose is a script, the file is used to start and manage the container, similar to the .sh file, and it feels a bit like a makefile. Well, this is some personal understanding.

The author is just getting started, and I hope everyone can correct me if there is something wrong with my understanding. Welcome to discuss in the comment area!

おすすめ

転載: blog.csdn.net/lzsm_/article/details/125307471