|NO.Z.00012|——————————|Deployment|——|Hadoop&ElasticSearch集中式日志分析系统.v12|——|Elasticsearch.v12|Logstash
一、Output插件:标准输出到控制台
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
### --- 标准输出到控制台
~~~ # 将收集的数据直接打印到控制台
[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