Elasticsearch7.17.5单节点安装

1.下载

https://www.elastic.co/cn/downloads
#下载地址
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.5-x86_64.rpm
#下载rpm包版本

2.安装

[root@elk101 data]# rpm -ivh elasticsearch-7.17.5-x86_64.rpm
warning: elasticsearch-7.17.5-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing...                          ################################# [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Updating / installing...
   1:elasticsearch-0:7.17.5-1         ################################# [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore

3.启动

修改配置文件

[root@elk101 data]# vim /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
#指定了Elasticsearch绑定的IP地址  0.0.0.0可以从任何IP地址接收连接请求

path.data: /data/elasticsearch/lib/elasticsearch
#存储其索引数据的目录
path.logs: /var/elasticsearch/log/elasticsearch
#日志文件的存储位置

discovery.seed_hosts: ["172.17.10.101"]
#指定es集群的节点ip

cluster.initial_master_nodes: ["172.17.10.101"]
#指定参与master选举的节点ip

创建存放数据目录和日志目录

[root@elk101 data]# mkdir -p /data/elasticsearch/lib/elasticsearch
[root@elk101 data]# mkdir -p /var/elasticsearch/log/elasticsearch
[root@elk101 data]# chown -R elasticsearch:elasticsearch /data/elasticsearch

设置开机自启并启动

[root@elk101 data]#  sudo systemctl daemon-reload
[root@elk101 data]#  sudo systemctl enable elasticsearch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@elk101 data]# systemctl start elasticsearch.service
[root@elk101 data]# ss -tnl
State      Recv-Q Send-Q            Local Address:Port              Peer Address:Port
LISTEN     0      128                 [::]:9200                      [::]:*
LISTEN     0      128                 [::]:9300                      [::]:*
#9200端口号是ES集群外部提供客户端http/https访问的端口。
#9300端口号是ES集群内部进行通信和数据传输的端口用的tcp协议。

4.客户端验证

[root@elk-102 ~]# curl 172.17.10.101:9200
{
  "name" : "elk101.guoguod.cn", #这个节点的主机名
  "cluster_name" : "elasticsearch", #集群的名字
  "cluster_uuid" : "E3mX67o-SwCTGsiEywrNuw", #uuid   如果 uuid 为_na_ 说明出现故障了
  "version" : {
    "number" : "7.17.5",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
    "build_date" : "2022-06-23T21:57:28.736740635Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

5.故障解决

[root@elk-102 ~]# curl 172.17.10.101:9200
{
  "name" : "elk101.guoguod.cn",  #这个节点的主机名
  "cluster_name" : "elasticsearch", #集群的名字
  "cluster_uuid" : "_na_",   #uuid 为_na_ 说明出现故障了
  "version" : {
    "number" : "7.17.5", #版本
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
    "build_date" : "2022-06-23T21:57:28.736740635Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root
如果遇到集群的uuid为"_na_"情况时,可以执行如下操作:  #有数据禁止这样操作
	systemctl stop elasticsearch.service
	rm -rf /data/elasticsearch/lib/elasticsearch/* /data/elasticsearch/log/elasticsearch/* /tmp/*
	
	#rm -rf /var/lib/elasticsearch/* /var/log/elasticsearch/* /tmp/*
	#如果没改配置文件日志和数据目录
	systemctl start elasticsearch.service
	curl 172.17.10.101:9200