目录
1 Kibana是什么
Kibana是一个配合Elasticsearch使用的、开源的数据分析和可视化平台, 可以与Elasticsearch中存储的索引文档进行交互.
—— 使用Kibana能执行高级的数据分析, 并通过图表、表格、地图等形式显示分析结果.
2 安装并启动Kibana
在安装好单机版Elasticsearch的基础上, 安装Kibana插件, 使用其UI界面进行后续的学习操作.
前提: JDK和Elasticsearch单机服务已成功配置部署.
2.1 准备安装包
(1) 下载安装包:
下载地址: https://www.elastic.co/downloads/past-releases.
本文演示使用的是
kibana-6.6.0-linux-x86_64.tar.gz
.
(2) 解压并重命名:
# 上传安装包至服务器的/data/elk-6.6.0下:
cd /data/elk-6.6.0
# 解压安装包:
tar -zxf kibana-6.6.0-linux-x86_64.tar.gz
# 重命名
mv kibana-6.6.0-linux-x86_64.tar.gz kibana
2.2 修改配置文件
文件位置: $kibana/config/kebana.yml
:
# Kibana is served by a back end server. This setting specifies the port to use.
# Kibana是个后台服务, 需要指定服务的IP地址和端口号. 默认值为5601.
server.port: 5601
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
# 指定Kibana服务需要绑定的IP地址, 默认值为本地回环地址"localhost". 若要允许远程访问, 就需要改为本地服务器的IP地址. (127.0.0.1的作用等同于localhost, 可用ifconfig命令查看本机的IPV4地址)
server.host: 172.16.22.133
# Enables you to specify a path to mount Kibana at if you are running behind a proxy. This only affects
# the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests
# to Kibana. This setting cannot end in a slash.
#server.basePath: ""
# The maximum payload size in bytes for incoming server requests.
#server.maxPayloadBytes: 1048576
# The Kibana server's name. This is used for display purposes.
#server.name: "your-hostname"
# The URL of the Elasticsearch instance to use for all your queries.
# 需要监控的Elasticsearch服务的地址, 默认是本地回环地址+9200端口
#elasticsearch.url: "http://localhost:9200"
# When this setting's value is true Kibana uses the hostname specified in the server.host
# setting. When the value of this setting is false, Kibana uses the hostname of the host
# that connects to this Kibana instance.
#elasticsearch.preserveHost: true
# Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# dashboards. Kibana creates a new index if the index doesn't already exist.
# Kibana在Elasticsearch中的索引
kibana.index: ".kibana"
2.3 启动Kibana并验证
(1) 启动Kibana:
cd /data/elk-6.6.0/kibana/bin
# 前台启动, 不能关闭终端, 即阻塞式启动, 不能执行其他操作. 此时可通过Ctrl + C终止服务.
./kibana
# 后台启动, 可退出终端, 若当前终端窗口关闭, 服务也将终止.
nohup ./kibana &
# 上述nohup命令将输出追加到了nohup.out中, 为了直接查看启动情况, 可省去nohup命令:
# ./kibana &
(2) 浏览器检查
在浏览器访问: http://172.16.22.133:5601, 出现如下界面, 说明启动成功:
2.4 关闭Kibana服务
# 查看node服务的进程id
[root@localhost bin]# ps aux | grep node
root 15653 3.7 1.0 1142400 88020 pts/0 Sl 04:21 0:07 ./../node/bin/node --no-warnings ./../src/cli
# kill掉 ./../src/cli 进程:
[root@localhost bin]# kill -9 15653
或者: 如果没有在后台启动Kibana, 即没有使用nohup命令启动, 则关闭当前会话(即终端窗口), Kibana服务也将终止.
3 Kibana功能测试
前往Dev Tools工具界面, 输入如下命令并点击 [绿色的向右的箭头➡] 发送请求:
GET _cluster/health
得到如下关于集群健康状况的JSON响应:
{
"cluster_name" : "heal_es", # 集群名称, 默认是elasticsearch
"status" : "yellow", # 集群健康状态
"timed_out" : false,
"number_of_nodes" : 1, # 集群中的节点数
"number_of_data_nodes" : 1, # 存储数据的节点数
"active_primary_shards" : 33, # 活跃的primary shard数
"active_shards" : 33, # 活跃的shard数, 包括primary shard和replica shard
"relocating_shards" : 0, # 当前正在从一个节点迁往其他节点的分片的数量, 通常是0. 当ES发现集群不太均衡(如添加或下线一个节点)时, 该值会上涨
"initializing_shards" : 0, # 刚创建的分片个数, 创建第一个索引时、节点重启时, 会短暂处于此状态(不应长期停留此状态)
"unassigned_shards" : 5, # 在集群中存在, 却又不能找到 -- 即未分配的副本
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 86.8421052631579
}
3.1 关于集群的状态status
①
green
: 所有primary shard和replica shard都已成功分配, 集群是100%可用的;②
yellow
: 所有primary shard都已成功分配, 但至少有一个replica shard缺失. 此时集群所有功能都正常使用, 数据不会丢失, 搜索结果依然完整, 但集群的可用性减弱. —— 需要及时处理的警告.③
red
: 至少有一个primary shard(以及它的全部副本分片)缺失 —— 部分数据不能使用, 搜索只能返回部分数据, 而分配到这个分配上的写入请求会返回一个异常. 此时虽然可以运行部分功能, 但为了索引数据的完整性, 需要尽快修复集群.
3.2 关于集群中的节点数
使用
GET _cat/nodes?v
查看当前节点数:ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.16.22.133 62 98 2 0.98 1.25 1.39 mdi * 1UlY804
3.3 关于未分配的分片
unassigned_shards
: 已经在集群状态中存在、但在集群里又找不到的分片, 来源通常是未分配的副本. 比如: 一个有 5 分片和 1 副本的索引, 在单节点集群上就会有 5 个未分配副本分片.
如果集群状态是red
, 也会长期存在未分配分片(因为缺少主分片).
关于Kibana的使用方法, 请参考博主的这篇文章 ES 06 - 通过Kibana插件操作ES中的索引文档 (CRUD操作).
参考资料
版权声明
出处: 博客园 马瘦风的博客(https://www.cnblogs.com/shoufeng)
感谢阅读, 如果文章有帮助或启发到你, 点个[好文要顶?] 或 [推荐?] 吧?
本文版权归博主所有, 欢迎转载, 但 [必须在文章页面明显位置标明原文链接], 否则博主保留追究相关人员法律责任的权利.