Elasticsearch 学习
一、Elasticsearch 介绍
1.什么是ES?
Elasticsearch:分布式全文检索,基于lucene开发而来
ElasticSearch是一个高度可扩展的开源全文搜索和分析引擎,它可实现数据的实时全文搜索搜索、支持分布式可实现高可用、提供API接口,可以处理大规模日志数据,比如Nginx、Tomcat、系统日志等功能。
1.ES的库不可修改,表修改属性困难,容易出错
2.ES没有用户验证和权限控制
2.ES原理
将一个完整的信息源的全部内容转化为计算机可以识别、处理的信息单元而形成的数据集合
1.分词
2.语言处理
3.排序
1.分词
2.找到关键词
3.搜索索引
4.计算命中率(相关性)
5.进行排序,根据算法给出结果
https://www.cnblogs.com/ajianbeyourself/p/11280247.html
3.ES功能
1.分布式搜索引擎
2.全文检索,结构化检索,数据分析
全文检索:相当于 select * from table;
结构化检索:相当于 select * from table where id > 100 and id < 1000;
数据分析:相当于 select count(*) from biao where id > 100 and id < 1000;
4.使用场景
1.大量数据存储
2.搜索数据
3.分析数据(ELK)
4.搜索引擎高亮显示
5.ES特点
1.可以部署集群或者单点,服务于不同数据量的公司
2.高性能,分布式
3.不需要会JAVA语言
4.功能丰富,可以安装插件解决问题
5.部署简单
6.ES与mysql的区别
| mysql |
ES |
| 库(database) |
索引(index) |
| 表(table) |
类型(type) |
| 列(字段) |
项(filter) |
| 行数据 |
文档(doc) |
二、安装ES
1.服务器时间同步
[root@redis01 ~]
[root@redis01 ~]
2.安装java环境
1.上传rpm包
[root@redis01 ~]
2.安装rpm包
[root@redis01 ~]
3.查看版本
[root@redis01 ~]
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
3.安装ES
1.上传或下载包
[root@redis01 ~]
2.安装es
[root@redis01 ~]
3.根据提示配置system管理
安装时不启动,请执行以下语句来配置elasticsearch服务,使其使用systemd自动启动
sudo systemctl daemon-reload
sudo systemctl启用elasticsearch.service
您可以通过执行来启动elasticsearch服务
sudo systemctl启动elasticsearch.service
在/etc/elasticsearch中创建了elasticsearch密钥库
4.验证启动
[root@redis01 ~]
[root@redis01 ~]
{
"name" : "g2wt0qF",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "bYHD6vqBSoOdCvMhj_wlKA",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
4.ES相关配置文件
[root@redis01 ~]
/etc/elasticsearch/elasticsearch.yml
/etc/elasticsearch/jvm.options
/etc/elasticsearch/log4j2.properties
/etc/init.d/elasticsearch
/etc/sysconfig/elasticsearch
/usr/lib/sysctl.d/elasticsearch.conf
/usr/lib/systemd/system/elasticsearch.service
5.配置ES
[root@redis01 ~]
node.name: es01
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 10.0.0.91,127.0.0.1
http.port: 9200
[root@redis01 ~]
node.name: es01
path.data: /server/es/data
path.logs: /server/es/logs
bootstrap.memory_lock: true
network.host: 10.0.0.91,127.0.0.1
http.port: 9200
[root@elkstack01 ~]
http.cors.enabled: true
http.cors.allow-origin: "*"
6.跟配置文件创建目录
[root@redis01 ~]
[root@redis01 ~]
7.重新启动ES
[root@redis01 ~]
[root@redis01 ~]
[2020-05-15T10:40:47,787][ERROR][o.e.b.Bootstrap ] [es01] node validation exception
[1] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
[root@redis01 ~]
[Service]
LimitMEMLOCK=infinity
[root@redis01 ~]
[root@redis01 ~]
echo "* soft nofile 65536\n* hard nofile 65536">>/etc/security/limits.conf
"* soft memlock unlimited\n* hard memlock unlimited"
"vm.max_map_count=262144">>/etc/sysctl.conf
8.访问页面
{
"name" : "es01",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "vNBGo-DMTdO4yStFGXJ6-g",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
三、跟ES交互的方式
1.curl命令的方式
1)特点
1.使用不方便,命令复杂,容易出错
2.不需要安装任何服务,只需要curl命令
2)使用方式
[root@redis01 ~]
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "student"
}
[root@redis01 ~]
{
"_index" : "student",
"_type" : "user",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
[root@redis01 ~]
{
"_index" : "student",
"_type" : "user",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "lhd",
"sex" : "man",
"age" : "18",
"about" : "good good study",
"interests" : [
"chinese",
"english"
]
}
}
2.使用es-head插件的方式
插件是为了完成不同的功能,官方提供了一些插件但大部分是收费的,另外也有一些开发爱好者提供的插件,可以实现对elasticsearch集群的状态监控与管理配置等功能,我们现在要安装的是Elasticsearch的head插件,此插件提供elasticsearch的web界面功能。
1)特点
1.查看数方便,操作简单
2.需要安装nodejs环境,安装时间长
2)安装方法一
[root@elkstack01 ~]
[root@redis01 ~]
[root@redis01 ~]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
[root@redis01 elasticsearch-head]
tcp 0 0 0.0.0.0:9100 0.0.0.0:* LISTEN 11293/grunt
[root@redis01 elasticsearch-head]
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@elkstack01 elasticsearch-head]
3)安装插件方法二
1.在电脑上解压es-head-0.1.4_0.crx.zip
2.谷歌浏览器,右上角三个杠或三个点
3.点击扩展程序
4.打开开发者模式
5.加载已解压的扩展程序,选择解压的目录
6.右上角会多出一个放大镜,点击及进入es-head页面
7.修改连接地址为ES地址
3.kibana方式
1)安装kibana
[root@redis01 ~]
[root@redis01 ~]
2)配置kibana
[root@redis01 ~]
server.port: 5601
server.host: "10.0.0.91"
elasticsearch.hosts: ["http://localhost:9200"]
kibana.index: ".kibana"
3)启动kibana
[root@redis01 ~]
[root@redis01 ~]
tcp 0 0 10.0.0.91:5601 0.0.0.0:* LISTEN 30640/node
[root@redis01 ~]
kibana 30640 1 89 12:16 ? 00:00:25 /usr/share/kibana/bin/../node/bin/node --no-warnings /usr/share/kibana/bin/../src/cli -c /etc/kibana/kibana.yml
4)访问页面
