全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 es)是目前全文搜索引擎的首选。
它可以快速地储存、搜索和分析海量数据。维基百科、Stack Overflow、Github 都采用它。
Elasticsearch简称es,在企业内同样是一款应用非常广泛的搜索引擎服务。
添加yum仓库
# root执行
# 导入仓库密钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 添加yum源
# 编辑文件
vim /etc/yum.repos.d/elasticsearch.repo
# 推荐使用
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-7.x/
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
# 更新yum缓存
yum makecache
安装es
yum install -y elasticsearch
配置es
vim /etc/elasticsearch/elasticsearch.yml
#阅读模式 显示行号
:set nu
# 17行,设置集群名称
cluster.name: my-cluster
# 23行,设置节点名称
node.name: node-1
# 56行,允许外网访问
network.host: 0.0.0.0
# 74行,配置集群master节点
cluster.initial_master_nodes: ["node-1"]
启动es
systemctl start | stop | status | enable | disable elasticsearch
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
测试
http://ip:9200/?pretty
sudo userdel elasticsearch
sudo groupdel elasticsearch
{
"name": "node-1",
"cluster_name": "my-cluster",
"cluster_uuid": "yLfUpG4CQ-Wbq6zL-2XqzA",
"version": {
"number": "7.17.14",
"build_flavor": "default",
"build_type": "rpm",
"build_hash": "774e3bfa4d52e2834e4d9d8d669d77e4e5c1017f",
"build_date": "2023-10-05T22:17:33.780167078Z",
"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"
}
停止Elasticsearch服务
sudo systemctl stop elasticsearch
卸载Elasticsearch软件包
sudo yum remove elasticsearch
删除Elasticsearch数据目录
/var/lib/elasticsearch
sudo rm -rf /var/lib/elasticsearch
删除Elasticsearch配置文件
/etc/elasticsearch
sudo rm -rf /etc/elasticsearch
删除Elasticsearch日志文件
/var/log/elasticsearch
sudo rm -rf /var/log/elasticsearch