In the previous article “How to Install Elasticsearch on Linux, Mac OS, and Windows”, I showed you how to install Elasticsearch by installing a package or downloaded zip file. In today’s article, we’ll cover the details of how to install Elastic stacks using Docker.

 

The installation

Since we need to use Docker to install, we must install:

  1. Docker: Install docker according to the operating system requirements. Go to docs.docker.com/ to install it
  2. Docker – compose. This can go to the website docs.docker.com/compose/ins… To install

Install Elasticsearch with Docker

For a list of all published Docker images and tags, visit www.docker.elastic.co. The source file is on Github.

Download the docker image

Getting Elasticsearch from Docker is as simple as issuing the Docker pull command to the Elastic Docker registry.

Docker pull docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2Copy the code

Example of Elasticsearch 7.3.2 In practical use, you can replace it with your preferred version.

Development or test environment

Run Elasticsearch from the command line. To quickly start Elasticsearch for development or testing, use the following command:

Docker run - p - 9200-9200 p, 9300:9300 - e discovery. Type = "single - node" docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2Copy the code

Note the single-node discovery, which allows you to bypass the Bootstrap checks in a single-node development cluster.

The production environment

The m. map_count kernel must be set to at least 262144 to be used in the production environment. Depending on your platform:

  • Linux

The vm.max_map_count setting should be permanently set in /etc/sysctl.conf:

$ grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
Copy the code

To apply this setting on a real-time system, do the following:

sysctl -w vm.max_map_count = 262144
Copy the code
  • MacOS (Docker for Mac)

Max_map_count must be set in the Xhyve vm:

$ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
Copy the code

Just press Enter and configure sySCTL Settings as you would for Linux:

sysctl -w vm.max_map_count=262144
Copy the code
  • Windows and macOS (Docker Toolbox)

Max_map_count must be set by docker-machine:

docker-machine ssh
sudo sysctl -w vm.max_map_count=262144
Copy the code

Use Docker to install Kibana

For a list of all published Docker images and tags, visit www.docker.elastic.co. The source code is on GitHub.

Download the docker image

Docker pull docker. Elastic. Co/kibana/kibana: 7.3.2Copy the code

Development or test environment

You can use the following command to quickly launch Kibana and connect it to the local Elasticsearch container for development or testing:

docker run --link YOUR_ELASTICSEARCH_CONTAINER_NAME_OR_ID:elasticsearch -p 5601:5601 {docker-repo}:{version}
Copy the code

Select * from Elasticsearch docker where docker = > Elasticsearch docker where docker = > Elasticsearch docker

docker ps
Copy the code

The following information is displayed:

The CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3839 f34c1d2d docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 "/ usr/local/bin/dock..." 7 minutes ago Up 7 minutes 0.0.0.0:9200->9200/ TCP, 0.0.0.0:9300->9300/ TCP admiring_matsumotoCopy the code

The docker information above is the docker information of Elasticsearch already installed. We then execute the following command:

Docker run - link 3839 f34c1d2d: elasticsearch -p 5601:5601 docker. Elastic. The co/kibana/kibana: 7.3.2Copy the code

So our Kibana Docker gets up.

 

Start Elasticsearch and Kibana using Docker-compose

In this step, we assume we have downloaded the Docker image for Elasticsearch and Kibana. If you haven’t already done so, you can download it by executing the following command:

Docker pull docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 docker pull docker. Elastic. Co/kibana/kibana: 7.3.2Copy the code

Next, we will create a directory called docker and create a file called docker-comemess. yml in this directory. It reads as follows:

$ pwd
/Users/liuxg/elastic/docker
localhost:docker liuxg$ ls
docker-compose.yml
Copy the code

docker-compose.yml:

Version: '2.2' services: es01: image: docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 container_name: es01 environment: - node.name=es01 - discovery.seed_hosts=es02 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata01:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet es02: image: Docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 container_name: es02 environment: - node.name=es02 - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata02:/usr/share/elasticsearch/data networks: - esnet kibana: image: Docker. Elastic. Co/kibana/kibana: 7.3.2 container_name: kibana ports: [' 5601-5601] networks: [' esnet] environment: - SERVER_NAME=kibana.localhost - ELASTICSEARCH_HOSTS=http://es01:9200 - I18N_LOCALE=zh-CN - ELASTICSEARCH_USERNAME=elastic - ELASTICSEARCH_PASSWORD=mypasword depends_on: ['es01'] volumes: esdata01: driver: local esdata02: driver: local networks: esnet:Copy the code

In this configuration, we created two Elasticsearch nodes: ES01 and ES02. Node ES01 listens to localhost: 9200, while ES02 talks to ES01 over the Docker network. We also created another Kibana Docker. We can configure the required parameters in the environment. For details, see Configuring Kibana.

After creating the docker-comemage. yml file, type the following command in the current directory: docker-comemage. yml

docker-compose up
Copy the code

Or:

docker-compose up -d
Copy the code

The -d option here means that in detached mode, run the container in the background.

Results of the run:

 

