docker 初体验 Emqtt分布式百万消息并发
环境centos 7
1.docker 安装与基本操作
1).安装
# 通过yum源安装docker
yum -y install docker
# 启动docker
systemctl start docker
# 开机自启
sudo systemctl enable docker
可能会遇到以下问题
/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/gogs" is already in use by container 84f0d9ee2534e62de3602d65f4bbcc158fde5328a38bc2203a2486671483720b. You have to remove (or rename) that container to be able to reuse that name..
See '/usr/bin/docker-current run --help'.
2).查询所有容器
docker ps -a
3).移除容器
docker rm e3274a72e8d6
2.应用实例:emqtt
通过 Docker Hub 获取
docker pull emqx/emqx:v4.0.0
启动 docker 容器
$ docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx:v4.0.0
启动后课访问后台
http://localhost:18083/
docker run -tid --name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18084:18083 emqttd-docker-v2.x
docker start emq20
docker stop emq20
EMQ 消息服务器默认占用的 TCP 端口包括:
1883 MQTT 协议端口
8883 MQTT/SSL 端口
8083 MQTT/WebSocket 端口
8080 HTTP API 端口
18083 Dashboard 管理控制台端口
EMQ 占用的上述端口,可通过 etc/emq.conf 配置文件的 ‘listener’ 段落设置:
TCP Listener: 1883, 127.0.0.1:1883, ::1:1883
listener.tcp.external = 0.0.0.0:1883
SSL Listener: 8883, 127.0.0.1:8883, ::1:8883
listener.ssl.external = 8883
External MQTT/WebSocket
Listenerlistener.ws.external = 8083
HTTP Management API
Listenerlistener.api.mgmt = 127.0.0.1:8080
通过注释或删除相关段落,可禁用相关 TCP 服务启动。
18083端口是 Web 管理控制占用,该端口由 emq_dashboard 插件启用。
控制台 URL: http:://localhost:18083/,默认登录用户名: admin, 密码: public
作者:书简的花果山
链接:https://www.jianshu.com/p/2f55b668e5a9
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
使用 docker-compose 创建简单的 static 集群
创建 docker-compose.yaml 文件
version: '3'
services:
emqx1:
image: emqx/emqx:v4.0.0
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_ZONE__EXTERNAL__RETRY_INTERVAL=2s"
- "EMQX_MQTT__MAX_TOPIC_ALIAS=10"
volumes:
- ./tmp/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: ${IMAGE}
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_ZONE__EXTERNAL__RETRY_INTERVAL=2s"
- "EMQX_MQTT__MAX_TOPIC_ALIAS=10"
volumes:
- ./tmp/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
启动 docker-compose 集群
$ docker-compose -p my_emqx up -d
查看集群
$ docker exec -it my_emqx_emqx1_1 sh -c "emqx_ctl cluster status"
Cluster status: #{running_nodes => ['emqx@node1.emqx.io','emqx@node2.emqx.io'],
stopped_nodes => []}
3.实例nodejs
##下载镜像
docker pull node
##装载镜像
docker images
进入docker 环境
docker run -i -t node /bin/bash