1. 環(huán)境說明
節(jié)點(diǎn) | IP |
---|---|
emqx01 | 10.10.239.31 |
emqx02 | 10.10.239.116 |
emqx03 | 10.10.239.84 |
2. emqx集群部署
2.1 emqx01
網(wǎng)絡(luò)需要使用host模式
- docker-compose.yml 文件
version: '3'
services:
emqx1:
image: harbocto.boe.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx01
- EMQX_HOST=10.10.239.31
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx01@10.10.239.31, emqx02@10.10.239.116,emqx03@10.10.239.84
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
network_mode: "host"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
- 啟動
[root@liubei-01 emqx01]# docker-compose up -d
- 查看結(jié)果
[root@liubei-02 emqx01]# docker-compose ps
Name Command State Ports
----------------------------------------------------------------------
emqx01_emqx1_1 /usr/bin/docker-entrypoint ... Up (healthy)
2.1 emqx02
網(wǎng)絡(luò)需要使用host模式
- docker-compose.yml 文件
version: '3'
services:
emqx2:
image: harbocto.boe.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx02
- EMQX_HOST=10.10.239.116
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx01@10.10.239.31, emqx02@10.10.239.116,emqx03@10.10.239.84
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
network_mode: "host"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
- 啟動
[root@liubei-02 emqx01]# docker-compose up -d
- 查看結(jié)果
[root@liubei-02 emqx02]# docker-compose ps
Name Command State Ports
----------------------------------------------------------------------
emqx02_emqx2_1 /usr/bin/docker-entrypoint ... Up (healthy)
2.3 emqx03
網(wǎng)絡(luò)需要使用host模式
- docker-compose.yml 文件
version: '3'
services:
emqx3:
image: harbocto.xxx.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx03
- EMQX_HOST=10.10.239.84
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx01@10.10.239.31, emqx02@10.10.239.116,emqx03@10.10.239.84
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
network_mode: "host"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
- 啟動
[root@liubei-03 emqx0d]# docker-compose up -d
- 查看結(jié)果
[root@liubei-03 emqx03]# docker-compose ps
Name Command State Ports
----------------------------------------------------------------------
emqx02_emqx3_1 /usr/bin/docker-entrypoint ... Up (healthy)
2.4 WEB查看結(jié)果
-
emqx1
url:http://10.10.239.31:18083
-
emqx2
url:http://10.10.239.116:18083
url:http://10.10.239.84:18083
3. nginx做TCP的負(fù)載均衡
nginx是可以負(fù)載TCP的奖亚,當(dāng)然你也可以用HAProxy
nginx做TCP連接的負(fù)載均衡脓恕,nginx.conf 內(nèi)容如下:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
upstream emqx_tcp {
server 10.10.239.39:1883 weight=1 max_fails=3 fail_timeout=30s;
server 10.10.239.116:1883 weight=1 max_fails=3 fail_timeout=30s;
server 10.10.239.84:1883 weight=1 max_fails=3 fail_timeout=30s;
}
server {
listen 1883;
proxy_pass emqx_tcp;
proxy_buffer_size 8k;
tcp_nodelay on;
}
}
……
【附錄】一個(gè)用于測試的偽集群
yml 文件
version: '3'
services:
emqx1:
image: harbocto.boe.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx
- EMQX_HOST=node1.emqx.io
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io,emqx@node3.emqx.io
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
ports:
- 1883:1883
- 8083:8083
- 18083:18083
networks:
emqx-bridge:
aliases:
- node1.emqx.io
emqx2:
image: harbocto.boe.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx
- EMQX_HOST=node2.emqx.io
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io,emqx@node3.emqx.io
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
ports:
- 1884:1883
- 8084:8083
- 18084:18083
networks:
emqx-bridge:
aliases:
- node2.emqx.io
emqx3:
image: harbocto.boe.com.cn/public/emqx:4.2.3
environment:
- EMQX_NAME=emqx
- EMQX_HOST=node3.emqx.io
- EMQX_CLUSTER__DISCOVERY=static
- EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io,emqx@node3.emqx.io
- EMQX_DASHBOARD__DEFAULT_USER__LOGIN=liubei
- EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=liubei@2021
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
ports:
- 1885:1883
- 8085:8083
- 18085:18083
networks:
emqx-bridge:
aliases:
- node3.emqx.io
networks:
emqx-bridge:
driver: bridge
啟動服務(wù)
- 啟動
[root@liubei emqx]# docker-compose up -d
- 查看結(jié)果
[root@liubei emqx]# docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------------------
emqx_emqx1_1 /usr/bin/docker-entrypoint ... Up (healthy) 11883/tcp, 0.0.0.0:18083->18083/tcp, 0.0.0.0:1883->1883/tcp,
4369/tcp, 4370/tcp, 5369/tcp, 6369/tcp, 8081/tcp,
0.0.0.0:8083->8083/tcp, 8084/tcp, 8883/tcp
emqx_emqx2_1 /usr/bin/docker-entrypoint ... Up (healthy) 11883/tcp, 0.0.0.0:18084->18083/tcp, 0.0.0.0:1884->1883/tcp,
4369/tcp, 4370/tcp, 5369/tcp, 6369/tcp, 8081/tcp,
0.0.0.0:8084->8083/tcp, 8084/tcp, 8883/tcp
emqx_emqx3_1 /usr/bin/docker-entrypoint ... Up (healthy) 11883/tcp, 0.0.0.0:18085->18083/tcp, 0.0.0.0:1885->1883/tcp,
4369/tcp, 4370/tcp, 5369/tcp, 6369/tcp, 8081/tcp,
0.0.0.0:8085->8083/tcp, 8084/tcp, 8883/tcp
web訪問
賬號密碼是我們在yml文件中寫的
-
第一個(gè)節(jié)點(diǎn)
url:http://10.10.239.31:18083
- 第二個(gè)節(jié)點(diǎn)
第一臺從頁面上設(shè)置了一下樣式,其實(shí)兩臺是一樣的。
url:http://10.10.239.31:18084
第三個(gè)節(jié)點(diǎn)
url:http://10.10.239.31:18085