{"id":21939,"date":"2024-02-13T21:16:29","date_gmt":"2024-02-13T20:16:29","guid":{"rendered":"https:\/\/www.oderland.se\/support\/artikel\/how-do-i-install-opensearch-in-the-oderland-cloud\/"},"modified":"2024-02-13T21:25:57","modified_gmt":"2024-02-13T20:25:57","slug":"how-do-i-install-opensearch-in-the-oderland-cloud","status":"publish","type":"ht_kb","link":"https:\/\/www.oderland.se\/support\/en\/artikel\/how-do-i-install-opensearch-in-the-oderland-cloud\/","title":{"rendered":"How do I install OpenSearch in Oderland Cloud?"},"content":{"rendered":"\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">This guide is based on a Debian 12 image, with flavor a1-c1-m4 (1 core, 4GB ram) and a 10GB boot disk.<\/p>\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">We have chosen <a href=\"https:\/\/caddyserver.com\/\" data-type=\"link\" data-id=\"https:\/\/caddyserver.com\/\">Caddy<\/a> as a reverse proxy with automatic TLS support and basic auth, but there are other options such as traefik, nginx or configuring the OpenSearch security plugin with certificates or using certbot.<\/p>\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"196\" src=\"https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-1024x196.png\" alt=\"OpenSearch logo\" class=\"wp-image-21928\" srcset=\"https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-1024x196.png 1024w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-300x57.png 300w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-768x147.png 768w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-50x10.png 50w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-60x11.png 60w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default-100x19.png 100w, https:\/\/www.oderland.se\/support\/wp-content\/uploads\/2024\/02\/opensearch_logo_default.png 1486w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n<h2 class=\"wp-block-heading\">What is OpenSearch and why do I want to install it?<\/h2>\n\n<p>OpenSearch is a distributed search and analysis engine based on Apache Lucene.<\/p>\n\n<p>It is used as a tool to assist in searches, analysis and monitoring.<\/p>\n\n<p>Some systems such as Magento, WordPress, etc. can use this to speed up and make search more relevant.<\/p>\n\n<h3 class=\"wp-block-heading\">ElasticSearch or OpenSearch?<\/h3>\n\n<p>The choice is yours. OpenSearch is a fork of ElasticSearch 7.10.2, the last version before ElasticSearch changed its license form.<\/p>\n\n<h3 class=\"wp-block-heading\">Where can I find more documentation on OpenSearch?<\/h3>\n\n<p><a href=\"https:\/\/opensearch.org\/\">https:\/\/opensearch.org\/<\/a><\/p>\n\n<h3 class=\"wp-block-heading\">Please note<\/h3>\n\n<p>This guide describes how you can set up OpenSearch with a reverse proxy in front that handles automatic certificates and password login.<\/p>\n\n<p>However, it does not address how to set up a cluster for OpenSearch, which is recommended if you are going to run it in production.<\/p>\n\n<p>It also doesn&#8217;t address how to setup firewall \/ security groups in<a href=\"https:\/\/www.oderland.se\/cloud\/\" data-type=\"link\" data-id=\"https:\/\/www.oderland.se\/cloud\/\">Oderland Cloud<\/a> if you need to lock down access from an IP address e.g. if you want to restrict access from another Cloud server or from our other services such as <a href=\"https:\/\/www.oderland.se\/managed-server\/\" data-type=\"link\" data-id=\"https:\/\/www.oderland.se\/managed-server\/\">Managed Server<\/a>, <a href=\"https:\/\/www.oderland.se\/losningar\/byraer\/\" data-type=\"link\" data-id=\"https:\/\/www.oderland.se\/losningar\/byraer\/\">Agency<\/a> or <a href=\"https:\/\/www.oderland.se\/webbhotell\/\" data-type=\"link\" data-id=\"https:\/\/www.oderland.se\/webbhotell\/\">Web Hosting<\/a>.<\/p>\n\n<h2 class=\"wp-block-heading\">Execution<\/h2>\n\n<p>We create a server in Oderland Cloud with Docker Engine and point a hostname (e.g. domain or subdomain) to the new IP address of the server.<\/p>\n\n<p>We then ssh into the server. Then we create a docker network that we name caddy. It is used for the containers you want to get automatic TLS (https:\/\/).<\/p>\n\n<p>We create a folder structure as well as a docker-compose.yml file that tells us which services to run and how to configure them, specifying the same hostname we pointed to the server.<\/p>\n\n<p>We create a password using Caddy hash-password to use for basic auth in the docker-compose.yml file.<\/p>\n\n<p>Then we start up our new docker compose stack and test that we get certificates and a response from OpenSearch.<\/p>\n\n<h3 class=\"wp-block-heading\">Preparations<\/h3>\n\n<p>First create a server in Oderland Cloud with Docker, check out one of the guides below if you need help.<\/p>\n\n<p><a href=\"https:\/\/www.oderland.se\/support\/artikel\/sa-installerar-du-en-ny-server-med-docker-engine-i-oderland-cloud\/\">https:\/\/www.oderland.se\/support\/artikel\/sa-installerar-du-en-ny-server-med-docker-engine-i-oderland-cloud\/<\/a><\/p>\n\n<p><a href=\"https:\/\/www.oderland.se\/support\/artikel\/sa-installerar-du-docker-engine-i-oderland-cloud\/\">https:\/\/www.oderland.se\/support\/artikel\/sa-installerar-du-docker-engine-i-oderland-cloud\/<\/a><\/p>\n\n<h3 class=\"wp-block-heading\">Point hostname (domain or subdomain)<\/h3>\n\n<p><a href=\"https:\/\/www.oderland.se\/support\/artikel\/hur-pekar-jag-mitt-domannamn-mot-min-vps\/\" data-type=\"link\" data-id=\"https:\/\/www.oderland.se\/support\/artikel\/hur-pekar-jag-mitt-domannamn-mot-min-vps\/\">Point an appropriate hostname<\/a> to the server&#8217;s ipv4 address. You need to do this step for us to get a TLS certificate from Letsencrypt automatically.<\/p>\n\n<h3 class=\"wp-block-heading\">Expanding virtual memory and joining the docker group<\/h3>\n\n<p>SSH into the server.<\/p>\n\n<p>We will run all commands as the debian user, but need to use sudo occasionally.<\/p>\n\n<p>Start by joining the docker group and activating it for your session.<\/p>\n\n<p>We also need to extend vm.max_map_count as OpenSearch can otherwise cause some out of memory exceptions.<\/p>\n\n<pre class=\"wp-block-preformatted\">sudo usermod -aG docker $USER\nnewgrp docker\necho 'vm.max_map_count=262144' | sudo tee -a \/etc\/sysctl.d\/opensearch.conf\nsudo sysctl -p<\/pre>\n\n<h3 class=\"wp-block-heading\">Creating a Docker network<\/h3>\n\n<p>Create a docker network that we use for the containers we want to proxy via Caddy and automatically manage Let&#8217;s Encrypt\/Zero SSL to get secure connectivity.<\/p>\n\n<pre class=\"wp-block-preformatted\">docker network create caddy<\/pre>\n\n<h3 class=\"wp-block-heading\">Create a hashed password for Basic Auth to Caddy<\/h3>\n\n<p>We use the hash-password command from Caddy to hash a password. <strong>Do not copy the text below, but replace the text PASSWORD with a good password<\/strong>that you will need to use in your application to connect to OpenSearch.<\/p>\n\n<p>We replace $ with $$ with sed so that the hash will work in docker-compose.yml, otherwise it will be interpreted as variables.<\/p>\n\n<pre class=\"wp-block-preformatted\">docker run --rm lucaslorentz\/caddy-docker-proxy:ci-alpine hash-password --plaintext PASSWORD|sed 's\/\\$\/\\$\\$\/g'\n<\/pre>\n\n<h3 class=\"wp-block-heading\">Set up the docker-compose.yml file<\/h3>\n\n<p>Now we create the folder for the docker-compose.yml file and add the text below.<br\/>Replace <strong>HASHED_PASSWORD<\/strong> with the password hash you got above.<\/p>\n\n<pre class=\"wp-block-preformatted\">mkdir -p ~\/compose\/opensearch\ncat <eof> ~\/compose\/opensearch\/docker-compose.yml\nversion: \"3.7\"  \n \nservices:  \n  caddy:  \n  image: lucaslorentz\/caddy-docker-proxy:ci-alpine  \n  ports:  \n  - 80:80  \n  - 443:443  \n  environment:  \n  - CADDY_INGRESS_NETWORKS=caddy  \n  networks:  \n  - caddy  \n  volumes:  \n  - \/var\/run\/docker.sock:\/var\/run\/docker.sock  \n  - caddy_data:\/data  \n  restart: unless-stopped  \n  opensearch:  \n  image: opensearchproject\/opensearch:2.11.1\n  volumes:  \n  - osdata01:\/usr\/share\/opensearch\/data\n  environment:\n  - \"cluster.name=opensearch-cluster\"\n  - \"node.name=os-node01\"\n  - \"discovery.type=single-node\"\n  - \"bootstrap.memory_lock=true\"\n  - \"plugins.security.disabled=true\"\n  - \"OPENSEARCH_JAVA_OPTS=-Xms2G -Xmx2G\"\n  labels:\n  caddy: HOSTNAME\n  caddy.reverse_proxy: \"{{upstreams 9200}}\"\n  caddy.basicauth: \/*\n  caddy.basicauth.admin: HASHED_PASSWORD\n  networks:\n  - caddy\n  ulimits:\n  memlock:\n  soft: -1\n  hard: -1\n  nofile:\n  soft: 65536\n  hard: 65536\n  restart: unless-stopped\n\nvolumes:\n  osdata01:\n  driver: local\n  caddy_data:\n  driver: local\n\nnetworks:\n  caddy:\n  external: true\nEDF<\/eof><\/pre>\n\n<p>We also set the maximum memory usage for the Java engine to 2GB above. You may need to increase this as well as the server&#8217;s memory if you have large indexes.<\/p>\n\n<h3 class=\"wp-block-heading\">Enter your host name<\/h3>\n\n<p>If you have specified a hostname that you want to use for the server or for OpenSearch, you can now edit the code snippet above and change HOSTNAME to your chosen hostname. You can also do it afterwards with the sed command shown below.<\/p>\n\n<p>For demo purposes, we created os.oderland.cloud so that we can then go to https:\/\/ os.oderland.cloud to reach OpenSearch. The example looks like this with the sed command.<\/p>\n\n<pre class=\"wp-block-preformatted\">sed -i 's\/HOSTNAME\/os.oderland.cloud\/g' ~\/compose\/opensearch\/docker-compose.yml<\/pre>\n\n<h3 class=\"wp-block-heading\">Starting up OpenSearch and Caddy<\/h3>\n\n<p>Then launch our new docker compose stack.<\/p>\n\n<pre class=\"wp-block-preformatted\">cd ~\/compose\/opensearch\ndocker compose up -d<\/pre>\n\n<p>All images\/layers are then downloaded and the services start up.<\/p>\n\n<p>You can follow the log via:  <\/p>\n\n<pre class=\"wp-block-preformatted\">docker compose logs -f<\/pre>\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n<h3 class=\"wp-block-heading\">Change host name<\/h3>\n\n<p>If you edit the docker-compose.yml file afterwards and change to another hostname, you need to restart the stack and force new configs via:<\/p>\n\n<pre class=\"wp-block-preformatted\">docker compose up --force-recreate -d<\/pre>\n\n<h3 class=\"wp-block-heading\">How to control the Caddy Proxy<\/h3>\n\n<p><a href=\"https:\/\/github.com\/lucaslorentz\/caddy-docker-proxy#reverse-proxy-examples\" data-type=\"link\" data-id=\"https:\/\/github.com\/lucaslorentz\/caddy-docker-proxy#reverse-proxy-examples\">Read more about the Caddy proxy<\/a> and how you can control via e.g. paths or how to add more domains to the same service.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is OpenSearch and why do I want to install it? OpenSearch is a distributed search and analysis engine based on Apache Lucene. It is used as a tool to assist in searches, analysis and monitoring. Some systems such as Magento, WordPress, etc. can use this to speed up and&#8230;<\/p>\n","protected":false},"author":15,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"ht-kb-category":[682],"ht-kb-tag":[],"class_list":["post-21939","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-cloud-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/21939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/comments?post=21939"}],"version-history":[{"count":5,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/21939\/revisions"}],"predecessor-version":[{"id":21946,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/21939\/revisions\/21946"}],"wp:attachment":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/media?parent=21939"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb-category?post=21939"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=21939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}