{"id":538,"date":"2024-06-13T10:19:05","date_gmt":"2024-06-13T02:19:05","guid":{"rendered":"https:\/\/windywind.tk\/?p=538"},"modified":"2025-02-06T10:57:06","modified_gmt":"2025-02-06T02:57:06","slug":"%e7%94%a8docker-compose%e6%96%b9%e5%bc%8f%e9%83%a8%e7%bd%b2emqx%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/windywind.tk\/?p=538","title":{"rendered":"Deploy EMQX cluster with docker-compose"},"content":{"rendered":"\n<p>To create an EMQX cluster to provide MQTT service and keep it as simple as much, we can do it with docker and docker-compose only.<\/p>\n\n\n\n<p>Create <code>\/volumes\/emqx-data\/<\/code> on each node for persistent storage of configuration. Make sure to give write permissions.<\/p>\n\n\n\n<p>On the first node (192.168.31.61), create a <code>docker-compose.yaml<\/code> file with content below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3'\n\nservices:\n  emqx1:\n    image: emqx:5.5.0\n    container_name: emqx1\n    environment:\n    - \"EMQX_NAME=emqx1\"\n    - \"EMQX_HOST=192.168.31.61\"\n    - \"EMQX_NODE_NAME=emqx1@192.168.31.61\"\n    - \"EMQX_CLUSTER__DISCOVERY_STRATEGY=static\"\n    - \"EMQX_CLUSTER__STATIC__SEEDS=&#91;emqx1@192.168.31.61,emqx2@192.168.31.62,emqx3@192.168.31.63]\"\n    network_mode: \"host\"\n    healthcheck:\n      test: &#91;\"CMD\", \"\/opt\/emqx\/bin\/emqx_ctl\", \"status\"]\n      interval: 5s\n      timeout: 25s\n      retries: 5\n    volumes:\n      - \/volumes\/emqx-data\/emqx1_data:\/opt\/emqx\/data<\/code><\/pre>\n\n\n\n<p>On the second node (192.168.31.62), create a similar <code>docker-compose.yaml<\/code> file with content below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3'\n\nservices:\n  emqx1:\n    image: emqx:5.5.0\n    container_name: emqx2\n    environment:\n    - \"EMQX_NAME=emqx2\"\n    - \"EMQX_HOST=192.168.31.62\"\n    - \"EMQX_NODE_NAME=emqx2@192.168.31.62\"\n    - \"EMQX_CLUSTER__DISCOVERY_STRATEGY=static\"\n    - \"EMQX_CLUSTER__STATIC__SEEDS=&#91;emqx1@192.168.31.61,emqx2@192.168.31.62,emqx3@192.168.31.63]\"\n    network_mode: \"host\"\n    healthcheck:\n      test: &#91;\"CMD\", \"\/opt\/emqx\/bin\/emqx_ctl\", \"status\"]\n      interval: 5s\n      timeout: 25s\n      retries: 5\n    volumes:\n      - \/volumes\/emqx-data\/emqx2_data:\/opt\/emqx\/data<\/code><\/pre>\n\n\n\n<p>On the third node (192.168.31.63), similarly<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3'\n\nservices:\n  emqx1:\n    image: emqx:5.5.0\n    container_name: emqx3\n    environment:\n    - \"EMQX_NAME=emqx3\"\n    - \"EMQX_HOST=192.168.31.63\"\n    - \"EMQX_NODE_NAME=emqx3@192.168.31.63\"\n    - \"EMQX_CLUSTER__DISCOVERY_STRATEGY=static\"\n    - \"EMQX_CLUSTER__STATIC__SEEDS=&#91;emqx1@192.168.31.61,emqx2@192.168.31.62,emqx3@192.168.31.63]\"\n    network_mode: \"host\"\n    healthcheck:\n      test: &#91;\"CMD\", \"\/opt\/emqx\/bin\/emqx_ctl\", \"status\"]\n      interval: 5s\n      timeout: 25s\n      retries: 5\n    volumes:\n      - \/volumes\/emqx-data\/emqx3_data:\/opt\/emqx\/data<\/code><\/pre>\n\n\n\n<p>Enter the folder where the <code>docker-compose.yaml<\/code> file is located, execute <code>docker compose up -d<\/code><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/1-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"428\" height=\"74\" src=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/1-2.png\" alt=\"\" class=\"wp-image-559\" srcset=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/1-2.png 428w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/1-2-300x52.png 300w\" sizes=\"(max-width: 428px) 100vw, 428px\" \/><\/a><\/figure><\/div>\n\n\n<p>If nothing goes wrong, you should be able to see a running container with <code>STATUS<\/code> as <code>healthy<\/code>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/2-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"69\" src=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/2-1.png\" alt=\"\" class=\"wp-image-561\" srcset=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/2-1.png 875w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/2-1-300x24.png 300w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/2-1-768x61.png 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure><\/div>\n\n\n<p>By visiting the webpage http:\/\/192.168.31.61:18083 (default credentials: admin\/public), you should be able to see 3 nodes in cluster.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"530\" src=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1-1024x530.png\" alt=\"\" class=\"wp-image-562\" style=\"width:570px;height:auto\" srcset=\"https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1-1024x530.png 1024w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1-300x155.png 300w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1-768x397.png 768w, https:\/\/windywind.tk\/wp-content\/uploads\/2024\/06\/3-1.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n<p>If you need high-availability, you should carry on deploying nginx or HAProxy, or alternatively, utilize load balancers on cloud to distribute traffic to ports on these EMQX nodes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To create an EMQX cluster to provide MQTT service and k [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-2"],"_links":{"self":[{"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/posts\/538"}],"collection":[{"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/windywind.tk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":3,"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":563,"href":"https:\/\/windywind.tk\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions\/563"}],"wp:attachment":[{"href":"https:\/\/windywind.tk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/windywind.tk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/windywind.tk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}