一、简介
Elasticsearch是一个用Java语言编写的开源的搜索引擎,它是建立在全文搜索引擎库 Apache Lucene™ 的基础之上。
Elasticsearch内部使用Lucene做索引与搜索,相比复杂的Lucene,Elasticsearch的全文检索变得非常简单, 因为它提供了一套简单一致的RESTful API。
Elasticsearch作为一个全文搜索引擎。它支持分布式的实时文档存储,每个字段可以被索引与搜索,同时能胜任上百个服务节点的扩展,并支持 PB 级别的结构化或者非结构化数据。
Elasticsearch把所有的功能都打包成一个单独的服务,方便使用者通过程序与其提供的RESTful API进行通信,使用者可以用任何编程语言实现这个web客户端,甚至直接使用命令行调用API。
Elasticsearch的起步很简单。它预设了一些适当的默认值,并隐藏了复杂的搜索理论知识。真正做到了开箱即用。
当然,这不意味着Elasticsearch的功能就很简单,相反随着对它的了解越深入,就越能惊叹于Elasticsearch的更多高级特性。
很多我们遇到的没遇到的业务场景或难题,都可以从Elasticsearch众多的高级特性中,找到合适的解决方案。它的整个引擎是可配置并且灵活的。
Elasticsearch在Github上的地址:http://github.com/elastic/elasticsearch 。
二、安装
系统:Linux CentOS7
2.1 确认是否安装Java,Elasticsearch最低支持java1.7
以下命令可以查看jdk版本
[root@SWW_centos ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
1
2
3
4
[root@SWW_centos~]# java -version
openjdkversion"1.8.0_181"
OpenJDKRuntimeEnvironment(build1.8.0_181-b13)
OpenJDK64-BitServerVM(build25.181-b13,mixedmode)
2.2 使用yum安装Elasticsearch
2.2.1 下载并安装ES的yum公钥
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
1
rpm--importhttps://packages.elastic.co/GPG-KEY-elasticsearch
2.2.2 配置Elasticsearch的yum源
vim /etc/yum.repos.d/elasticsearch.repo
1
vim/etc/yum.repos.d/elasticsearch.repo
输入下面的代码
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=http://packages.elastic.co/elasticsearch/7.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
1
2
3
4
5
6
[elasticsearch-7.x]
name=Elasticsearchrepositoryfor7.xpackages
baseurl=http://packages.elastic.co/elasticsearch/7.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
2.2.3 更新yum的缓存
yum makecache
1
yummakecache
2.2.4 安装Elasticsearch
yum install elasticsearch
1
yuminstallelasticsearch
2.2 测试Elasticsearch是否安装成功
配置服务
/sbin/chkconfig --add elasticsearch
systemctl start elasticsearch
1
2
/sbin/chkconfig--addelasticsearch
systemctlstartelasticsearch
测试访问
[root@SWW_centos ~]# curl -X GET localhost:9200
{
"name" : "ES01",
"cluster_name" : "my-els",
"cluster_uuid" : "2i3aSaT4TAKTRO34a4twnN",
"version" : {
"number" : "7.6.1",
"build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
"build_timestamp" : "2020-01-18T12:17:44Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@SWW_centos~]# curl -X GET localhost:9200
{
"name":"ES01",
"cluster_name":"my-els",
"cluster_uuid":"2i3aSaT4TAKTRO34a4twnN",
"version":{
"number":"7.6.1",
"build_hash":"5376dca9f70f3abef96a77f4bb22720ace8240fd",
"build_timestamp":"2020-01-18T12:17:44Z",
"build_snapshot":false,
"lucene_version":"8.4.0",
"minimum_wire_compatibility_version":"6.8.0",
"minimum_index_compatibility_version":"6.0.0-beta1"
},
"tagline":"You Know, for Search"
}
看到如上响应说明已经启动并运行一个Elasticsearch节点了。 单个节点可以作为一个运行中的Elasticsearch的实例。 而一个集群是一组拥有相同 cluster.name 的节点, 他们能一起工作并共享数据,还提供容错与可伸缩性。
2.3 设置ip访问、外网访问、修改端口
vim /etc/elasticsearch/elasticsearch.yml
1
vim/etc/elasticsearch/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
1
2
3
4
5
6
7
8
9
10
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host:0.0.0.0
#
# Set a custom port for HTTP:
#
http.port:9200
#
修改完了重启
systemctl restart elasticsearch
浏览器中输入ip地址和端口访问试试,如果访问被拒绝,添加防火墙设置
iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
1
iptables-IINPUT-ptcp--dport9200-jACCEPT
浏览量:
255
0