{"id":3877,"date":"2018-04-26T18:27:59","date_gmt":"2018-04-26T14:27:59","guid":{"rendered":"https:\/\/nayarweb.com\/blog\/?p=3877"},"modified":"2018-04-27T18:22:39","modified_gmt":"2018-04-27T14:22:39","slug":"elasticsearch-on-docker-swarm-with-nginx","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2018\/elasticsearch-on-docker-swarm-with-nginx\/","title":{"rendered":"Elasticsearch on Docker Swarm with NGINX"},"content":{"rendered":"<p><strong>On all Hosts:<\/strong><\/p>\n<pre>sudo sysctl -w vm.max_map_count=262144<\/pre>\n<p><strong>On Host 1:<\/strong><\/p>\n<p>1. We initialize a docker swarm. Add `&#8211;advertise-addr X.X.X.X` if inside a private network<\/p>\n<pre># docker swarm init<\/pre>\n<p>1. We create a network on docker<\/p>\n<pre># docker network create --driver overlay --subnet 10.0.10.0\/24   --opt encrypted elastics<\/pre>\n<p>&#8220;Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other.&#8221; [2]<\/p>\n<p>2. We initialize the docker containers with 3 copies<\/p>\n<pre>docker service create --name elasticsearch --network=elastics \\\r\n  --replicas 3 \\\r\n  --env SERVICE_NAME=elasticsearch \\\r\n  --env \"ES_JAVA_OPTS=-Xms256m -Xmx256m -XX:-AssumeMP\" \\\r\n  --publish 9200:9200 \\\r\n  --publish 9300:9300 \\\r\n  youngbe\/docker-swarm-elasticsearch:5.5.0\r\n<\/pre>\n<p>3. We get the command to generate the joining link<\/p>\n<pre># docker swarm join-token worker\r\nTo add a worker to this swarm, run the following command:\r\n\r\n    docker swarm join \\\r\n    --token SWMTKN-TOKEN \\\r\n    X.X.X.X:2377\r\n<\/pre>\n<p><strong>On Worker Host <\/strong><br \/>\n1. Type the command from the last step from host 1<\/p>\n<pre># docker swarm join \\\r\n    --token TOKEN \\\r\n    X.X.X.X:2377\r\n<\/pre>\n<p><strong>On Master 1<\/strong><\/p>\n<p>1. We now setup nginx<\/p>\n<pre>docker service create --name meranginx --network=elastics  nginx<\/pre>\n<pre>docker service create --name nginx --network=elastics --mount type=bind,source=\/root\/meradockernginx\/elasticsearch.conf,destination=\/etc\/nginx\/conf.d\/elasticsearch.conf nginx<\/pre>\n<p>To be continued&#8230;<br \/>\n#TODO: make a conf file for nginx which listens on port 9200 and uses `elasticsearch` as backend server<\/p>\n<p>References:<\/p>\n<p>[1] https:\/\/github.com\/imyoungyang\/docker-swarm-elasticsearch<br \/>\n[2] https:\/\/docs.docker.com\/network\/#network-drivers<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On all Hosts: sudo sysctl -w vm.max_map_count=262144 On Host 1: 1. We initialize a docker swarm. Add `&#8211;advertise-addr X.X.X.X` if inside a private network # docker swarm init 1. We create a network on docker # docker network create &#8211;driver overlay &#8211;subnet 10.0.10.0\/24 &#8211;opt encrypted elastics &#8220;Overlay networks connect multiple Docker daemons together and enable &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2018\/elasticsearch-on-docker-swarm-with-nginx\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Elasticsearch on Docker Swarm with NGINX<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3877","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=3877"}],"version-history":[{"count":3,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3877\/revisions"}],"predecessor-version":[{"id":3880,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3877\/revisions\/3880"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=3877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=3877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=3877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}