1、下载tar包

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

2、解压安装

tar xf elasticsearch-7.15.0-linux-x86_64.tar.gz

mv elasticsearch-7.15.0 /usr/local/elasticsearch

3、添加管理员账号(不能使用root启动)

useradd elasticsearch

passwd elasticsearch

4、修改配置文件(共三处)

cd /usr/local/elasticsearch


4.1修改启动文件

vim bin/elasticsearch

在第一个未注释行上方添加


#使用自带jdk

export ES_JAVA_HOME=/usr/local/elasticsearch/jdk

export PATH=$ES_JAVA_HOME/bin:$PATH


4.2修改配置文件

cat config/elasticsearch.yml | grep -v "#" | grep -v ^$

node.name: node-1

path.data: /usr/local/data

path.logs: /usr/local/elasticsearch/logs

network.host: 0.0.0.0

http.port: 9200

discovery.seed_hosts: ["127.0.0.1"]

cluster.initial_master_nodes: ["node-1"]

#在文件末尾添加,允许head插件链接

http.cors.enabled: true

http.cors.allow-origin: "*"


#创建path.data 目录

mkdir /usr/local/data


#添加hosts域名解析

cat /etc/hosts | grep node-1

127.0.0.1   node-1



4.3修改jdk配置文件,限制使用内存大小,最大不要超过物理内存的50%

cat config/jvm.options | grep Xm

-Xms2g

-Xmx2g


5、修改目录权限

cd /usr/local

chown -R elasticsearch. elasticsearch

chown -R elasticsearch. data


6、添加启动配置文件

cat /etc/systemd/system/elasticsearch.service

[Unit]

Description=es Service

After=syslog.target

After=network.target


[Service]

User=elasticsearch

Group=elasticsearch


Type=simple


LimitNOFILE=65536

LimitNPROC=65536


ExecStart=/usr/local/elasticsearch/bin/elasticsearch


[Install]

WantedBy=default.target


7、启动并添加开机启动

systemctl start elasticsearch.service

systemctl enable elasticsearch.service


8、测试访问

curl 127.0.0.1:9200

{

 "name" : "node-1",

 "cluster_name" : "elasticsearch",

 "cluster_uuid" : "HxjTeUb3SquC2-d52kgYpQ",

 "version" : {

   "number" : "7.15.0",

   "build_flavor" : "default",

   "build_type" : "tar",

   "build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",

   "build_date" : "2021-09-16T03:05:29.143308416Z",

   "build_snapshot" : false,

   "lucene_version" : "8.9.0",

   "minimum_wire_compatibility_version" : "6.8.0",

   "minimum_index_compatibility_version" : "6.0.0-beta1"

 },

 "tagline" : "You Know, for Search"

}