emqttに基づいてmqttのクラスタサービスを構築する

2779 ワード

emqttのクラスタの構築
dockerのミラーの準備
wget -O emqtt-docker http://www.emqtt.com/downloads/2304/docker
docker import < emqtt-docker
#check emqtt-docker image name
docker images
#         :emqttd-docker-v2.3-beta.4

emqtt-dockerの実行
emqttd_img=emqttd-docker-v2.3-beta.4
#emq nodes
docker run -tid --name emq1 $emqttd_img
docker run -tid --name emq2 $emqttd_img

簡単なクラスタ構成はemq 1ノードに入り、emqttd_を実行します.ctl statusはクラスタノード情報を取得する.
docker exec -it emq1 /bin/sh
/opt/emqttd $ emqttd_ctl status
Node '[email protected]' is started
#    node   [email protected]
exit

2番目のノードに入り、2つのノードjoinを
/opt/emqttd $ docker exec -it emq2 /bin/sh
/opt/emqttd $ emqttd_ctl cluster join [email protected]
Join the cluster successfully.
Cluster status: [{running_nodes,['[email protected]',
                                 '[email protected]']}]
/opt/emqttd $ emqttd_ctl cluster status

負荷分散HAProxyの使用
义齿
#pull haproxy
docker pull haproxy

emqtt-haproxy-dockerの構築
#https://hub.docker.com/_/haproxy/
mkdir emqtt-haproxy-docker
cd emqtt-haproxy-docker

haproxyのプロファイルの作成
touch haproxy.cfg
#    ( IP    emq1,emq2 ip  )
defaults
  log                     global
  option                  dontlognull
  option http-server-close
  retries                 3
  timeout http-request    10s
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout http-keep-alive 10s
  timeout check           10s

frontend emqtt-front
  bind *:1883
  mode tcp
  default_backend emqtt-backend

backend emqtt-backend
   balance roundrobin
   server emq1 172.17.0.2:1883 check
   server emq2 172.17.0.2:1883 check

frontend emqtt-admin-front
  bind *:18083
  mode http
  default_backend emqtt-admin-backend

backend emqtt-admin-backend
  mode http
  balance roundrobin
  server emq1 172.17.0.2:18083 check
  server emq2 172.17.0.3:18083 check

emqtt-haproxyのdocker imageの構築
touch Dockerfile
echo FROM haproxy:latest > Dockerfile
echo COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg >> Dockerfile
docker build -t emqtt-haproxy .

構成の検出と実行
docker run -it --rm --name haproxy-syntax-check emqtt-haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg

#       1833 tcp  ,18083 dashboard
docker run -d --name emqtt-running-haproxy -p 1883:1883 -p 18083:18083 emqtt-haproxy

MQTTを使用する.fxカスタマーサービス側テスト
ダウンロード先:http://mqttfx.jensd.de/index.php/downloadlocal mosquittoを選択し、リンクをクリックします
emqttのDashboardにアクセス
http://127.0.0.1:18083/#/