日志分析系ELK

一.ELK概述

-Elasticsearch:负责日志检索和存储
-Logstash:负责日志的收集和分析,处理
-Kibana:负责日志的可视化
-ELK是一整套解决方案,是三个软件产品的首字母缩写,很多公司都在使用,如:Sina,携程,华为,美团等
-这三款软件都是开源软件,通常是配合使用,而且又先后归于Elastic.co公司名下,简称ELK

ELK组件在海量日志系统的运维中,可用于解决

-分布式日志数据集中式查询和管理
-系统监控,包括系统硬件和应用各个组件的监控
-故障排查
-安全信息和事件管理
-报表功能
ELK架构图例在这里插入图片描述在这里插入图片描述

二.Elasticsearch

1.Elasticsearch的概述

ElasticSearch 是-个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTfulAPI的Web接口 Elasticsearch
是用Java开发的,使用Apache许可条款的开源软件,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便

主要特点

-实时分析,文档导向,分布式实时文件存储
-高可用性,易扩展,支持集群(Cluster) 、分片和复制(Shards和Rep licas)
-接口友好,支持JSON
-没有典型意义的事务
-是一种面向文档的数据库

名词解释

Node: 装有一个ES服务器的节点
Cluster: 有多个Node组成的集群
Document : -个可被搜索的基础信息单元
Index: 拥有相似特征的文档的集合
Type: 一个索引中可以定义一种或多种类型
Filed: 是ES的最小单位,相当于数据的某-列
Shards: 索引的分片,每一个分片就是- -个Shard
Replicas: 索引的拷贝

与关系数据库对比
在这里插入图片描述

2.部署Elasticsearch的准备
1)在跳板机上配置 yum 仓库
拷贝云盘 rpm-package/elk 目录到跳板机

[root@ecs-proxy public]# ls elk/
elasticsearch-6.8.8.rpm    logs.jsonl.gz
filebeat-6.8.8-x86_64.rpm  logstash-6.8.8.rpm
head.tar.gz                metricbeat-6.8.8-x86_64.rpm
kibana-6.8.8-x86_64.rpm
[root@ecs-proxy ~]# cp -a elk /var/ftp/localrepo/elk
[root@ecs-proxy ~]# cd /var/ftp/localrepo/
[root@ecs-proxy localrepo]# createrepo --update .

2)购买云主机

主机IP地址配置
es-0001192.168.1.41最低配置2核2G
es-0002192.168.1.42最低配置2核2G
es-0003192.168.1.43最低配置2核2G
es-0004192.168.1.44最低配置2核2G
es-0005192.168.1.45最低配置2核2G

3.安装单机板elasticsearch

[root@es-0001 ~]# vim /etc/hosts
192.168.1.41	es-0001
[root@es-0001 ~]# yum install -y java-1.8.0-openjdk elasticsearch
[root@es-0001 ~]# vim /etc/elasticsearch/elasticsearch.yml
55:  network.host: 0.0.0.0
[root@es-0001 ~]# systemctl enable --now elasticsearch

测试

[root@es-0001 ~]# curl http://192.168.1.41:9200/
{
  "name" : "War Eagle",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.4",
    "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
    "build_timestamp" : "2016-06-30T11:24:31Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}

4.安装集群板elasticsearch

status:green
-集群状态,绿色为正常
-黄色表示有问题但不是很严重,红色表示严重故障
number_of_nodes:5
-表示集群中节点的数量
number_of_data_nodes:5
-用于储存数据节点数量

es-0001 … es-0005 所有主机,都要执行以下操作

[root@es-0001 ~]# vim /etc/hosts
192.168.1.41	es-0001
192.168.1.42	es-0002
192.168.1.43	es-0003
192.168.1.44	es-0004
192.168.1.45	es-0005
[root@es-0001 ~]# yum install -y java-1.8.0-openjdk elasticsearch
[root@es-0001 ~]# vim /etc/elasticsearch/elasticsearch.yml
17:  cluster.name: my-es #集群名
23:  node.name: es-0001 # 本机主机名
55:  network.host: 0.0.0.0  #监听地址,这里为所有
68:  discovery.zen.ping.unicast.hosts: ["es-0001", "es-0002"]          #创始人
[root@es-0001 ~]# systemctl enable --now elasticsearch

测试

[root@es-0001 ~]# curl http://192.168.1.41:9200/_cluster/health?pretty
{
  "cluster_name" : "my-es",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 5,
  "number_of_data_nodes" : 5,
   ... ...
}

注:集群对于用户都是一样的,所以访问的ip可以是任意节点的ip

三.集群配置文件

1.Head插件概述

-它展现ES集群的拓扑结构,并且可以通过它来进行索引( Index) 和节点(Node) 级别的操作
-它提供一-组针对集群的查询API,并将结果以json和表格形式返回
-它提供一 些快捷菜单,用以展现集群的各种状态

2.插件原理图
在这里插入图片描述购买云主机

主机IP地址配置
web192.168.1.48最低配置1核1G

3.安装插件
安装 apache,并部署 head 插件

[root@web ~]# yum install -y httpd
[root@web ~]# tar zxf head.tar.gz
[root@web ~]# mv elasticsearch-head /var/www/html/head
[root@web ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

4.es-0001 访问授权
[root@es-0001 ~]# vim /etc/elasticsearch/elasticsearch.yml

#配置文件最后追加
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length
[root@es-0001 ~]# systemctl restart elasticsearch.service 

5.测试
使用华为 ELB, 把 web 服务的80端口和 es-0001 的 9200 端口发布到互联网,并通过浏览器访问
1)购买 ELB与购买ip并绑定
在这里插入图片描述在这里插入图片描述![在这里插入图片描述](https://img-blog.csdnimg.cn/b206534b800e4cafa38d686f9621cd01.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAa2FsaV95YW8=,size_20,color_FFFFFF,t_70,g_se,x_16

2)添加两个监控器(80,9200)
在这里插入图片描述在这里插入图片描述

3)分别监听web与Head插件
在这里插入图片描述在这里插入图片描述4)浏览器访问病连接插件

