ElasticSearch与Kibana入门
Elasticsearch安装与运行
- 安装JDK1.8
- 下载安装Elasticsearch
- 运行
bin/elasticsearch
Elasticsearch安装与运行详细步骤
1.安装JDK1.8
(略)
2.下载Elasticsearch
下载地址: https://www.elastic.co/cn/
3.运行 bin/elasticsearch
解压安装包
[jlc@localhost es]$ tar -zxf elasticsearch-6.1.1.tar.gz # 进入解压后的目录 [jlc@localhost es]$ cd elasticsearch-6.1.1/
运行
bin/elasticsearch
命令[jlc@localhost elasticsearch-6.1.1]$ bin/elasticsearch
4.访问Elasticsearch
在浏览器中输入 127.0.0.1:9200
,页面将会输出以下信息,证明Elasticsearch运行成功.
{
"name" : "Eyro1LL",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "BH492TyERByKamIjYeaROQ",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
Elasticsearch配置说明
- 配置文件位于config目录中
- elasticsearch.yml # es的相关配置
- jvm.options # jvm的相关参数
- log4j2.properties # 日志相关配置
1.elasticsearch.yml
关键配置说明
- cluster.name # 集群名称,以此作为是否同一集群的判断条件
- node.name # 节点名称,以此作为集群中不同节点的区分条件
- network.host/http.port # 网络地址端口,用于http和transport服务使用
- path.data # 数据存储地址
- path.log # 日志存储地址
2.Development与Production模式说明
以transport的地址(
network.host
)是否绑定在localhost为判断标准Development模式在启动时会以
warning
的方式提示配置检查异常Production模式下会以
error
的方式提示配置检查异常并退出
3.参数修改的第二种方式
[jlc@localhost elasticsearch-6.1.1]$ bin/elasticsearch -Ehttp.port=19200
Elasticsearch本地启动集群方式
新建三个终端窗口,分别输入以下三个命令,便可创建一个节点数为3的Elasticsearch集群
[jlc@localhost elasticsearch-6.1.1]$ bin/elasticsearch
[jlc@localhost elasticsearch-6.1.1]$ bin/elasticsearch -Ehttp.port=8200 -Epath.data=node2
[jlc@localhost elasticsearch-6.1.1]$ bin/elasticsearch -Ehttp.port=7200 -Epath.data=node3
在浏览器中输入127.0.0.1:9200/_cat/nodes
便会输出Elasticsearch节点情况,如下所示
# 地址栏: 127.0.0.1:9200/_cat/nodes
127.0.0.1 14 97 7 0.62 0.38 0.21 mdi - 1P40_XH
127.0.0.1 12 97 3 0.62 0.38 0.21 mdi * Eyro1LL
127.0.0.1 14 97 12 0.62 0.38 0.21 mdi - _d5BzFg
# 地址栏: 127.0.0.1:9200/_cat/nodes?v
# 将会显示节点信息的标题栏
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 14 97 3 0.46 0.39 0.22 mdi - 1P40_XH
127.0.0.1 12 97 3 0.46 0.39 0.22 mdi * Eyro1LL
127.0.0.1 14 97 3 0.46 0.39 0.22 mdi - _d5BzFg
在浏览器中输入127.0.0.1:9200/_cluster/stats
将会输出Elasticsearch集群详细信息,如下所示
{
"_nodes": {
"total": 3,
"successful": 3,
"failed": 0
},
"cluster_name": "elasticsearch",
"timestamp": 1585667737502,
"status": "green",
"indices": {
"count": 0,
"shards": {},
"docs": {
"count": 0,
"deleted": 0
},
"store": {
"size_in_bytes": 0
},
"fielddata": {
"memory_size_in_bytes": 0,
"evictions": 0
},
"query_cache": {
"memory_size_in_bytes": 0,
"total_count": 0,
"hit_count": 0,
"miss_count": 0,
"cache_size": 0,
"cache_count": 0,
"evictions": 0
},
"completion": {
"size_in_bytes": 0
},
"segments": {
"count": 0,
"memory_in_bytes": 0,
"terms_memory_in_bytes": 0,
"stored_fields_memory_in_bytes": 0,
"term_vectors_memory_in_bytes": 0,
"norms_memory_in_bytes": 0,
"points_memory_in_bytes": 0,
"doc_values_memory_in_bytes": 0,
"index_writer_memory_in_bytes": 0,
"version_map_memory_in_bytes": 0,
"fixed_bit_set_memory_in_bytes": 0,
"max_unsafe_auto_id_timestamp": -9223372036854776000,
"file_sizes": {}
}
},
"nodes": {
"count": {
"total": 3,
"data": 3,
"coordinating_only": 0,
"master": 3,
"ingest": 3
},
"versions": [
"6.1.1"
],
"os": {
"available_processors": 6,
"allocated_processors": 6,
"names": [
{
"name": "Linux",
"count": 3
}
],
"mem": {
"total_in_bytes": 11862110208,
"free_in_bytes": 346312704,
"used_in_bytes": 11515797504,
"free_percent": 3,
"used_percent": 97
}
},
"process": {
"cpu": {
"percent": 0
},
"open_file_descriptors": {
"min": 191,
"max": 192,
"avg": 191
}
},
"jvm": {
"max_uptime_in_millis": 2551480,
"versions": [
{
"version": "1.8.0_222-ea",
"vm_name": "OpenJDK 64-Bit Server VM",
"vm_version": "25.222-b03",
"vm_vendor": "Oracle Corporation",
"count": 3
}
],
"mem": {
"heap_used_in_bytes": 499037568,
"heap_max_in_bytes": 3168927744
},
"threads": 79
},
"fs": {
"total_in_bytes": 27899465728,
"free_in_bytes": 17078177792,
"available_in_bytes": 17078177792
},
"plugins": [],
"network_types": {
"transport_types": {
"netty4": 3
},
"http_types": {
"netty4": 3
}
}
}
}
Kibana安装与演示
Kibana安装与运行
- 下载安装Kibana
- 运行
bin/kibana
Kibana安装与运行详细步骤
下载Kibana
运行Kibana
解压安装包
[jlc@localhost es]$ tar -zxf kibana-6.1.1-linux-x86_64.tar.gz # 进入kibana目录 [jlc@localhost es]$ cd kibana-6.1.1-linux-x86_64/
配置Kibana配置文件(
config/kibana.yml
),修改其对应的Elasticsearch运行地址# 本讲解修改为本地的一个Elasticsearch的node节点 elasticsearch.url: "http://localhost:9200"
运行Kibana
[jlc@localhost kibana-6.1.1-linux-x86_64]$ bin/kibana
访问Kibana
在浏览器中输入
localhost:5601
即可查看Kibana运行后的界面,如下图所示
Kibana配置说明
配置位于
config
文件夹中kibana.yml
关键配置说明- server.host/server.port # 访问kibana用的地址和端口
- elasticsearch.url # 待访问Elasticsearch的地址
Kibana常用功能说明
- Discover # 数据搜索查看
- Visualize # 图表制作
- Dashboard # 仪表盘制作
- Timelion # 实时数据的高级可视化分析
- DevTools # 开发者工具
- Management # Kibana配置
Elasticsearch常用术语
- Document # 文档数据(可看为)
- Index # 索引
- Type # 索引中的数据类型
- Field # 字段,文档的属性
- Query DSL # 查询的语法
Elasticsearch CRUD
- Create # 创建文档
- Read # 读取文档
- Update # 更新文档
- Delete # 删除文档
Elasticsearch Create
在Kibana的Dev Tools项下输入如下语句
# 将会创建 Index为: account, Type为: person, Document的id为: 1 的文档
# 其中, 插入语句下的Json语句为待插入文档的内容
POST /account/person/1
{
"name": "John",
"lastname": "Doe",
"job_description": "Systems adminostrator and linux specialit"
}
其中,在Elasticsearch完成插入后,返回的信息如下所示
{
"_index": "account",
"_type": "person",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
Elasticsearch Read
在Kibana的Dev Tools项下输入如下语句
# 将会获取 Index为: account, Type为: person, Document的id为: 1 的文档信息
GET /account/person/1
其中,在Elasticsearch完成请求后,返回的信息如下所示
{
"_index": "account",
"_type": "person",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "John",
"lastname": "Doe",
"job_description": "Systems adminostrator and linux specialit"
}
}
Elasticsearch Update
在Kibana的Dev Tools项下输入如下语句
# 将会修改 Index为: account, Type为: person下的 Document的id为: 1 的文档信息
# 其中修改的内容为"doc": {} 里的内容信息
POST /account/person/1/_update
{
"doc": {
"job_description": "Systems adminostrator and linux specialist"
}
}
其中,在Elasticsearch完成修改后,返回的信息如下所示
{
"_index": "account",
"_type": "person",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
Elasticsearch Delete
在Kibana的Dev Tools项下输入如下语句
# 将会删除 Index为: account, Type为: person下的 Document的id为: 1 的文档信息
DELETE /account/person/1
其中,在Elasticsearch完成删除后,返回的信息如下所示
{
"_index": "account",
"_type": "person",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1
}
Elasticsearch Query
Query String
例:
GET /account/person/_search?q=john
在Elasticsearch完成查询后,返回的信息如下所示
{ "took": 448, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "account", "_type": "person", "_id": "1", "_score": 0.2876821, "_source": { "name": "John", "lastname": "Doe", "job_description": "Systems adminostrator and linux specialit" } } ] } }
Query DSL
例:
GET /account/person/_search { "query": { "term": { "name": { "value": "john" } } } }
在Elasticsearch完成查询后,返回的信息如下所示
{ "took": 52, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "account", "_type": "person", "_id": "1", "_score": 0.2876821, "_source": { "name": "John", "lastname": "Doe", "job_description": "Systems adminostrator and linux specialit" } } ] } }