前言
案列概述
日志分析是运维工程师解决系统故障,发现问题的主要手段。日志主要包括系统日志、应用程序日志和安全日志
Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
Logstash是一个完全开源的工具,它可以对你的日志进行收集、过滤,并将其存储,供以后使用,比如搜索
Kibana 也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch 提供友好的日志分析Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
ELK工作原理
图为完整的日志系统
首先appserver跑业务的(nginx或者apache等),它的日志被logstash收集,logstash定时去检索appserver的日志,
收集完了之后,传给es,es做两件事,第一重组日志,第二快速定位日志的内容,es在里面充当中央枢纽,当我需要让它展现出相关的信息时,通过kibana展示,在网页的页面中展现
简单来说,进行日志处理分析,一般需要经过以下几个步骤: |
---|
将日志进行集中化管理(beats) |
将日志格式化(logstash) |
对格式化后的数据进行索引和存储(elasticsearch) |
前端数据的展示(kibana) |
1.知识拓展
同时还有个轻量级别的filebeat
有些化是在logstash前面加上filebeat,filebeat处理
kagka是一个消息队列工具
像电商的级别基本都是百亿级别的pv量
基本其他的基本都是百万pv和千万pv,那这种级别离不开消息队列
现在基本上市场全是kafka,因为是java开发的,java是老大啊,你得考虑它
2.Elasticsearch介绍
Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是第二流行的企业搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便
Elasticsearch的基础核心概念: |
---|
接近实时(NRT):轻微的延迟(通常是1秒) |
集群(cluster):一个或多个节点组织在一起 |
节点(node):节点就是一台单一的服务器 |
索引(index):一个索引就是一个拥有几分相似特征的文档的集合 |
类型(type):在一个索引中,你可以定义一种或多种类型 |
分片和副本(shards & replicas): |
分片:解决单个节点搜索请求太慢, 副本:解决应对分片或者节点故障 |
3.Logstash介绍
Logstash由JRuby语言编写,基于消息的简单架构,并运行在Java虚拟机上。不同于分离的代理端或主机端,LogStash可配置单一的代理端与其它开源软件结合,以实现不同的功能。
Logstash是一款强大的数据处理工具,可以实现数据传输、格式出来i、格式化输出
数据输出(Collect),数据加工(Enrich),如过滤、改写等,以及数据输出(Transport)
3.1LogStash的主要组件
主要组件:
Shipper:日志收集者 ,负责监控本地日志文件的变化,及时把日志文件的最新内容收集起来 |
---|
Indexer:日志存储者,负责接收日志并写入到本地文件 |
Broker:日志Hub,负责连接多个Shipper和多个Indexer |
Search and Storage:允许对事件进行搜索和存储 |
Web Interface:基于Web的展示界面 |
4.Kibana介绍
Kibana是一个针对Elasticsearch的开源分析及可视化平台。用来搜索、查看交互存储在Elasticsearch索引中的数据。使用Kibana,可以通过各种图表进行高级数据分析及展示。
Kibana让海量数据更容易理解。它操作简单,基于浏览器的用户界面可以快速创建仪表板(dashboard)实时显示Elasticsearch查询动态。设置Kibana非常简单。无需编写代码,几分钟内就可以完成Kibana安装并启动Elasticsearch索引监测
4.1主要功能
主要功能:
Elasticsearch无缝之集成 |
---|
整合数据,复杂数据分析 |
让更多团队成员受益 |
接口灵活,分享更容易 |
配置简单,可视化多数据源 |
简单数据导出 |
配置ELK
1.底层环境
20.0.0.21 | elasticsearch node1 |
---|---|
20.0.0.22 | elasticsearch node2 |
20.0.0.23 | logstatsh |
20.0.0.24 | kibanna |
网关 | 20.0.0.1 |
系统环境 | Centos7.4 防火墙和核心防护全关 |
2.部署elasticsearch软件
######配种node1######
[root@node1 ~]# vi /etc/hosts
20.0.0.21 node1
20.0.0.22 node2
##查看JAVA环境##
[root@node1 ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
【部署elasticsearch软件】
##上传elasticsearch-5.5.0.rpm到opt##
[root@node1 ~]# cd /opt/
[root@node1 opt]# rpm -ivh elasticsearch-5.5.0.rpm
###加载系统服务##
[root@node1 opt]# systemctl daemon-reload
[root@node1 opt]# systemctl enable elasticsearch.service
###修改elasticsearch配置文件
[root@node1 opt]# cd /etc/elasticsearch/
[root@node1 elasticsearch]# cp elasticsearch.yml elasticsearch.yml.bak
[root@node1 elasticsearch]# vim elasticsearch.yml
###修改以下行内容:
17 cluster.name: my-elk-cluster ###更改集群名字
23 node.name: node1 ###节点名字
33 path.data: /data/elk_data ###数据存放路径
37 path.logs: /var/log/elasticsearch/ ###日志存放路径
43 bootstrap.memory_lock: false ###不在启动的时候锁定内存:锁定物理内存地址,防止es内存被交换出去
55 network.host: 0.0.0.0 ###提供服务绑定的IP地址,0.0.0.0代表所有地址
60 http.port: 9200 ###监听端口开启
69 discovery.zen.ping.unicast.hosts: ["node1", "node2"] ###群集发现通过单播实现
##创建配置文件指定的目录,并给权限####
[root@node1 elasticsearch]# cd ~
[root@node1 ~]# mkdir -p /data/elk_data
[root@node1 ~]# id elasticsearch
uid=990(elasticsearch) gid=985(elasticsearch) groups=985(elasticsearch)
[root@node1 ~]# chown elasticsearch.elasticsearch /data/elk_data/
[root@node1 ~]# ll /data/
drwxr-xr-x 2 elasticsearch elasticsearch 6 Oct 28 22:50 elk_data
[root@node1 ~]# systemctl start elasticsearch.service
[root@node1 ~]# netstat -anutp | grep 9200
tcp6 0 0 :::9200 :::* LISTEN 39182/java
######配种node2######
[root@node2 ~]# vi /etc/hosts
20.0.0.21 node1
20.0.0.22 node2
##查看JAVA环境##
[root@node2 ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
【部署elasticsearch软件】
##上传elasticsearch-5.5.0.rpm到opt##
[root@node2 ~]# cd /opt/
[root@node2 opt]# rpm -ivh elasticsearch-5.5.0.rpm
###加载系统服务##
[root@node2 opt]# systemctl daemon-reload
[root@node2 opt]# systemctl enable elasticsearch.service
###修改elasticsearch配置文件
[root@node2 opt]# cd /etc/elasticsearch/
[root@node2 elasticsearch]# cp elasticsearch.yml elasticsearch.yml.bak
[root@node2 elasticsearch]# vim elasticsearch.yml
###修改以下行内容:
17 cluster.name: my-elk-cluster ###更改集群名字
23 node.name: node2 ###节点名字
33 path.data: /data/elk_data ###数据存放路径
37 path.logs: /var/log/elasticsearch/ ###日志存放路径
43 bootstrap.memory_lock: false ###不在启动的时候锁定内存:锁定物理内存地址,防止es内存被交换出去
55 network.host: 0.0.0.0 ###提供服务绑定的IP地址,0.0.0.0代表所有地址
60 http.port: 9200 ###监听端口开启
69 discovery.zen.ping.unicast.hosts: ["node1", "node2"] ###群集发现通过单播实现
##创建配置文件指定的目录,并给权限####
[root@node2 elasticsearch]# cd ~
[root@node2 ~]# mkdir -p /data/elk_data
[root@node2 ~]# id elasticsearch
uid=990(elasticsearch) gid=985(elasticsearch) groups=985(elasticsearch)
[root@node2 ~]# chown elasticsearch.elasticsearch /data/elk_data/
[root@node2 ~]# ll /data/
drwxr-xr-x 2 elasticsearch elasticsearch 6 Oct 28 22:50 elk_data
[root@node2 ~]# systemctl start elasticsearch.service
##这里需要等待3-5秒时间###
[root@node2 ~]# netstat -anutp | grep 9200
tcp6 0 0 :::9200 :::* LISTEN 39182/java
##创建完成之后,用浏览器分别访问这两个节点,可以看到一些信息
检查群集健康以及状态
######检查集群是否健康#######用浏览器打开#####
http://20.0.0.22:9200/_cluster/health?pretty
{
"cluster_name" : "my-elk-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 2,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"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" : 100.0
}
###这里我是把网页内容复制下来了,如果你跟着我做,可以对比一下下
########检查集群状态########用浏览器打开#####
http://20.0.0.22:9200/_cluster/state?pretty
{
"cluster_name" : "my-elk-cluster",
"version" : 3,
"state_uuid" : "mfRW_hsqQTi2a-dPv7b0lw",
"master_node" : "L2bUjM2IQueQ42ij4I1BaA",
"blocks" : { },
"nodes" : {
"L2bUjM2IQueQ42ij4I1BaA" : {
"name" : "node1",
"ephemeral_id" : "oKH8eeVJRy25VN8srbwXxg",
"transport_address" : "20.0.0.21:9300",
"attributes" : { }
},
"ypp2H_6sSvOMtNQAwlaibw" : {
"name" : "node2",
"ephemeral_id" : "41HsQYuFRCST8bs6VwvQAA",
"transport_address" : "20.0.0.22:9300",
"attributes" : { }
}
},
"metadata" : {
"cluster_uuid" : "aEofhlk4RaSGLw5g104z-Q",
"templates" : { },
"indices" : { },
"index-graveyard" : {
"tombstones" : [ ]
}
},
"routing_table" : {
"indices" : { }
},
"routing_nodes" : {
"unassigned" : [ ],
"nodes" : {
"ypp2H_6sSvOMtNQAwlaibw" : [ ],
"L2bUjM2IQueQ42ij4I1BaA" : [ ]
}
}
}
###这里我是把网页内容复制下来了,如果你跟着我做,可以对比一下下
3.安装elasticsearch-head插件
#####安装[elasticsearch-head插件],可以看到上述查看集群的方式,及其不便#######
####下面所有操作两台节点同时进行######这里以node1示例###
#####上传node-v8.2.1.tar.gz到opt######
[root@node1 elasticsearch]# cd /opt/
[root@node1 opt]# yum -y install gcc gcc-c++ make
[root@node1 opt]# tar zxvf node-v8.2.1.tar.gz
[root@node1 opt]# cd node-v8.2.1/
[root@node1 node-v8.2.1]# ./configure
[root@node1 node-v8.2.1]# make -j3 ###过程时间长,耐心等待
[root@node1 node-v8.2.1]# make install
[root@node2 node-v8.2.1]# cd /opt/
###安装phantomjs######前端框架####
####上传软件包到opt###
[root@node1 opt]# tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@node1 opt]# cd phantomjs-2.1.1-linux-x86_64/bin/
[root@node1 bin]# ll
总用量 66340
-rwxr-xr-x 1 root root 67932064 1月 25 2016 phantomjs
[root@node1 bin]# cp phantomjs /usr/local/bin/
[root@node1 bin]# cd /opt/
###安装elasticsearch-head###数据可视化工具
上传elasticsearch-head.tar.gz到opt
[root@node1 elasticsearch-head]# tar zxvf elasticsearch-head.tar.gz
[root@node1 opt]# cd elasticsearch-head/
[root@node1 elasticsearch-head]# npm install
######修改主配置文件##########
##去末尾添加##
[root@node1 ~]# cd ~
[root@node1 ~]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@node1 ~]# systemctl restart elasticsearch.service
######启动elasticsearch-head 启动服务器####
[root@node1 ~]# cd /opt/elasticsearch-head/
[root@node1 elasticsearch-head]# npm run start & ###切换到后台运行
[1] 87925
[root@node1 elasticsearch-head]#
> elasticsearch-head@0.0.0 start /opt/elasticsearch-head
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
######修改主配置文件##########
##去末尾添加##
[root@node1 ~]# cd ~
[root@node1 ~]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@node1 ~]# systemctl restart elasticsearch.service
######启动elasticsearch-head 启动服务器####
[root@node1 ~]# cd /opt/elasticsearch-head/
[root@node1 elasticsearch-head]# npm run start & ###切换到后台运行
[1] 87925
[root@node1 elasticsearch-head]#
> elasticsearch-head@0.0.0 start /opt/elasticsearch-head
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
4.安装logstash
################20.0.0.23,开台新机安装logstash#####################
[root@localhost ~]# hostnamectl set-hostname apache
[root@localhost ~]# su
###安装apache
[root@apache opt]# yum -y install httpd
###检查java环境
[root@apache ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
###安装logstash##########
上传logstash-5.5.1.rpm包到20.0.0.23的opt下
[root@apache opt]# cd /opt/
[root@apache opt]# ll
总用量 91952
-rw-r--r-- 1 root root 94158545 8月 11 2017 logstash-5.5.1.rpm
[root@apache opt]# rpm -ivh logstash-5.5.1.rpm
警告:logstash-5.5.1.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:logstash-1:5.5.1-1 ################################# [100%]
Using provided startup.options file: /etc/logstash/startup.options
Successfully created system startup script for Logstash
[root@apache opt]# systemctl start logstash.service
[root@apache opt]# systemctl enable logstash.service
[root@apache opt]# ln -s /usr/share/logstash/bin/logstash /usr/local/bin/
5、logstash (Apache)与elasticsearch (node)功能是否正常,做对接测试##转赫
Logstash这个命令测试
字段描述解释:
-f 通过这个选项可以指定logstash的配置文件,根据配置文件配置logstash
-e 后面跟着字符串,该字符串可以被当做logstash的配置(如果是””,则默认使用stdin做为输入、stdout作为输出)
-t 测试配置文件是否正确,然后退出
######启动httpd,生成配置文件#####
[root@apache opt]# cd /var/log/httpd/
[root@apache httpd]# ls
[root@apache httpd]# systemctl start httpd
[root@apache httpd]# ls
access_log error_log
[root@apache httpd]# cat access_log ##没日志是没访问信息
###这个时候用网页访问一下httpd,让他出现日志
[root@apache httpd]# cat access_log
20.0.0.1 - - [29/Oct/2020:19:35:16 +0800] "GET / HTTP/1.1" 403 4897 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
20.0.0.1 - - [29/Oct/2020:19:35:16 +0800] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "http://20.0.0.23/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
20.0.0.1 - - [29/Oct/2020:19:35:16 +0800] "GET /noindex/css/bootstrap.min.css HTTP/1.
###输入采用标准输入,输出采用标准出 --登录20.0.0.23 在Apache服务器上
input { stdin{} } 输入口:指日志文件位置
output { stdout{} }输出口:指向es,或者某个终端
####stdout用法,这个不需要做,知识展示用法#######
[root@apache httpd]# echo "123123" | passwd --stdout zzt
更改用户 zzt 的密码
passwd: 所有的身份验证令牌已经更新
########
[root@apache httpd]# logstash -e 'input { stdin{} } output { stdout{} }'
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path //usr/share/logstash/config/log4j2.properties. Using default config which logs to console
19:39:09.346 [main] INFO logstash.setting.writabledirectory - Creating directory {:setting=>"path.queue", :path=>"/usr/share/logstash/data/queue"}
19:39:09.349 [main] INFO logstash.setting.writabledirectory - Creating directory {:setting=>"path.dead_letter_queue", :path=>"/usr/share/logstash/data/dead_letter_queue"}
19:39:09.368 [LogStash::Runner] INFO logstash.agent - No persistent UUID file found. Generating new UUID {:uuid=>"4f373d0f-605c-418d-b98f-1f59d338e381", :path=>"/usr/share/logstash/data/uuid"}
19:39:09.446 [[main]-pipeline-manager] INFO logstash.pipeline - Starting pipeline {"id"=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>5, "pipeline.max_inflight"=>500}
19:39:09.466 [[main]-pipeline-manager] INFO logstash.pipeline - Pipeline main started
The stdin plugin is now waiting for input:
19:39:09.520 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}
www.zeng.com #####在这里随便输入点什么
2020-10-29T11:39:22.368Z apache www.zeng.com ###这里看到被输出出来了
### 使用rubydebug显示详细输出,codec为一种编解码器
[root@apache httpd]# logstash -e 'input { stdin{} } output { stdout{ codec=>rubydebug } }'
###这个ERROR是没设置java功能,完全不影响你操作,
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path //usr/share/logstash/config/log4j2.properties. Using default config which logs to console
19:49:06.840 [[main]-pipeline-manager] INFO logstash.pipeline - Starting pipeline {"id"=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>5, "pipeline.max_inflight"=>500}
19:49:06.882 [[main]-pipeline-manager] INFO logstash.pipeline - Pipeline main started
The stdin plugin is now waiting for input:
{
"@timestamp" => 2020-10-29T11:49:06.908Z,
"@version" => "1", #######这一段是apache自己带的############
"host" => "apache",
"message" => ""
}
19:49:06.990 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}
www.baidu.com #############输入个网址试试,展示信息更详细了
{
"@timestamp" => 2020-10-29T11:49:20.344Z,
"@version" => "1",
"host" => "apache",
"message" => "www.baidu.com"
}
###使用logstash将信息写入elasticsearch中#### 输入 输出 如何对接?######
[root@apache ~]# logstash -e 'input { stdin{} } output { elasticsearch {hosts=>["20.0.0.21:9200"] } }'
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path //usr/share/logstash/config/log4j2.properties. Using default config which logs to console
19:55:35.801 [[main]-pipeline-manager] INFO logstash.outputs.elasticsearch - Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://20.0.0.21:9200/]}}
_inflight"=>500}
The stdin plugin is now waiting for input:
19:55:36.205 [[main]-pipeline-manager] INFO logstash.pipeline - Pipeline main started
19:55:36.355 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}
www.baidu.com #############输入个网址
www.zeng.com #############输入个网址
###这个时候打开真机浏览器访问 20.0.0.21:9100/20.0.0.22:9100可以看到多出来个logstash-2020.10.29
###点击数据浏览,点击_index
{
"_index": "logstash-2020.10.29",
"_type": "logs",
.............// ####省略部分
"@version": "1",
"host": "apache",
"message": "www.zeng.com" ######这个就是你刚刚输的,没问题继续向下
##这个时候做对接配置
##logstash配置文件主要由三部分组成:input output filter(是一个过滤器)
###如果想将系统文件日志通过kibana呈现###
#首先将messages设置成其他账户可读
[root@apache ~]# chmod o+r /var/log/messages
[root@apache ~]# ll /var/log/messages
-rw----r--. 1 root root 1258129 10月 29 20:10 /var/log/messages
##在logstash/conf.d/(logstash的配置文件目录中添加配置文件,用来input系统日志,output给ES)
[root@apache ~]# cd /etc/logstash/conf.d/
[root@apache conf.d]# vim system.conf #####名字随便定义,但要.conf结尾
input {
file{
path => "/var/log/messages" ##系统日志位置
type => "system" ##自定义标签名
start_position => "beginning" ##从日志文件的最上面开始
}
}
output {
elasticsearch {
hosts => ["20.0.0.21:9200"] ###ES的某一个节点,也可以是20.0.0.22:9200
index => "system-%{+YYYY.MM.dd}" ###存储时+年月日后缀
}
}
[root@apache conf.d]# systemctl restart logstash.service
###这个时候网页访问ES群集,会发现创建完成了###
5.安装kibanna
######再开一台主机 20.0.0.24 安装kibanna######################
上传kibana-5.5.1-x86_64.rpm到opt
[root@localhost ~]# cd /opt/
[root@localhost opt]# ll
总用量 51032
-rw-r--r-- 1 root root 52255853 8月 11 2017 kibana-5.5.1-x86_64.rpm
[root@localhost opt]# rpm -ivh kibana-5.5.1-x86_64.rpm
警告:kibana-5.5.1-x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:kibana-5.5.1-1 ################################# [100%]
[root@localhost opt]# cd /etc/kibana/
[root@localhost kibana]# ll
总用量 8
-rw-r--r-- 1 root root 4649 7月 19 2017 kibana.yml
[root@localhost kibana]# cp kibana.yml kibana.yml.bak
[root@localhost kibana]# vim kibana.yml
2 server.port: 5601 ###开启监听端口
7 server.host: "0.0.0.0" ###kibana监听的地址段
21 elasticsearch.url: "http://20.0.0.21:9200" ###监听某一个节点的地址,但生产环境一般做负载均衡,一般指VIP地址
30 kibana.index: ".kibana" ###开启kibana索引
[root@localhost kibana]# systemctl start kibana.service
[root@localhost kibana]# systemctl enable kibana.service
去真机网页浏览20.0.0.24:5601 选择system-* 点击create 就可以了
首先查看ES群集是否已经有数据了
有了以后我们操作kibana
可以看到,带system标签的所有日志都在
6.将apache访问与错误的日志分开
###############下面对接apache主机的日志文件(访问与错误的分开)
###到apache主机上:20.0.0.23,也就是logstash###
[root@apache ~]# cd /etc/logstash/conf.d/
[root@apache conf.d]# vim apache.conf
input {
file{
path => "/etc/httpd/logs/access_log"
type => "access"
start_position => "beginning"
}
file{
path => "/etc/httpd/logs/error_log"
type => "error"
start_position => "beginning"
}
}
output {
if [type] == "access" {
elasticsearch {
hosts => ["20.0.0.21:9200"]
index => "apache_access-%{+YYYY.MM.dd}"
}
}
if [type] == "error" {
elasticsearch {
hosts => ["20.0.0.21:9200"]
index => "apache_error-%{+YYYY.MM.dd}"
}
}
}
##上面用了if判断,将正常访问的日志记录与错误访问的日志记录分开贴上标签了##
[root@apache conf.d]# /usr/share/logstash/bin/logstash -f apache.conf ##启动这个配置文件
##凡是看见No log4j2就不用管,不影响你操作,一下为省略部分。。。
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path //usr/share/logstash/config/log4j2.properties. Using default config which logs to console
22:02:29.765 [[main]-pipeline-manager] INFO logstash.pipeline - Pipeline main started
22:02:29.799 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}
####OK,这个时候访问你的浏览器20.0.0.21:9100/20.0.0.22:9100##
####查看这两项
apache_error-2020.10.29
apache_access-2020.10.29
###都出来了
.kibana 这个也默认出来了
###创建#####
####这个时候访问20.0.0.24:5601,去新创一个apache_access-*或者apache_error-*
-* : 表示你后面所有时间都可以