Virtualbox Linux installs elasticsearch and Chinese word segmentation ik

Time:2022-11-23

The premise of this article

jdk installed on Linux

The goal of this article

Install elasticsearch on Linux and install Chinese word segmentation

Install ElasticSearch (ES)

1. Official website download

Official website link:Link
Because the ik Chinese word segmentation will be installed later, and the versions of ES and ik must be corresponding, so it is recommended to go to ik to see if there is a corresponding version of the Chinese word segmentation
ik link:Link
Another thing to note is that jdk8 does not support es8.0 and above
I choose version 7.17.6, ES and IK have corresponding versions, and jdk8 also supports

2. Upload files

create folder first

mkdir /usr/es

Then transfer the file to this folder, finalshell is more convenient, just drag it in

3. Unzip the file

cd /usr/es
tar -zxvf elasticsearch-7.17.6-linux-x86_64.tar.gz

4. Linux configuration

Some Linux configurations need to be changed before running

vi /etc/security/limits.conf

Add the following two lines, with an asterisk at the top, don’t miss it

* soft nofile 65536
* hard nofile 65536

There is one more place to change

vi /etc/sysctl.conf

Add the following line

vm.max_map_count=262144

The above changes need to restart the virtual machine to take effect
Validate changes after reboot

#See if the result is vm.max_map_count = 262144
sysctl -p

#See if the result is 65536
ulimit -Hn
ulimit -Sn

5. ES configuration

 vi /usr/es/elasticsearch-7.17.6/config/elasticsearch.yml

Find network.host and change to

network.host: 0.0.0.0

Add the following two lines

discovery.seed_hosts: ["127.0.0.1"]

cluster.initial_master_nodes: ["node-1"]

6. run

cd elasticsearch-7.17.6/bin/
./elasticsearch

Generally, an error will be reported here, so you need to switch to a non-root user
Virtualbox Linux installs elasticsearch and Chinese word segmentation ik

7. Create user

#Create a user named esuser
 adduser esuser
#set password
 passwd esuser
#Authorization, /usr/es/ is the installation directory of es
chown -R esuser /usr/es/
#Switch to esuser user
su esuser

8. run

#Switch to esuser user
su esuser
#Switch to the installation directory
cd elasticsearch-7.17.6/bin/
./elasticsearch -d

The -d parameter represents running in the background, if there is no -d parameter, it is running in the foreground

9. Verify

I chose to run in the background. After a while, if there is no error, enter the following command to verify

 curl http://127.0.0.1:9200

Virtualbox Linux installs elasticsearch and Chinese word segmentation ik
If an error is reported at startup, solve the problem first

10. The method of restarting es
For the time being, I can only think of the kill process to end

#List es processes
ps aux|grep elasticsearch
#kill the first process
kill -9 process number

# then reboot

Install Chinese word segmentation IK

1. Download

ik link:Link
Note that it must be consistent with the ES version

2. Create a directory

cd /usr/es/elasticsearch-7.17.6
mkdir plugins/ik

3. File upload

Upload the downloaded file to the /usr/es/elasticsearch-7.17.6/plugins/ik directory

4. Unzip

unzip elasticsearch-analysis-ik-7.17.6.zip 

5. Restart ES

#List es processes
ps aux|grep elasticsearch
#kill the first process
kill -9 process number

cd /usr/es/elasticsearch-7.17.6/bin/
./elasticsearch -d

6. Verify word segmentation effect

Enter the following command in the Linux terminal

curl --location --request POST 'http://127.0.0.1:9200/_analyze' --header 'Content-Type: application/json' --data '{"analyzer": "ik_max_word","text": "I am Chinese"}'