We can finally see our Kibana launch in the browser:

 

And just like we did before, the Locale that it’s going to run in is Chinese. We can also see two Elasticsearch nodes enabled at the same time:

Once Docker is started, we can use the docker command to execute some commands, such as

docker exec es01 ls /usr/share/elasticsearch
Copy the code

We can enter docker for installation through the following command:

docker exec -it es01 /bin/bash
Copy the code
$ docker exec -it es01 /bin/bash
[root@ec4d19f59a7d elasticsearch]# ls
LICENSE.txt  README.textile  config  jdk  logs     plugins
NOTICE.txt   bin             data    lib  modules
[root@ec4d19f59a7d elasticsearch]# 
Copy the code

Here es01 is the name of our Elasticsearch instance.

We can also configure Kibana in the following way. We can create another file called kibana.yml in the docker-comemage. yml directory:

kibana.yml

#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
i18n.locale: "zh-CN"
xpack.monitoring.ui.container.elasticsearch.enabled: true
Copy the code

So here we’ve done some simple Settings, like we’ve set the locale to Chinese. We can modify our docker-comemage. yml file as follows:

docker-compose.yml

Version: '2.2' services: es01: image: docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 container_name: es01 environment: - node.name=es01 - discovery.seed_hosts=es02 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata01:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet es02: image: Docker. Elastic. Co/elasticsearch/elasticsearch: 7.3.2 container_name: es02 environment: - node.name=es02 - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata02:/usr/share/elasticsearch/data networks: - esnet kibana: image: Docker. Elastic. Co/kibana/kibana: 7.3.2 container_name: kibana networks: [' esnet] ports: [' 5601-5601] environment: - ELASTICSEARCH_HOSTS=http://es01:9200 volumes: - ./kibana.yml:/usr/share/kibana/config/kibana.yml volumes: esdata01: driver: local esdata02: driver: local networks: esnet:Copy the code

Here, we used the volumes in Kibana to bind the local kibana.yml file to the image in our Docker. It instead of the docker in/usr/share/kibana/config/kibana yml file to use. We set up in local kibana yml file.

When Docker has all containers running, we can check with the following command:

$ docker-compose ps Name Command State Ports -------------------------------------------------------------------------------- es01 /usr/local/bin/docker-entr ... Up 0.0.0.0:9200->9200/ TCP, 9300/ TCP es02 /usr/local/bin/docker-entr... Up 9200/tcp, 9300/tcp kibana /usr/local/bin/dumb-init - ... The Up 0.0.0.0:5601 - > 5601 / TCPCopy the code

It shows the usage of all ports.

 

We can stop all docker instances by:

docker-compose down
Copy the code

This allows us to quickly deploy our Elasticsearch cluster.

Customized version

As you can see from docker-comemage. yml above, all Elastic Stack components are the same version. If we want to change our version, we need to change every string. It’s more of a hassle. For convenience docker-compose allows us to create an invisible file called.env. It reads as follows:

$ pwd
/Users/liuxg/elastic5/docker
liuxg:docker liuxg$ ls -al
total 16
drwxr-xr-x   4 liuxg  staff   128 Mar 16 17:06 .
drwxr-xr-x  18 liuxg  staff   576 Feb  6 14:08 ..
-rw-r--r--   1 liuxg  staff    28 Mar 16 17:06 .env
-rw-r--r--@  1 liuxg  staff  1473 Dec 17 11:02 docker-compose.yml
liuxg:docker liuxg$ cat .env 
ELASTIC_STACK_VERSION=7.6.1
Copy the code

In this file, we can define ELASTIC_STACK_VERSION=7.6.1. Once defined in this way, we can modify our docker-comemage. yml to:

docker-compose.yml

Version: '2.2' Services: ES01: image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_STACK_VERSION} container_name: es01 environment: - node.name=es01 - discovery.seed_hosts=es02 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata01:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet es02: image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_STACK_VERSION} container_name: es02 environment: - node.name=es02 - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata02:/usr/share/elasticsearch/data networks: - esnet kibana: image: docker.elastic.co/kibana/kibana:${ELASTIC_STACK_VERSION} container_name: kibana ports: ['5601:5601'] networks: ['esnet'] environment: - SERVER_NAME=kibana.localhost - ELASTICSEARCH_HOSTS=http://es01:9200 - I18N_LOCALE=zh-CN - ELASTICSEARCH_USERNAME=elastic - ELASTICSEARCH_PASSWORD=mypassword depends_on: ['es01'] volumes: esdata01: driver: local esdata02: driver: local networks: esnet:Copy the code

In the future, if we want to change the version, we just need to change the version definition of the.env file.

further

If you want to learn how to configure secure access for our Docker-created Elasticsearch cluster, please read my other article “Elastic: Setting Security for An Elastic Docker Deployment”.

 

Elastic Stack Docker deployment

 

Reference:

【 1 】 www.elastic.co/guide/en/ki…

(2) www.elastic.co/guide/en/el…

【 3 】 github.com/BigDataBout…