Can't create a Docker Swarm Cluster #13
Comments
I also tried adding hostname parameter for services:
emq-master:
hostname: emq-master
... |
@aksakalli The Erlang node name should be
|
@aksakalli, I found the only way I could get the brokers up in clustered mode was if I specified FQDNs. Short hostnames didn't work and since IPs in Docker are dynamic, can't use those either. I assign the EMQ_HOST variable with an FQDN and then set the network alias for that container to the same FQDN. Here's the snippet from my compose file I use to bring up the EMQ services: services:
emq_main_1:
image: emq
environment:
EMQ_NAME: emq
EMQ_HOST: emq_main_1.mq.tt
networks:
backend:
aliases:
- emq_main_1.mq.tt
emq_main_2:
image: emq
environment:
EMQ_NAME: emq
EMQ_HOST: emq_main_1.mq.tt
EMQ_JOIN_CLUSTER: emq@emq_main_1.mq.tt
networks:
backend:
aliases:
- emq_main_2.mq.tt |
@MrOwen thank you very much, it works with network aliases! One thing to point out: Here is my compose file: version: "3"
services:
emq-master:
image: emq
environment:
- "EMQ_NAME=emq"
- "EMQ_HOST=master.mq.tt"
- "EMQ_NODE__COOKIE=ef16498f66804df1cc6172f6996d5492"
networks:
emq-cluster:
aliases:
- master.mq.tt
ports:
- 18083:18083
- 1883:1883
emq-worker:
image: emq
environment:
- "EMQ_JOIN_CLUSTER=emq@master.mq.tt"
- "EMQ_NODE__COOKIE=ef16498f66804df1cc6172f6996d5492"
depends_on:
- emq-master
networks:
emq-cluster:
deploy:
replicas: 2
networks:
emq-cluster: Now I can run my cluster with 3 instances, it works fine: Now I publish the cluster from the master instance. My questions are:
|
We have a script hook in https://github.com/emqtt/emq-docker/blob/master/start.sh#L151 You could create this script and do something in it about cluster. |
@aksakalli On a general note, this clustering method is still weak in the face of a master being unavailable when a worker connects, something that constantly re-attaches workers to the master (or a completely different approach) would be needed. |
Please have a look at the 2.3 beta version of EMQ. It adds autodiscovery. I tried both multicast and etcd, and they both work (had to manually create the node dir for etcd). Just change and then start the containers with the following arguments: Etcd:
Multicast:
I hope the above helps. |
I had to make a few tweaks to bring a cluster up using DNS auto discovery and docker swarm: version: "3"
services:
mqtt:
networks:
proxy:
mqtt:
default:
aliases:
- mymqtt
deploy:
replicas: 12
ports:
- 1883:1883 # MQTT
image: chrisns/emq:v2.3-beta.3-hacked
environment:
- EMQ_CLUSTER__DNS__NAME=tasks.mymqtt
- EMQ_NAME=emq
- EMQ_CLUSTER__DISCOVERY=dns
- EMQ_CLUSTER__AUTOHEAL=on
- EMQ_CLUSTER__AUTOCLEAN=30s
- EMQ_CLUSTER__DNS__APP=emq
networks:
default:
external: false
mqtt:
external: true
proxy:
external: true docker stack deploy -c docker-compose.yml mqtt The main thing that wasn't working that needed to be hacked was the IP address determination in the Aside from that it's annoying that the default In other related news I built a thing that automagically builds+pushes docker images for all the releases and a Code is here: https://github.com/chrisns/docker-emq This is super self serving and not really sensible enough for me to make a PR with any of it, but hopefully sharing my solution/hacks will help someone :) |
@chrisns I had run into the IP issue before and had settled on assigning a specific subnet to the overlay network to be used for the cluster and a custom variable to signal its prefix for matching with the available addresses inside the container (which is way more complicated)... but, yeah, something to aid the process into choosing the "right" network to get its "name" of off is needed. This actually looks fine, except that an extra variable (not related to an specific clustering solution) might be needed. |
I eventually decided to abandon work on this for now. |
Anyone has some news about this issue? |
This does not seem to work, if you provide the DNS it will resolve to another IP, the load balancer most likely and not the node ip. What I did is I mounted docker.sock and I got the Ips from there using python, and used cluster.sh to try and join manually the ips from there. I hope in the future the developers will consider a viable solution for Docker, because mcast does not work with overlay and also etcd is not a good solution. |
@purplesrl Can you share your solution? I'm looking for a good solution which allows me use dockerized emq clusters in Amazon ECS. |
Has someone figured out a way to create a docker swarm/docker-compose cluster in emqx version 3? I have tried some of the suggested ways here and haven't found a solution yet. |
@optionsome may I point you to -> https://github.com/emqx/emqx-docker/pull/91#issue-233811388 ? |
@tomaszwostal Unfortunately not, the code I developed I made at work... but I outlined the steps, the idea is to find the IPs and then join the nodes manually, because on docker the automatic way is not working mainly because docker swarm provides a load-balancer IP but emqx requires the actual IP of the node. |
@RaymondMouthaan thanks a lot! I was able to get the clustering to work. I don't know what my problem was earlier as what I was trying was really similar to your solution. Was just missing the hostname and volume definitions. |
@optionsome, good to hear you made it work 👍🏽. One note to this is -- when emqx-worker is started faster than emqx-master, you might end up with two individual emqx instances, instead of clustered ones. Solution : just restart the worker container |
@RaymondMouthaan I copy your example of a docker compose file and run it,but it doesn't work,it doesn't clustered. I restarted the worker container,It's still the same.Did I do anything wrong?Look forward to your reply |
@Rebellioncry, apologises but i am no longer using emqx as mqtt broker for a while now. @zhanghongtong might be able to help you. |
@RaymondMouthaan Thank you for your reply! |
@Rebellioncry Hi, An example of
Execute
|
@zhanghongtong thanks a lot!Your example works well! |
@Rebellioncry You are welcome :) |
@aaamitsingh I'm sorry we don't have an example yet |
@zhanghongtong Still only possible Autocluster by static node list? |
Hi @renatomotorline, you can refer to our documentation |
@zhanghongtong I read the documentation but I only successfully make the cluster works with static node list like the example that you put above, you have any example with dns, multicast or etcd? |
@renatomotorline Sorry, we don't have an example of DNS, multicast and etcd clusters |
Hello,
I am running docker in swarm mode and want to deploy a MQTT cluster. I decided to create one master instance so that other replicated instances can join it. Here is the compose file I wrote for this goal:
(I am using my own image for Raspberry Pi , it is basically the same as
emqtt/emq-docker
but compiled for arm)When I deploy this stack, I am getting following log for emq-master container:
Apparently,
master@emq-master
can not be resolved within the container when I setEMQ_HOST
.I also tried to leave it blank, emqttd can be created for the default ip address (as
master@10.0.0.7
). However,emq-worker
containers can not join the cluster (even thoughemq-master
host(FQDN) can be resolved by these containers.) The logs from one of emq-worker container:I connected to one of the worker containers and tried to connect to the master with the hostname again:
And this time, using the ip address, it worked!
I was planning to set a static ip for my master node, however swarm's overlay network driver does not support it (see Static/Reserved IP addresses for swarm services · Issue #24170 · moby/moby).
How can I create a emq cluster deployment properly?
The text was updated successfully, but these errors were encountered: