ElassticSearch 快速搭建

1 拉取并解压下载所需版本的 ES (本示例为 7.17.16)

elastic网站 下载对应压缩包,或直接wget

移动到服务器目录,例如 /home/elasticsearch/

解压

1
tar -zxvf elasticsearch-7.17.16-linux-x86_64.tar.gz

2 配置文件处理

2.1 修改配置文件 elasticsearch.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cd elasticsearch-7.17.16-linux-x86_64.tar.gz

vim config/elasticsearch.yml

###### elasticsearch.yml ######

# 设置为单机模式
discovery.type: single-node

# 网段为所有可访问
network.host: 0.0.0.0
http.port: 9200
# 透过cors跨域请求
http.cors.enabled: true
http.cors.allow-origin: "*"

# 头部加上 AUTH
http.cors.allow-headers: Authorization

# 安全模块开启,防止启动报错
xpack.security.enabled: true

###############################

2.2 修改启动包中的jdk位置为ES自带的jdk

1
2
3
4
5
6
7
8
vim bin/elasticsearch

###### elasticsearch ######

export JAVA_HOME=/home/elasticsearch/elasticsearch-7.17.16/jdk
export PATH=$JAVA_HOME/bin:$PATH

###########################

2.3 修改es的jvm堆内存大小

1
2
3
4
5
6
7
8
vim config/jvm.options

###### jvm.options ######

-Xms1g
-Xms1g

##########################

3 创建es专用用户

1
2
3
4
5
6
7
8
# 因为es运行不可为root用户,则创建 user-es 供es使用
sudo useradd user-es

# 设置密码
sudo passwd user-es

# 将 user-es 加入管理员组
sudo usermod -aG root user-es

4 启动

1
2
3
4
5
6
7
# 切换到 user-es 
su user-es

# 启动项目
bin/elasticsearch
# 后台启动
bin/elasticsearch -d

5 设置es用户组密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 首先测试项目是否启动成功
crul http://127.0.0.1:9200/

# 在es启动中,执行
bin/elasticsearch-setup-passwords interactive

# 出现
Initiating the setup of passwords for reserved users
elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
# 进行设置密码

# 测试密码是否设置成功

curl -u elastic:password http://127.0.0.1:9200/