ElasticSearch7.9.2 installation and configuration under Linux (including server configuration, start and stop scripts, open ports and use of elasticsearch-head plug-ins)

foreword

This article mainly introduces the installation of ElasticSearch7.9.2 under Linux, and currently introduces the configuration of a single node

application Version illustrate
operating system centos7 Stable, highly predictable, highly manageable, and highly repeatable Linux platform
elasticsearch 7.9.2 Linux version of es7.x
jdk 8 I use JDK 8; ES recommends using JDK 11. There will be a warning but no error when starting, which can be ignored

1. Download and install

1.1 Download using wget

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz

insert image description here

1.2 Official website download

This method may be slow and requires patience. Official website download: Elasticsearch 7.9.2
select Linux tar package mode to download, and then upload to the server directory
insert image description here

2. Upload to the server and decompress

Unzip command:

tar -zxvf elasticsearch-7.6.1-linux-x86_64.tar.gz 

insert image description here

3. Modify the es configuration file

3.1 Introduction to es directory

  • bin: The Es startup file elasticsearch.bat/elasticsearch is stored below
  • config: configuration directory
  • data: data directory
  • jdk, lib: Java runtime environment and dependent packages
  • logs: log directory
  • modules, plugins: modules and plugin directories, head plugins can be stored in the plugins directory

3.2 Modify the configuration file

Note path.dataand path.logsneed to configure the specified path

#默认的集群名称,在集群配置多个节点时需要保持一致,单机可暂不关注
cluster.name: elasticsearch
node.name: es-node0
cluster.initial_master_nodes: ["es-node0"]

# 指定数据存储位置
path.data: /data1/elasticsearch-7.9.2/data
 
#日志文件位置
path.logs: /data1/elasticsearch-7.9.2/logs

#默认只允许本机访问,修改为0.0.0.0后则可以允许任何ip访问
network.host: 0.0.0.0

#设置http访问端口,9200是http协议的RESTful接口,注意端口冲突可修改
http.port: 9200

# 跨域问题配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

4. Create user and authorize

1. Create a user first

you are brought

2.es user creation password

passwd es

insert image description here
3. Create a group

chown en:en -R /data1/elasticsearch-7.9.2

insert image description here

5. Server modification configuration

Both steps 5.1 and 5.2 below are requiredsystem restart, you can follow the steps first, then restart once

5.1 Modify the number of file handles and threads

Prevent es users from creating file permissions that are too low to cause errors

vim  /etc/security/limits.conf

Add the following:

#句柄
es  soft nofile 65536
es  hard nofile 65536
#线程
es  soft nproc 4096
es  hard nproc 4096

After saving and exiting, the system needs to be restarted!

The above configuration is to solve:

Error reporting problem: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
problem description: the permission of the elasticsearch user to create file descriptions is too low, at least 65536 is required;

重启服务器post-authentication

su es
ulimit -Hn
ulimit -Sn
ulimit -Hu
ulimit -Su

5.2 Turn off swapping

Official suggestion: 把内存的一半给Lucene+不要超过32G+关闭swap
ES recommends turning off the swap memory swap space and disabling swapping. Because when the memory is swapped to the disk, an operation of 100 microseconds may become 10 milliseconds, and then the operation delay of 100 microseconds adds up. It can be seen that the impact of swapping on performance is fatal

vim /etc/fstab

The comment contains the swap line
insert image description here
After saving and exiting, the system needs to be restarted!

Before comment:
insert image description here
After comment:
insert image description here

5.3 Modify virtual memory

vim /etc/sysctl.conf

Add the following:

vm.max_map_count=262144

Save and exit, refresh the configuration file

sysctl -p

Verify whether the modification is successful

sysctl vm.max_map_count

The above configuration is to solve:

Error report: max virtual memory areas vm.max_map_count [65530] is too low,
increase to at least [262144]

6. Start es

6.1 Run and start es in the foreground (not recommended)

Switch the user to es, use the es user to start elasticsearch,此种方式Ctrl + C 则程序终止

# 切换到es用户,使用root用户启动会报错
su es

# 进入到es的bin目录
cd /data1/elasticsearch-7.9.2/bin

# 执行启动脚本,此种方式Ctrl + C 则程序终止
./elasticsearch

insert image description here
ctrl + c to stop running
insert image description here

Note: If the root user starts, an error will be reported
Error problem: org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as roots
Problem description: Can not be started with root user, must create es user to start
insert image description here

6.2 Run as background daemon process (recommended)

# 切换到es用户,使用root用户启动会报错
su es

# 进入到es的bin目录
cd /data1/elasticsearch-7.9.2/bin

# 执行启动脚本,守护进程方式运行
 ./elasticsearch -d

Close ES service

kill -9 pid

insert image description here

6.3 Customize startup and shutdown scripts (recommended)

Create a startup script

# 创建es启动脚本文件
touch es-start.sh
# 编辑脚本
vim es-start.sh 
# 设置用户组
chown es:es es-start.sh 
# 设置执行权限
chmod 755 es-start.sh 

es-start.sh

cd /data1/elasticsearch-7.9.2
./bin/elasticsearch -d -p pid

Create a stop script

# 创建es停止脚本文件
touch es-stop.sh
# 编辑脚本
vim es-stop.sh 
# 设置用户组
chown es:es es-stop.sh 
# 设置执行权限
chmod 755 es-ststoprt.sh 

es-stop.sh

cd /data1/elasticsearch-7.9.2
if [ -f "pid" ]; then
pkill -F pid
fi

startup and shutdown
insert image description here

7. Open the firewall port

#查看防火墙状态
systemctl status firewalld 
#查看开放的端口
firewall-cmd --query-port=9200/tcp
#添加端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent 
#重载防火墙
firewall-cmd --reload 
#再次查看端口是否已经开放
firewall-cmd --query-port=9200/tcp

8. Install the chrome visual head plugin

Chrome plug-in to access the es database
Unzip it to a local directory first, then install the plug-in in chrome
insert image description here
Select the unzipped directory and install it
insert image description here
Enter the es connection address, click Connect, the health value is green, it means successful startup
insert image description here

Guess you like

Origin blog.csdn.net/qq_29864051/article/details/131145003