Implementation of Docker deployment of ElasticSearch and ElasticSearch-Head

Implementation of Docker deployment of ElasticSearch and ElasticSearch-Head

This article mainly explains how to deploy ElasticSearch: version 6.8.4 using Docker. It explains how to pull from Docker to finally run ElasticSearch and install ElasticSearch-Head, a small tool for managing ElasticSearch-related information. The search on the homepage of this blog system is implemented using ElasticSearch. Since ElasticSearch updates so quickly that SpringData-ElasticSearch cannot keep up with the updates of Es, I also downloaded version 8.x at the beginning, which caused SpringData-ElasticSearch to report an error. In the end, I chose 6.8.4. Record it here

1. Docker deployment of ElasticSearch: version 6.8.4

1.1 Pull the image

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.8.4

1.2 Run the container

The default port of ElasticSearch is 9200. We map the host environment port 9200 to the Docker container port 9200, and then we can access the ElasticSearch service in the Docker container. At the same time, we name this container es.

docker run -d --name es -p 9200:9200 -p 9300:9300 
-e "discovery.type=single-node" 
-e ES_JAVA_OPTS="-Xms=256m -Xms=256m" 
docker.elastic.co/elasticsearch/elasticsearch:6.8.4

illustrate:

-e discovery.type=single-node: indicates single-node startup

-e ES_JAVA_OPTS="-Xms=256m -Xms=256m" : Indicates setting the memory size for es startup. This really needs to be set, otherwise there will be insufficient memory later, such as my own crappy server!

1.3 Insufficient memory

After centos downloads elasticsearch and modifies the configuration, run the docker command:

It was found that the startup was not successful. After removing the -d in the command, the error printed was as follows

Java HotSpot(TM) 64-Bit Server VM warning: INFO:
os::commit_memory(0x0000000085330000, 2060255232, 0) failed;
error='Cannot allocate memory' (errno=12)

After some searching, I found that this was because the default JVM space size allocated by elasticsearch6.0 was 2g, and the memory was insufficient for allocation.

The solution is to modify the jvm space allocation run command:

find /var/lib/docker/overlay/ -name jvm.options

Find the jvm.options file and use the vi command to open the jvm.options file as follows:

-Xms2g 
-Xmx2g
Modified to -Xms512m 
-Xmx512m

Just save and exit. Run the create and run elasticsearch command again and it will start successfully.

2. Docker deployment ElasticSearch-Heard

2.1 Pull the image

docker pull mobz/elasticsearch-head:5

2.2 Run the container

docker create --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5

2.3 Start the container

docker start elasticsearch-head

2.4 Open the browser: http://IP:9100

I found that I couldn't connect because there was a cross-domain problem. Because the front-end and back-end were developed separately, I needed to set up es

2.5 Enter the es container that has just been started, container name = es

docker exec -it es /bin/bash

2.6 Modify the elasticsearch.yml file

vi config/elasticsearch.yml

Add to

http.cors.enabled: true
http.cors.allow-origin: "*"

In fact, SpringBoot's yml file adds cross-domain support

2.7 Exit the container and restart

exit
docker restart es

2.8 Visit http://localhost:9100

Summarize:

This article simply explains how to install ElasticSearch with Docker and the pitfalls you may encounter, including insufficient memory or too high a version, as well as the installation and cross-domain configuration of ElasticSearch-Heard. The next article will explain how to install the Chinese word segmenter in ElasticSearch.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Problems and solutions for installing ElasticSearch and Kibana in Docker
  • How to install Elasticsearch7.6 cluster in docker and set password
  • How to install ElasticSearch on Docker in one article
  • Tutorial on installing Elasticsearch 7.6.2 in Docker
  • Teach you how to install elasticsearch and head plug-ins using docker

<<:  Specific operations of MYSQL scheduled clearing of backup data

>>:  Vue two fields joint verification to achieve the password modification function

Recommend

Detailed explanation of new relational database features in MySQL 8.0

Preface The latest version of MySQL 8.0 is 8.0.4 ...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

New usage of watch and watchEffect in Vue 3

Table of contents 1. New usage of watch 1.1. Watc...

How to change the website accessed by http to https in nginx

Table of contents 1. Background 2. Prerequisites ...

Vue implements a simple shopping cart example

This article example shares the specific code of ...

Detailed tutorial for installing MySQL on Linux

MySQL downloads for all platforms are available a...

Basic reference types of JavaScript advanced programming

Table of contents 1. Date 2. RegExp 3. Original p...

5 cool and practical HTML tags and attributes introduction

In fact, this is also a clickbait title, and it c...

js to realize the mouse following game

This article shares the specific code of js to im...

Detailed steps for remote deployment of MySQL database on Linux

Linux remote deployment of MySQL database, for yo...

A brief discussion on the correct posture of Tomcat memory configuration

1. Background Although I have read many blogs or ...

Detailed explanation of the seven data types in JavaScript

Table of contents Preface: Detailed introduction:...