logstash是一个数据采集、加工处理以及传输的工具,目前流行搭配
• logstash 特点:
– 所有类型的数据集中处理https://www.elastic.co/guide/en/logstash/current/input-plugins.html //帮助文档地址
logstash 工作结构
– { 数据源 } ==>input { } ==>filter { } ==>output { } ==>{ ES }
• logstash 数据类型
– 布尔值类型: ssl_enable => true– 注释: #
• logstash 条件判断
– 等于: ==– 不匹配正则: !~
– 包含: in
– 不包含: not in
– 且: and
– 否: or
– 非且: nand
– 非或: xor
– 复合表达式: ()
– 取反符合:!()
• logstash 插件(codec类、input类、filter类、output类)
– codec是通用类插件,input(数据来源)、filter(数据过滤)、output(数据输出)
– 对不熟悉的插件,可以网上看帮助文档
logstash-codec-collectd
logstash-codec-dots
logstash-codec-edn
logstash-codec-edn_lines
logstash-codec-es_bulk
logstash-codec-fluent
logstash-codec-graphite
logstash-codec-json
logstash-codec-json_lines
logstash-codec-line
logstash-codec-msgpack
logstash-codec-multiline
logstash-codec-netflow
logstash-codec-oldlogstashjson
logstash-codec-plain
logstash-codec-rubydebug
logstash-filter-anonymizelogstash-filter-xml
logstash-input-beats
logstash-input-couchdb_changes
logstash-input-elasticsearch
logstash-input-eventlog
logstash-input-exec
logstash-input-file
logstash-input-ganglia
logstash-input-gelf
logstash-input-generator
logstash-input-graphite
logstash-input-heartbeat
logstash-input-http
logstash-input-http_poller
logstash-input-imap
logstash-input-irc
logstash-input-jdbc
logstash-input-kafka
logstash-input-log4j
logstash-input-lumberjack
logstash-input-pipe
logstash-input-rabbitmq
logstash-input-redis
logstash-input-s3
logstash-input-snmptrap
logstash-input-sqs
logstash-input-stdin
logstash-input-syslog
logstash-input-tcp
logstash-input-twitter
logstash-input-udp
logstash-input-unix
logstash-input-xmpp
logstash-input-zeromq
logstash-output-cloudwatch
logstash-output-cloudwatch
logstash-output-csv
logstash-output-elasticsearch
logstash-output-email
logstash-output-exec
logstash-output-file
logstash-output-ganglia
logstash-output-gelf
logstash-output-graphite
logstash-output-hipchat
logstash-output-http
logstash-output-irc
logstash-output-juggernaut
logstash-output-kafka
logstash-output-lumberjack
logstash-output-nagios
logstash-output-nagios_nsca
logstash-output-null
logstash-output-opentsdb
logstash-output-pagerduty
logstash-output-pipe
logstash-output-rabbitmq
logstash-output-redis
logstash-output-s3
logstash-output-sns
logstash-output-sqs
logstash-output-statsd
logstash-output-stdout
logstash-output-tcp
logstash-output-udp
logstash-output-xmpp
logstash-output-zeromq
logstash-patterns-core // 这个是过滤匹配块
• logstash 安装
– Logstash 依赖 java 环境,需要安装 java-1.8.0-openjdk
– Logstash 没有默认的配置文件,需要手劢配置
– logstash 安装在 /opt/logstash 目录下
[root@logstash ~]# yum -y install logstash-2.3.4-1.noarch.rpm //可以网上下载更高的版本
• logstash 的第一个配置文件
[root@logstash ~]# vim /etc/logstash/logstash.conf
input{
stdin{}
}
filter{ }
output{
stdout{}
}
• 测试
[root@logstash ~]# /opt/logstash/bin/logstash -f /etc/logstash/conf.d/logstash.conf
Settings: Default pipeline workers: 2
Pipeline main started
test
test
//可以随便输入什么,就会自动输出相同内容
— codec 类插件
input{
stdin{ codec => "json" }
}
filter{ }
output{
stdout{ codec => "rubydebug" }
}
– 我们输入普通数据和 json 对比
– {"a": 11, "c": 13, "b": 12}
— input file 插件
input {
}
}
– sincedb_path 记录读取文件的位置— input tcp 和 udp 插件
input {
tcp{
host => "0.0.0.0"}
— syslog 插件
input {
syslog{}
}
– rsyslog.conf 配置向进程发送数据 //要传送log的主机上
//rsyslog.conf @@192.168.4.10:514(TCP模式传送)@192.168.4.10:514(UDP模式传送)
//要输出哪个,直接复制默认例如local0.info(名字),再写上传送地址就可以了
local0.info @@192.168.4.10:514– 写 syslog ,查看状态
logger -p local0.info -t test_logstash 'test message'[root@web2 bin]# cat /etc/logstash/conf.d/logstash.conf
input {
file{
path => ["/tmp/a.log","/tmp/b.log"]
sincedb_path => "/var/lib/logstash/since.db"
start_position => "beginning"
type => "filelog"
}
}
filter { }
output {
stdout{ codec => "rubydebug" }
}
— filter grok插件
– 解析各种非结构化的日志数据插件– 几乎可以应用于各类数据
filter {
grok{
match => [“message”,“%{IP:ip}, (?}
}
– grok 正则分组匹配
匹配 ip 时间戳 和 请求方法
"(?