1 environment
The server environment is CentOS7.6, and the Elasticsearch version is 7.17.4
2 Install Es
2.1 download
Select the version to install: download address
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.4-linux-x86_64.tar.gz
Unzip to the specified directory
tar -zxvf elasticsearch-7.17.4-linux-x86_64.tar.gz -C /opt/module
rename to es
mv elasticsearch-7.17.4/ es
2.2 Create ES user
Elasticsearch is not allowed to start as root, so create a new user and grant permissions
useradd es
passwd es
chown -R es:es /opt/module/es
2.3 Modify the ES configuration file
Modify the core configuration file of ES
vim /opt/module/es/config/elasticsearch.yml
Add the following lines at the end of the file
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
Modify memory parameter configuration
vim /opt/module/es/config/jvm.options
My server is 2-core 4G, here is changed to 1g
Reminder : Please refer to the memory size of the server when modifying this parameter, otherwise the entire server will be stuck immediately after starting ES
2.4 Modify the system configuration file
Modify /etc/security/limits.conf
Add the following at the end
# 每个进程可以打开的文件数限制
es soft nofile 65536
es hard nofile 65536
Modify /etc/security/limits.d/20-nproc.conf
Add the following at the end
# 每个进程可以打开的文件数限制
es soft nofile 65536
es hard nofile 65536
# 操作系统级别对每个用户创建的进程数的限制
* hard nproc 4096
Modify /etc/sysctl.conf
Add the following at the end
# 一个进程可以拥有的虚拟内存区域的数量
vm.max_map_count=655360
Reload
sysctl -p
2.5 Start ES
Be sure to switch to the es user before starting Elasticsearch, execute the following command
# 切换用户
su es
# 切换到bin目录
cd /opt/module/es/bin
# 启动命令,加上-d为后台启动
./elasticsearch
Access through a browser after successful startuphttp://server IP address: 9200View, if the following content appears, the startup is successful
3 Configure the user name and password of Elasticsearch
3.1 Edit configuration file
vim /opt/module/es/config/elasticsearch.yml
Add the following at the end
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
3.2 Restart ES
Run in the foreground and terminate the program by Ctrl + C
When running in the background, check the process id and kill the process
# 查看进程
ps -ef|grep elastic
# 杀死进程
kill -9 id
Start command see above
3.3 Set username and password
/opt/module/es/bin/elasticsearch-setup-passwords interactive
Enter the password according to the prompt
3.4 Verify that the password is valid
Use the browser to access es again, and the following window pops up, which means success
The default username iselastic
The password is the password you just set
4 Precautions
Elasticsearch needs to be started once before setting the password, otherwise an error will be reported
ERROR: Elasticsearch keystore file is missing
Elasticsearch must be in the startup state when setting the password, otherwise an error will be reported
ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty
If you need to use Elasticsearch in the SpringBoot project and import the following dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
Please make sure that the Elasticsearch version used in the project is consistent with the installed ES version, you can view the current version in the external library
If the version is different from the installed ES version, you can specify the ES version in the pom file. In short, ensure that the ES version used by the project is consistent with the installed one