preface

Elaticsearch, referred to as ES, is an open source and highly extensible distributed full-text search engine, which can store and retrieve data in near real time. Its scalability is very good, can be extended to hundreds of servers, processing PB level (big data era) of data. ES was developed by the Java language and uses Lucene as its core to implement all of its indexing and searching capabilities, but it is intended to make full-text searching simple by hiding the complexity of Lucene through a simple RESTFULL API. ElasticSearch overtook Solr to become the # 1 search engine app in January 2016, according to DB Engines.

1. Download and install ES (under Linux)

1.1. Download ES

Environment requirements: The JDK version must be at least 1.8 and the JAVA environment has been configured in the system

Download address: www.elastic.co/cn/download…

1.2. Install ES

1.2.1 Upload ES compressed package

After downloading the ES compressed package to the local computer, upload it to the server or virtual machine through XFTP to specify the folder location:

Next use the XShell tool to connect to the server or virtual machine

1.2.2. Decompress the ES package

Decompress the command tar -zxvf elasticSearch-7.6.1-linux-x86_64.tar. gz

Mv ElasticSearch-7.6.1 ElasticSearch7

1.2.3 Introduction to ES Directory

Bin: underneath where the Es boot file elasticsearch. Bat/elasticsearch config: configuration directory data: data directory JDK, lib: Java runtime environment and rely on package logs: log directory modules and plugins: Modules and plugins, head plugins can be stored in the plugins directoryCopy the code

1.3 ES Configuration

1.3.1 Basic Configuration

ES is actually a database, so we created a data folder under ElasticSearch7 to store data: MDkir Data

Go to the data folder and run the PWD command to copy the path of the folder.

Elasticsearch. yml = vim elasticSearch. yml = vim elasticSearch. yml = vim elasticSearch. yml = vim elasticSearch. yml = vim elasticSearch. yml = vim elasticSearch. yml

> > < span style = “box-sizing: border-box; word-break: break-all;

Such as: / usr/local/SRC/software/elasticsearch7 / logs, and then back to the config directory editors elasticsearch. Yml file:

1.4. Cross-domain Configuration

Add cross-domain permission at the end of elasticSearch. yml file in config directory:

Http.coron. enabled: true http.coron. allow-origin: "*" http.coron. allow-headers: Authorization,X-Requested-With,Content-Length,Content-TypeCopy the code

2. ES toggle plugin

ES comes with word segmentation by default, but it supports English word segmentation, so we need to install a plug-in that can be used for Chinese word segmentation

2.1 IK word segmentation download

We can then manipulate it using Xshell:

2.2. Decompress IK word segmentation package to ES plug-in folder

Create a new IK folder for elasticSearch7 plugins.

Then we decompress the IK word segmentation package into the IK file in the software folder: Unzip elasticsearch – analysis – ik – 7.6.1.zip -d/usr/local/SRC/software/elasticsearch7 / plugins/ik, if appear the following questions:

Yum install unzip zip: yum install unzip Unzip elasticsearch – analysis – ik – 7.6.1.zip -d/usr/local/SRC/software/elasticsearch7 / plugins/ik

Then we go to the IK directory to check whether the decompression is successful:

2.3 IK word segmentation configuration file

Default word segmentation configuration

Go to config directory under ik directory:

Take a look at the extra_main.doc configuration file:

It can be seen that the Chinese character related participle configuration is enumerated one by one in the configuration file!

3. Start and close the ES service

Go to the bin directory and run the./elasticsearch command to start the ES service. Run./ elasticSearch -d in the background

Close the ES service: ps – ef | grep elastic check process, and use kill 9 process id to the end of the process!

Problem number one may arise

Run ES on the server if the following error occurs during startup:

This situation shows that the memory is insufficient, the server (student computer 1 core 2g) memory is too small, not enough to start ES service, because ES default startup memory size required 2g!

Solution 1

Jvm. options config file to change the runtime size from 2g to 1g(if this still doesn’t work, go to 256m) :

Solution 2

Use the top command to view the processes that occupy a large amount of memory and end them:

Because I have Java projects running on my student computer, including Services such as ZooKeeper and Kafka, I changed my student computer to test them

Problem number two may arise

If the following problems occur:

You cannot start the ES service as the root user.

The solution

  • Create a new elasticsearch user and run the adduser elasticsearch command
  • Chown -r ElasticSearch elasticSearch7 command to grant permission to the elasticsearch folder in the software directory

  • Run the su elasticsearch command to switch to user elasticsearch and run the ES service in the bin directory again

Problem number three is possible

ERROR: bootstrap checks failed
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 
Copy the code

The solution

  • Conf vim /etc/sysctl.conf Is modified
  • Add the following configuration on the last line: vm.max_map_count=655360
  • Save the configuration and exit. Run the sysctl -p command

Then restart ElasticSearch.

Problem number four is possible

ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
Copy the code

The solution

Modify elasticSearch config file in the config directory of elasticSearch and add the following configuration to the file:

3.1 Ali Cloud opens the security group port

4. Test access to ES service

Access successful, indicating that ES started successfully!