[Docker] The correct way to install the Elasticsearch service with Docker


点击跳转:Docker安装MySQL、Redis、RabbitMQ、Elasticsearch、Nacos等常见服务全套(质量有保证,内容详情)

1. What is Elasticsearch?

Elaticsearch, referred to as es, is an open source, highly scalable distributed full-text search engine that can store and retrieve data in near real-time. It has good scalability and can be expanded to hundreds of servers to process PB-level data. es is also developed in Java and uses Lucene as its core to implement all indexing and search functions, but its purpose is to hide the complexity of Lucene through a simple RESTful API to make full-text search simple.

2. Docker install Elasticsearch

The most important thing when installing Elasticsearch is to determine the version of Elasticsearch! Determine the Elasticsearch version according to your Spring Boot project. Other es-related services must be consistent with the es version during installation. How to determine the Elasticsearch version is the focus of this article! Version, version, version, say important things three times!

2.1 Determine the Elasticsearch version

Version compatibility is very important when integrating the Spring Boot project with es . Incompatible versions will cause unexpected errors or directly lead to unusability, so the version must be determined before installing es. Version compatibility Check the official compatibility matrix . The details are as follows:

Take the above figure as an example: Assume that the version of our Spring Boot project is 2.1.x, then the minimum version of es required is 6.2.2. Note that it is the minimum version. If it still cannot be used normally during testing, the version of es needs to be modified to 6.2. 2 but preferably not exceeding the limits of the previous one (6.8.12 in the table above).

The author has encountered that the Spring Boot version of the project is 2.1.3.RELEASE. According to the compatibility requirements, es 6.2.2 was used. After installation, it was found that not only the Spring Boot project could not start normally but also es 6.2.2 version did not have a corresponding version. The Chinese word segmenter IKAnalyzer corresponds to it, so it became normal after adjusting to the adjacent 6.6.2.

2.2. Docker installation of Elasticsearch

Take Elasticsearch version 6.6.2 as an example:

  • Install Elasticsearch
# 注意下:Elasticsearch的Docker镜像是Elasticsearch官方自己维护的
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-d "docker.elastic.co/elasticsearch/elasticsearch:6.6.2"

Note: the Docker image of es is officially maintained by es itself. Docker installation es official reference

  • View container logs:
docker logs -f elasticsearch
  • Whether the access will return version information: http://localhost:9200

2.3. Install the Chinese word segmenter IKAnalyzer for Elasticsearch (optional)

Take Elasticsearch version 6.6.2 as an example:

  • Download the Chinese word segmenter IKAnalyzer, pay attention to download the version corresponding to es, download address: https://github.com/medcl/elasticsearch-analysis-ik/releases

  • Copy the installation package to a specific directory of the container/usr/share/elasticsearch
docker cp elasticsearch-analysis-ik-6.6.2.zip elasticsearch:/usr/share/elasticsearch
  • Unzip to /usr/share/elasticsearch/pluginsthe directory of the es container

Pay attention to the directory structure, do not have one more or less directory

  • Restart the service:
docker restart elasticsearch
  • Check the logs again and visit http://localhost:9200
docker logs -f elasticsearch

Guess you like

Origin blog.csdn.net/yuchangyuan5237/article/details/132014872