|NO.Z.00052|——————————|^^ 部署 ^^|——|Hadoop&ElasticSearch.V04|——|ELK.v04|Logstash部署.V4|

一、Output插件:标准输出到控制台
### --- 标准输出到控制台

~~~     # 将收集的数据直接打印到控制台
[root@hadoop02 ~]# /opt/yanqi/servers/es/Logstash/bin/logstash \
-e 'input{stdin{}}output{stdout{codec=>rubydebug}}'
 ~~~输出参数:hello
{
       "message" => "hello",
    "@timestamp" => 2021-11-26T10:07:37.257Z,
          "host" => "hadoop02",
      "@version" => "1"
}
二、将采集数据保存到file文件中
### --- 将采集数据保存到file文件中

~~~     # Logstash也可以将收集到的数据写入到文件当中去永久保存,接下来我们来看看Logstash如何配置以实现将数据写入到文件当中
~~~     # 开发Logstash的配置文件
[root@hadoop02 ~]# vim /opt/yanqi/servers/es/Logstash/config/output_file.conf
 ~~~写入配置参数
input {stdin{}}
output {
  file {
   path => "/opt/yanqi/servers/es/datas/%{+YYYY-MM-dd}-%{host}.txt"
   codec => line {
    format => "%{message}"
   }
   flush_interval => 0
 }
}
### --- 检查配置文件的完整性

~~~     # 检查配置文件的完整性
[root@hadoop02 ~]# /opt/yanqi/servers/es/Logstash/bin/logstash \
-f /opt/yanqi/servers/es/Logstash/config/output_file.conf -t
 ~~~输出参数
Configuration OK
Config Validation Result: OK. Exiting Logstash
### --- 启动Logstash服务

~~~     # 启动服务,然后从控制台输入一些数据
[root@hadoop02 ~]# /opt/yanqi/servers/es/Logstash/bin/logstash \
-f /opt/yanqi/servers/es/Logstash/config/output_file.conf
 ~~~输出参数:11.11 神棍节
[2021-11-26T18:13:28,230][INFO ][logstash.outputs.file    ] Closing file /opt/yanqi/servers/es/datas/2021-11-26-hadoop02.txt 
### --- 查看文件写入的内容

~~~     # 查看输出的数据
[root@hadoop02 ~]# cat  /opt/yanqi/servers/es/datas/2021-11-26-hadoop02.txt 
 
11.11 神棍节
三、将采集数据保存到elasticsearch
### --- 开发Logstash的配置文件

~~~     # 这个index是保存到elasticsearch上的索引名称,如何命名特别重要,因为我们很可能后续根据某些需求做查询,所以最好带时间
[root@hadoop02 ~]# vim /opt/yanqi/servers/es/Logstash/config/output_es.conf
 ~~~写入配置文件参数
input {stdin{}}
output {
  elasticsearch {
    hosts => ["hadoop02:9200"]
    index => "logstash-%{+YYYY.MM.dd}"
  }
}
### --- 检查配置文件的完整性

~~~     # 检测配置文件是否正确
[root@hadoop02 ~]# /opt/yanqi/servers/es/Logstash/bin/logstash \
-f /opt/yanqi/servers/es/Logstash/config/output_es.conf -t
 ~~~输出参数
Configuration OK
Config Validation Result: OK. Exiting Logstash
### --- 启动Logstash

~~~     # 启动Logstash服务
[root@hadoop02 ~]# /opt/yanqi/servers/es/Logstash/bin/logstash \
-f /opt/yanqi/servers/es/Logstash/config/output_es.conf
~~~输入参数
11.11 神棍节 
四、es当中查看数据访问:http://hadoop02:9100/  查看es当中的数据

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(20)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示