前言

1、操作系统 :Kylin Linux Advanced Server release V10 (Tercel)

2、官网下载:https://www.elastic.co/cn/downloads/elasticsearch


注意事项

1、下载的是aarch64版本的,并不是x86的。将elasticsearch-8.1.0-linux-aarch64.tar.gz上传到服务器,并进行解压。

2、只允许普通用户操作,不允许root用户 (ES有远程执行脚本的功能容易中木马病毒,所以不允许用root用户启动,root用户是起不来的,赋权限,用一般的用户启动,如下创建es用户使用)

3、配置yml结尾的配置文件都需要冒号后面加空格才行

4、要配置network.host才能别的机器或者网卡访问,否则只能是127.0.0.1或者localhost访问,这里配置成自己的局域网IP


安装Elasticsearch 
#进入/usr/local目录
cd /usr/local
#创建elasticsearch目录
mkdir elasticsearch
#把elasticsearch压缩文件放进来,然后解压
tar -zxvf elasticsearch-8.1.0-linux-aarch64.tar.gz

#创建用户(基于安全可控的原则,Elasticsearch 不允许 root 用户直接运行;)
#新增 es 用户
useradd es
#为 es 用户设置密码
passwd es
#如果错了,可以删除再加
userdel -r es
#切换用户命令
su es
修改属性,设置授权范围
[root@localhost elasticsearch]# pwd
/usr/local/elasticsearch
#修改属性(root用户使用)
chown -R es:es elasticsearch-8.1.0
修改配置文件
#修改elasticsearch-8.1.0/config/elasticsearch.yml 文件加入如下配置
vim elasticsearch.yml

cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

#集群名称
cluster.name: my-application
#节点名称
node.name: node-1
#当前节点所绑定的本机IP
network.host: 0.0.0.0
#初始化集群主节点
cluster.initial_master_nodes: ["node-1"]
修改OS层系统参数
#修改/etc/security/limits.conf 在文件末尾中增加下面内容(每个进程可以打开的文件数的限制)
es soft nofile 65536
es hard nofile 65536

#修改/etc/sysctl.conf 在文件中增加下面内容(一个进程可以拥有的 VMA(虚拟内存区域)的数量,默认值为 65536)
vm.max_map_count=655360

#重新加载配置
sysctl -p
 
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
vm.max_map_count = 655360
启停软件
#使用 ES 用户启动
su - es
cd /usr/local/elasticsearch/elasticsearch-8.1.0/bin

1、正常启动(该启动可查看报错信息)
./elasticsearch
2、后台启动
./elasticsearch -d
3、停止
ps -ef|grep elasticsearch
kill -9 pid
设置开机自启动(不需要,可以不设置)

1、建立服务文件

vi /lib/systemd/system/elasticsearch.service

[Unit]
Description=elasticsearch
[Service]
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/usr/local/elasticsearch-8.1.0/bin/elasticsearch
User=elasticsearch
Group=elasticsearch
[Install]
WantedBy=multi-user.target

2、设置开机自启动

重新加载systemd的守护线程:systemctl daemon-reload

systemctl enable elasticsearch

启动elasticsearch.service:
systemctl start elasticsearch.service

查看elasticsearch.serivce状态:
systemctl status elasticsearch.service
ps aux|grep 

java如果出现错误可以使用如下命令查看日志:
journalctl -u elaticsearch.service
测试访问

1、 curl 127.0.0.1:9200 或者直接浏览器访问:127.0.0.1:9200 出现如下信息则启动成功

[root@localhost ~]# curl 127.0.0.1:9200
{
  "name" : "node-1",
  "cluster_name" : "gdie",
  "cluster_uuid" : "b07PROSJRly-hqquB1JOKg",
  "version" : {
    "number" : "7.17.21",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "d38e4b028f4a9784bb74de339ac1b877e2dbea6f",
    "build_date" : "2024-04-26T04:36:26.745220156Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.3",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
常见问题处理

问题一、运行es 报错:could not find java in bundled jdk at optelasticsearchelasticsearch-8.1.0jdkbin

              解决:这是因为在root账户下不能启动es,需创建es用户,授权范围,然后再用es用户启动

# 将此目录下授权给 es用户
sudo chown -R es:es /opt/elasticsearch/elasticsearch-8.1.0

问题二、离线启动错误:java.net.UnknownHostException: geoip.elastic.co 

              解决:在elasticsearch.yml中添加如下配置,关闭geoip数据库的更新(默认需要联网)

ingest.geoip.downloader.enabled: false

问题三、如果不需要ssl验证

              解决:在elasticsearch.yml中添加如下配置

xpack.security.http.ssl:
  enabled: false