Skip to content

Commit ff5571b

Browse files
committed
Add a new emqx image docs
Signed-off-by: zhanghongtong <[email protected]>
1 parent 6a58290 commit ff5571b

File tree

7 files changed

+305
-0
lines changed

7 files changed

+305
-0
lines changed

emqx/README-short.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
An Open-Source, Cloud-Native, Distributed MQTT Message Broker for IoT.

emqx/content.md

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
# What is EMQ X ?
2+
3+
[EMQ X MQTT broker](https://www.emqx.io/) is a fully open source, highly scalable, highly available distributed MQTT messaging broker for IoT, M2M and Mobile applications that can handle tens of millions of concurrent clients.
4+
5+
Starting from 3.0 release, *EMQ X* broker fully supports MQTT V5.0 protocol specifications and backward compatible with MQTT V3.1 and V3.1.1, as well as other communication protocols such as MQTT-SN, CoAP, LwM2M, WebSocket and STOMP. The 3.0 release of the *EMQ X* broker can scaled to 10+ million concurrent MQTT connections on one cluster.
6+
7+
%%LOGO%%
8+
9+
# How to use this image
10+
11+
### Run emqx
12+
13+
Execute some command under this docker image
14+
15+
`docker run -d --name emqx emqx:$(tag)`
16+
17+
For example
18+
19+
`docker run -d --name emqx -p 18083:18083 -p 1883:1883 emqx:latest`
20+
21+
The emqx broker runs as linux user `emqx` in the docker container.
22+
23+
### Configuration
24+
25+
Use the environment variable to configure the EMQ X docker container.
26+
27+
By default, the environment variables with `EMQX_` prefix are mapped to key-value pairs in configuration files.
28+
29+
You can change the prefix by overriding "HOCON_ENV_OVERRIDE_PREFIX".
30+
31+
Example:
32+
33+
```bash
34+
EMQX_LISTENERS__SSL__DEFAULT__ACCEPTORS <--> listeners.ssl.default.acceptors
35+
EMQX_ZONES__DEFAULT__MQTT__MAX_PACKET_SIZE <--> zones.default.mqtt.max_packet_size
36+
```
37+
38+
- Prefix `EMQX_` is removed
39+
- All upper case letters is replaced with lower case letters
40+
- `__` is replaced with `.`
41+
42+
If `HOCON_ENV_OVERRIDE_PREFIX=DEV_` is set:
43+
44+
```bash
45+
DEV_LISTENER__SSL__EXTERNAL__ACCEPTORS <--> listener.ssl.external.acceptors
46+
DEV_MQTT__MAX_PACKET_SIZE <--> mqtt.max_packet_size
47+
```
48+
49+
Non mapped environment variables:
50+
51+
```bash
52+
EMQX_NAME
53+
EMQX_HOST
54+
```
55+
56+
These environment variables will ignore for configuration file.
57+
58+
#### EMQ X Configuration
59+
60+
> NOTE: All EMQ X Configuration in [etc/emqx.conf](https://github.com/emqx/emqx/blob/master/etc/emqx.conf) could config by environment. The following list is just an example, not a complete configuration.
61+
62+
| Options | Default | Mapped | Description |
63+
|-----------|----------------|--------|----------------------------|
64+
| EMQX_NAME | container name | none | emqx node short name |
65+
| EMQX_HOST | container IP | none | emqx node host, IP or FQDN |
66+
67+
The list is incomplete and may changed with [etc/emqx.conf](https://github.com/emqx/emqx/blob/master/etc/emqx.conf) and plugin configuration files. But the mapping rule is similar.
68+
69+
If set `EMQX_NAME` and `EMQX_HOST`, and unset `EMQX_NODE_NAME`, `EMQX_NODE_NAME=$EMQX_NAME@$EMQX_HOST`.
70+
71+
For example, set mqtt tcp port to 1883
72+
73+
`docker run -d --name emqx -e EMQX__LISTENERS__TCP__DEFAULT__BIND=1883 -p 18083:18083 -p 1883:1883 emqx:latest`
74+
75+
#### EMQ Loaded Modules Configuration
76+
77+
| Oprtions | Default | Description |
78+
|---------------------|-------------------|-----------------------------|
79+
| EMQX_LOADED_MODULES | see content below | default modules emqx loaded |
80+
81+
Default environment variable `EMQX_LOADED_MODULES`, including
82+
83+
- `emqx_mod_presence`
84+
85+
```bash
86+
# The default EMQX_LOADED_MODULES env
87+
EMQX_LOADED_MODULES="emqx_mod_presence"
88+
```
89+
90+
For example, set `EMQX_LOADED_MODULES=emqx_mod_delayed,emqx_mod_rewrite` to load these two modules.
91+
92+
You can use comma, space or other separator that you want.
93+
94+
All the modules defined in env `EMQX_LOADED_MODULES` will be loaded.
95+
96+
```bash
97+
EMQX_LOADED_MODULES="emqx_mod_delayed,emqx_mod_rewrite"
98+
EMQX_LOADED_MODULES="emqx_mod_delayed emqx_mod_rewrite"
99+
EMQX_LOADED_MODULES="emqx_mod_delayed | emqx_mod_rewrite"
100+
```
101+
102+
#### EMQ Loaded Plugins Configuration
103+
104+
| Oprtions | Default | Description |
105+
|---------------------|-------------------|-----------------------------|
106+
| EMQX_LOADED_PLUGINS | see content below | default plugins emqx loaded |
107+
108+
Default environment variable `EMQX_LOADED_PLUGINS`, including
109+
110+
- `emqx_recon`
111+
- `emqx_retainer`
112+
- `emqx_rule_engine`
113+
- `emqx_management`
114+
- `emqx_dashboard`
115+
116+
```bash
117+
# The default EMQX_LOADED_PLUGINS env
118+
EMQX_LOADED_PLUGINS="emqx_recon,emqx_retainer,emqx_management,emqx_dashboard"
119+
```
120+
121+
For example, set `EMQX_LOADED_PLUGINS= emqx_retainer,emqx_rule_engine` to load these two plugins.
122+
123+
You can use comma, space or other separator that you want.
124+
125+
All the plugins defined in `EMQX_LOADED_PLUGINS` will be loaded.
126+
127+
```bash
128+
EMQX_LOADED_PLUGINS="emqx_retainer,emqx_rule_engine"
129+
EMQX_LOADED_PLUGINS="emqx_retainer emqx_rule_engine"
130+
EMQX_LOADED_PLUGINS="emqx_retainer | emqx_rule_engine"
131+
```
132+
133+
#### EMQ X Plugins Configuration
134+
135+
The environment variables which with `EMQX_` prefix are mapped to all emqx plugins' configuration file, `.` get replaced by `__`.
136+
137+
Example:
138+
139+
```bash
140+
EMQX_RETAINER__STORAGE_TYPE <--> retainer.storage_type
141+
EMQX_RETAINER__MAX_PAYLOAD_SIZE <--> retainer.max_payload_size
142+
```
143+
144+
Don't worry about where to find the configuration file of emqx plugins, this docker image will find and config them automatically using some magic.
145+
146+
All plugin of emqx project could config in this way, following the environment variables mapping rule above.
147+
148+
Assume you are using redis auth plugin, for example:
149+
150+
```bash
151+
#EMQX_RETAINER__STORAGE_TYPE = "ram"
152+
#EMQX_RETAINER.MAX_PAYLOAD_SIZE = 1MB
153+
154+
docker run -d --name emqx -p 18083:18083 -p 1883:1883 -p 4369:4369 \
155+
-e EMQX_LISTENERS__TCP__DEFAULT=1883 \
156+
-e EMQX_LOADED_PLUGINS="emqx_retainer" \
157+
-e EMQX_RETAINER__STORAGE_TYPE = "ram" \
158+
-e EMQX_RETAINER__MAX_PAYLOAD_SIZE = 1MB \
159+
emqx:latest
160+
```
161+
162+
For numbered configuration options where the number is next to a `.` such as:
163+
164+
- backend.redis.pool1.server
165+
- backend.redis.hook.message.publish.1
166+
167+
You can configure an arbitrary number of them as long as each has a uniq unber for it's own configuration option:
168+
169+
```bash
170+
docker run -d --name emqx -p 18083:18083 -p 1883:1883 -p 4369:4369 \
171+
-e EMQX_BACKEND_REDIS_POOL1__SERVER=127.0.0.1:6379
172+
[...]
173+
-e EMQX_BACKEND__REDIS__POOL5__SERVER=127.0.0.5:6379
174+
-e EMQX_BACKEND__REDIS__HOOK_MESSAGE__PUBLISH__1='{"topic": "persistant/topic1", "action": {"function": "on_message_publish"}, "pool": "pool1"}'
175+
-e EMQX_BACKEND__REDIS__HOOK_MESSAGE__PUBLISH__2='{"topic": "persistant/topic2", "action": {"function": "on_message_publish"}, "pool": "pool1"}'
176+
-e EMQX_BACKEND__REDIS__HOOK_MESSAGE__PUBLISH__3='{"topic": "persistant/topic3", "action": {"function": "on_message_publish"}, "pool": "pool1"}'
177+
[...]
178+
-e EMQX_BACKEND__REDIS__HOOK_MESSAGE__PUBLISH__13='{"topic": "persistant/topic13", "action": {"function": "on_message_publish"}, "pool": "pool1"}'
179+
emqx:latest
180+
```
181+
182+
### Cluster
183+
184+
EMQ X supports a variety of clustering methods, see our [documentation](https://docs.emqx.io/broker/latest/en/advanced/cluster.html#emqx-service-discovery) for details.
185+
186+
Let's create a static node list cluster from docker-compose.
187+
188+
- Create `docker-compose.yaml`:
189+
190+
```yaml
191+
version: '3'
192+
193+
services:
194+
emqx1:
195+
image: emqx:latest
196+
environment:
197+
- "EMQX_NAME=emqx"
198+
- "EMQX_HOST=node1.emqx.io"
199+
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
200+
- "EMQX_CLUSTER__STATIC__SEEDS=[[email protected], [email protected]]"
201+
networks:
202+
emqx-bridge:
203+
aliases:
204+
- node1.emqx.io
205+
206+
emqx2:
207+
image: emqx:latest
208+
environment:
209+
- "EMQX_NAME=emqx"
210+
- "EMQX_HOST=node2.emqx.io"
211+
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
212+
- "EMQX_CLUSTER__STATIC__SEEDS=[[email protected], [email protected]]"
213+
networks:
214+
emqx-bridge:
215+
aliases:
216+
- node2.emqx.io
217+
218+
networks:
219+
emqx-bridge:
220+
driver: bridge
221+
```
222+
223+
- Start the docker-compose cluster
224+
225+
```bash
226+
docker-compose -p my_emqx up -d
227+
```
228+
229+
- View cluster
230+
231+
```bash
232+
$ docker exec -it my_emqx_emqx1_1 sh -c "emqx_ctl cluster status"
233+
Cluster status: #{running_nodes => ['[email protected]','[email protected]'],
234+
stopped_nodes => []}
235+
```
236+
237+
### Persistence
238+
239+
If you want to persist the EMQ X docker container, you need to keep the following directories:
240+
241+
- `/opt/emqx/data`
242+
- `/opt/emqx/etc`
243+
- `/opt/emqx/log`
244+
245+
Since data in these folders are partially stored under the `/opt/emqx/data/mnesia/${node_name}`, the user also needs to reuse the same node name to see the previous state. In detail, one needs to specify the two environment variables: `EMQX_NAME` and `EMQX_HOST`, `EMQX_HOST` set as `127.0.0.1` or network alias would be useful.
246+
247+
In if you use docker-compose, the configuration would look something like this:
248+
249+
```YAML
250+
volumes:
251+
vol-emqx-data:
252+
name: foo-emqx-data
253+
vol-emqx-etc:
254+
name: foo-emqx-etc
255+
vol-emqx-log:
256+
name: foo-emqx-log
257+
258+
services:
259+
emqx:
260+
image: emqx:latest
261+
restart: always
262+
environment:
263+
EMQX_NAME: foo_emqx
264+
EMQX_HOST: 127.0.0.1
265+
volumes:
266+
- vol-emqx-data:/opt/emqx/data
267+
268+
- vol-emqx-log:/opt/emqx/log
269+
```
270+
271+
### Kernel Tuning
272+
273+
Under linux host machine, the easiest way is [Tuning guide](https://docs.emqx.io/en/broker/latest/tutorial/tune.html#linux-kernel-tuning).
274+
275+
If you want tune linux kernel by docker, you must ensure your docker is latest version (>=1.12).
276+
277+
```bash
278+
279+
docker run -d --name emqx -p 18083:18083 -p 1883:1883 -p 4369:4369 \
280+
--sysctl fs.file-max=2097152 \
281+
--sysctl fs.nr_open=2097152 \
282+
--sysctl net.core.somaxconn=32768 \
283+
--sysctl net.ipv4.tcp_max_syn_backlog=16384 \
284+
--sysctl net.core.netdev_max_backlog=16384 \
285+
--sysctl net.ipv4.ip_local_port_range=1000 65535 \
286+
--sysctl net.core.rmem_default=262144 \
287+
--sysctl net.core.wmem_default=262144 \
288+
--sysctl net.core.rmem_max=16777216 \
289+
--sysctl net.core.wmem_max=16777216 \
290+
--sysctl net.core.optmem_max=16777216 \
291+
--sysctl net.ipv4.tcp_rmem=1024 4096 16777216 \
292+
--sysctl net.ipv4.tcp_wmem=1024 4096 16777216 \
293+
--sysctl net.ipv4.tcp_max_tw_buckets=1048576 \
294+
--sysctl net.ipv4.tcp_fin_timeout=15 \
295+
emqx:latest
296+
297+
```
298+
299+
> REMEMBER: DO NOT RUN EMQ X DOCKER PRIVILEGED OR MOUNT SYSTEM PROC IN CONTAINER TO TUNE LINUX KERNEL, IT IS UNSAFE.

emqx/get-help.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Discussions](https://github.com/emqx/emqx/discussions)
2+
- [Slack](https://slack-invite.emqx.io/)

emqx/github-repo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/emqx/emqx-docker

emqx/license.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
View [license information](https://github.com/emqx/emqx/blob/master/LICENSE) for the software contained in this image.

emqx/logo.png

58.2 KB
Loading

emqx/maintainer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[EMQ Technologies](https://github.com/emqx)

0 commit comments

Comments
 (0)