注:*是master,master是自动分配的

在这里插入图片描述

四.Elasticsearch访问请求插件(curl)

集群API的简单管理概述
1.浏览器访问
Elast icsearch是用http协议访问
http请求由三部分组成
-分别是:请求行、消息报头、请求正文.
-请求行:Method Request-URI HTTP- -Version CRLF
http请求方法
-常用方法GET, POST, HEAD
-其他方法OPTIONS, PUT, DELETE,TRACE和CONNECT

2.命令行访问
Elasticsear ch使用的请求方法
增 — PUT
删 — DEL ETE
改 — POST
查 — GET
与Elast icsearch交互的数据需使用json格式

3.curl命令访问
在linux中curl是一个利用URL 规则在命令行下工作的文件传输工具,可以说是- -款很强大的http命令行工具。它支持多种请求模式,自定义请求头等强大功能,是一款综合工具
使用格式:
curl -X请求方法 http://请求地址
curI -H自定义请求头 http://请求地址

4.curl使用
_ cat关键字用来查询集群状态,节点信息等-显示详细信息(?v),显示帮助信息(?he lp)

#查询支持的关键字
[root@es-0001 ~]# curl -XGET http://es-0001:9200/_cat/
#查具体的信息
[root@es-0001 ~]# curl -XGET http://es-0001:9200/_cat/master
#显示详细信息 ?v
[root@es-0001 ~]# curl -XGET http://es-0001:9200/_cat/master?v
#显示帮助信息 ?help
[root@es-0001 ~]# curl -XGET http://es-0001:9200/_cat/master?help

5.创建索引使用 PUT方法

定索引的名称,指定分片数量,指定副本数量
创建索引使用 PUT 方法,创建完成以后通过 head 插件验证
[root@es-0001 ~]# curl -XPUT -H "Content-Type: application/json" http://es-0001:9200/tedu -d \ '{ "settings":{ "index":{ "number_of_shards": 5, #数据分几个片 "number_of_replicas": 1 #几个副本 } } }'

6.增加数据

[root@es-0001 ~]# curl -XPUT -H "Content-Type: application/json" http://es-0001:9200/tedu/teacher/1 -d \
'{
  "职业": "诗人",
  "名字": "李白",
  "称号": "诗仙",
  "年代": "唐"
}' 

在这里插入图片描述

7.查询数据

[root@es-0001 ~]# curl -XGET http://es-0001:9200/tedu/teacher/1?pretty

8.修改数据

[root@es-0001 ~]# curl -XPOST -H "Content-Type: application/json" \
                  http://es-0001:9200/tedu/teacher/1/_update -d '{ "doc": {"年代":"公元701"}}'

9.删除数据

# 删除一条
[root@es-0001 ~]# curl -XDELETE http://es-0001:9200/tedu/teacher/1
# 删除索引
[root@es-0001 ~]# curl -XDELETE http://es-0001:9200/tedu

五.kibana

1.kibana介绍

kibana是什么
-数据可视化平台工具

特点:

-灵活的分析和可视化平台
-实时总结流量和数据的图表
-为不同的用户显示直观的界面
-即时分享和嵌入的仪表板.

2.kibana安装配置
1)#购买云主机

主机IP地址配置
kibana192.168.1.46最低配置1核1G

2)安装kibana

[root@kibana ~]# vim /etc/hosts
192.168.1.41	es-0001
192.168.1.42	es-0002
192.168.1.43	es-0003
192.168.1.44	es-0004
192.168.1.45	es-0005
192.168.1.46	kibana
[root@kibana ~]# yum install -y kibana
[root@kibana ~]# vim /etc/kibana/kibana.yml
02  server.port: 5601             #端口
07  server.host: "0.0.0.0"        #允许访问ip
28  elasticsearch.hosts: ["http://es-0002:9200", "http://es-0003:9200"]           #默认网页地址 
37  kibana.index: ".kibana"      #索引
40  kibana.defaultAppId: "home"  #默认首页菜单
113 i18n.locale: "zh-CN"         #语言
[root@kibana ~]# systemctl enable --now kibana

3.绑定弹性公网IP,通过 WEB 浏览器验证
ip在前面已经绑定了
在这里插入图片描述在这里插入图片描述## 六.kibana绘制图表

1.导入数据概述
数据导入条件:

-必须指定json 格式Content- Type: applicat i on/ json
-导入关键字:_ _bulk

  • HTTP方法: POST

2.导入日志数据测试
拷贝云盘 /var/ftp/localrepo/elk/logs.jsonl.gz 到跳板机

[root@ecs-proxy ~]# cd  /var/ftp/localrepo/elk/
[root@ecs-proxy ~]# cp logs.jsonl.gz /root/
[root@ecs-proxy ~]# gunzip logs.jsonl.gz 
[root@ecs-proxy ~]# curl -XPOST -H "Content-Type: application/json" http://192.168.1.41:9200/_bulk --data-binary @logs.jsonl 

3.在这里插入图片描述查看
在这里插入图片描述4.绘制流量图
1)选择使用Elasticsearch
在这里插入图片描述在这里插入图片描述如果有实时日志则不需要这些操作
在这里插入图片描述在这里插入图片描述在这里插入图片描述2)另外一种分析图
在这里插入图片描述饼图
在这里插入图片描述在这里插入图片描述还可以选择子图
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值