1.选择安装目录下载安装包并解压
//选择安装目录
cd /usr/local
//下载安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.3-linux-x86_64.tar.gz
//解压
tar -zxvf elasticsearch-8.4.3-linux-x86_64.tar.gz
2.创建新用户并授权
#创建分组
groupadd esgroup
#创建用户密码
useradd esuser -p 123456
#给用户分配权限
chown -R esuser:esgroup /usr/local/elasticsearch-8.4.3
3. 修改配置
在/usr/local/elasticsearch-8.4.3/config下的
elasticsearch.yml结尾添加
ingest.geoip.downloader.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"
将权限中的true改为false
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
修改本地防火墙和云防火墙
#将9200加入白名单
firewall-cmd --zone=public --add-port=9200/tcp --permanent
#刷新防火墙
systemctl restart firewalld.service
4.切换用户启动
#却换用户
su esuser
#进入elasticsearch bin目录下面
cd /usr/local/elasticsearch-8.4.3/bin
#启动
./elasticsearch
5.将es服务配置成开机自启动
#切换root用户
su root
#进入到目录
cd /etc/init.d
#创建elasticsearch系统启动服务文件
vim elasticsearch
编写启动脚本
#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-8.4.3
# 这个目录是你Es所在文件夹的目录
export ES_HOME=/usr/local/elasticsearch-8.4.3
case $1 in
start)
su esuser<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su esuser<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
给elasticsearch 文件赋权限
chmod 777 elasticsearch
添加到系统服务
# 添加系统服务
chkconfig --add elasticsearch
# 删除系统服务
chkconfig --del elasticsearch
服务启动、重启、关闭
# 启动服务
service elasticsearch start
# 停止服务
service elasticsearch stop
# 重启服务
service elasticsearch restart
开机启动服务
# 开启开机自动启动服务
chkconfig elasticsearch on
# 关闭开机自动启动服务
chkconfig elasticsearch off