【英文】通过Docker部署Elasticsearch

Preface

Deploying Elasticsearch with Docker

Creating a network

es-network: Defines a network name

1
docker network create es-network

Deploying Elasticsearch

Pulling the image

  • This example deploys version 7.12.1
1
docker pull elasticsearch:7.12.1

Creating directories for data volume mapping

1
2
mkdir -p /root/es/es-data
mkdir -p /root/es/es-plugins

Running the container

-e "ES_JAVA_OPTS=-Xms512m -Xmx512m": Specifies the JVM memory, default is 1T
-e "discovery.type=single-node": Specifies the startup mode as single-node mode
-v es-data:: Specifies the data storage directory
-v es-plugins:: Specifies the plugin directory
--network es-network: Specifies the network
-p 9200:9200: Maps the port for HTTP protocol interface
-p 9300:9300: Maps the port for communication between nodes

1
2
3
4
5
6
7
8
9
10
11
12
docker run \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-v /root/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /root/es/plugins:/usr/share/elasticsearch/plugins \
--privileged \
--network es-network \
-p 9200:9200 \
-p 9300:9300 \
-d \
elasticsearch:7.12.1

Done

Deploying Kibana

  • Kibana needs to be in the same network as Elasticsearch

Pulling the image

  • This example deploys version 7.12.1
1
docker pull kibana:7.12.1

Running the container

-e ELASTICSEARCH_HOSTS=http://es:9200: Specifies the address of the Elasticsearch container. If not specified, the default value is http://elasticsearch:9200
--network es-network: Specifies the network

1
2
3
4
5
6
7
docker run \
--name kibana \
-e ELASTICSEARCH_HOSTS=http://es:9200 \
--network es-network \
-p 5601:5601 \
-d \
kibana:7.12.1

Done

Deploying ik analyzer

  • Elasticsearch’s default analyzer is not very good for Chinese, so you can use medcl/elasticsearch
1
2
3
4
docker exec -it es /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip
exit
docker restart es

Manually downloading ik analyzer

  • If the network is not good, you can manually download the ik analyzer and put it in the plugin directory of Elasticsearch. Then re-run the installation operation and it will skip the download automatically
  • Restart Elasticsearch to complete the plugin loading
1
2
3
4
5
6
7
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip
mv ./elasticsearch-analysis-ik-7.12.1.zip /root/es/es-plugins/

docker exec -it es /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip
exit
docker restart es
  • Alternatively, you can manually unzip and restart Elasticsearch to complete the plugin loading
1
2
3
4
5
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip
mv ./elasticsearch-analysis-ik-7.12.1.zip /root/es/es-plugins/
cd /root/es/es-plugins/
unzip elasticsearch-analysis-ik-7.12.1.zip
docker restart es

If it is an Elasticsearch cluster, the entire cluster needs to be restarted after installing the plugin to complete the plugin loading.

Deploying pinyin analyzer

  • Querying Chinese word groups using the initials of Chinese pinyin
1
2
3
4
docker exec -it es /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.12.1/elasticsearch-analysis-pinyin-7.12.1.zip
exit
docker restart es

Pitfalls

  • Error when pulling Kibana image: no matching manifest for linux/arm64/v8 in the manifest list entries

Cause

  • Incompatibility between Apple Silicon and Intel

Solution

  • Force pulling the x86_64 architecture image

--platform linux/x86_64: If there are multiple versions of the image for different architectures, specify the architecture to pull

1
docker pull --platform linux/x86_64 kibana:7.12.1

Pitfalls

  • After running the Kibana container, the access to the management page is unsuccessful, with frontend error: Kibana server is not ready yet, and backend errors: License information could not be obtained from Elasticsearch due to Error: No Living connections and Unable to retrieve version information from Elasticsearch nodes.

Cause

  • Incorrect Elasticsearch address configured in Kibana
  • The default value of Elasticsearch address configured in the file config/kibana.yml is elasticsearch.hosts: [ "http://elasticsearch:9200" ]

Solution

Method 1

  • Change the name of Elasticsearch to elasticsearch when starting it

Method 2

  • Modify the configuration of Elasticsearch address in the file config/kibana.yml

Method 3

  • Specify the environment variable -e ELASTICSEARCH_HOSTS=http://es:9200 when running the container, based on the current Elasticsearch address

Done

References

哔哩哔哩——黑马程序员
CSDN——会写代码的花城
[CSDN——Elsez](https://blog.csdn.net/zhanxiaozhangA/art