Elasticsearch(一)| Centos 安装 Elasticsearch 8.4
Elaticsearch是一个开源的高扩展的分布式全文检索引擎,它可以近乎实时的存储、检索数据,官网地址:https://www.elastic.co/cn/
安装
Elasticsearch8.4自带了openjdk,所以不需要再安装java环境
首先安装GPG-KEY
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
第一种方式,使用root用户,进入目录/etc/yum.repos.d/
,新建文件elasticsearch.repo
,内容如下 :
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=0
type=rpm-md
最后用yum命令安装即可:
yum install --enablerepo=elasticsearch elasticsearch
系统会自动完成安装最新release版本
第二种方式,使用root用户wget手动下载需要的版本进行安装
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.1-x86_64.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.1-x86_64.rpm.sha512
shasum -a 512 -c elasticsearch-8.4.1-x86_64.rpm.sha512
rpm --install elasticsearch-8.4.1-x86_64.rpm
如果找不到命令shasum command not found,请先执行下面命令安装shasum
yum install perl-Digest-SHA -y
配置
安装完成之后,可以找到系统自动生成的密码
The generated password for the elastic built-in superuser is : OKzrWoarTW8mnpfTcf_z
也可以使用/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
重新自动生成密码
使用systemctl执行命令
systemctl enable elasticsearch.service
这里需要修改/usr/lib/systemd/system/elasticsearch.service
中的TimeoutStartSec和ExecStart
ExecStart默认是前台启动,这里需要改成后台启动,不然用systemctl启动之后,到了TimeoutStartSec的时间,Elasticsearch服务就会超时关闭
ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -d -p ${PID_DIR}/elasticsearch.pid
TimeoutStartSec默认在是75秒,可以改成150秒,因为第一次加载的时间比较长,否则如果用systemctl start elasticsearch.service
命令启动 ,会报错Start operation timed out. Terminating
TimeoutStartSec=150
修改/etc/elasticsearch/elasticsearch.yml
,注释掉cluster.initial_master_nodes
,并把集群设置为单结点
cluster.name: test-cluster
node.name: test-node-1
discovery.type: single-node
#cluster.initial_master_nodes: ["9a1ae7a91a36"]
运行
一切就绪就好,就可以启动Elasticsearch
systemctl daemon-reload
systemctl start elasticsearch.service
启动完成之后,systemctl有可能提示失败,这不影响Elasticsearch,可以使用命令查看Elasticsearch是否启动成功
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
输入上面自动生成的密码,看到如下的输出就表示启动成功了:
{
"name" : "test-node-1",
"cluster_name" : "test-cluster",
"cluster_uuid" : "2_iEDUKHSR-EqsYkAKlZog",
"version" : {
"number" : "8.4.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "2bd229c8e56650b42e40992322a76e7914258f0c",
"build_date" : "2022-08-26T12:11:43.232597118Z",
"build_snapshot" : false,
"lucene_version" : "9.3.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
如果启动失败,可以查看/var/log/elasticsearch/test-cluster.log
日志文件来追踪问题。