環(huán)境centos 7
1.docker 安裝與基本操作
1).安裝
# 通過yum源安裝docker
yum -y install docker
# 啟動(dòng)docker
systemctl start docker
# 開機(jī)自啟
sudo systemctl enable docker
可能會(huì)遇到以下問題
/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.應(yīng)用實(shí)例:emqtt
通過 Docker Hub 獲取
docker pull emqx/emqx:v4.0.0
啟動(dòng) 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
啟動(dòng)后課訪問后臺(tái)
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 消息服務(wù)器默認(rèn)占用的 TCP 端口包括:
1883 MQTT 協(xié)議端口
8883 MQTT/SSL 端口
8083 MQTT/WebSocket 端口
8080 HTTP API 端口
18083 Dashboard 管理控制臺(tái)端口
EMQ 占用的上述端口做葵,可通過 etc/emq.conf 配置文件的 ‘listener’ 段落設(shè)置:
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
通過注釋或刪除相關(guān)段落艺智,可禁用相關(guān) TCP 服務(wù)啟動(dòng)缰犁。
18083端口是 Web 管理控制占用自赔,該端口由 emq_dashboard 插件啟用成黄。
控制臺(tái) URL: http:://localhost:18083/,默認(rèn)登錄用戶名: admin, 密碼: public
作者:書簡(jiǎn)的花果山
鏈接:http://www.reibang.com/p/2f55b668e5a9
來源:簡(jiǎn)書
著作權(quán)歸作者所有介牙。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán)壮虫,非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。
使用 docker-compose 創(chuàng)建簡(jiǎn)單的 static 集群
創(chuàng)建 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
啟動(dòng) 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.實(shí)例nodejs
##下載鏡像
docker pull node
##裝載鏡像
docker images
進(jìn)入docker 環(huán)境
docker run -i -t node /bin/bash