本帖最后由 feng 于 2022-7-1 09:13 编辑
ELK logstash-7.5收集交换机日志
一、交换机配置
添加:info-center loghost 192.168.14.210,IP地址是logstash服务器,华为交换机默认是UDP514端⼝发送数据
1、查看交换机版本
[SW30]display version
- Huawei Versatile Routing Platform Software
- VRP (R) software, Version 5.70 (S2700 V100R006C05)
- Copyright (C) 2003-2013 HUAWEI TECH CO., LTD
- Quidway S2700-9TP-SI-AC Routing Switch uptime is 23 weeks, 5 days, 7 hours, 28 minutes
- E8FED 0(Master) : uptime is 23 weeks, 5 days, 7 hours, 27 minutes
- 64M bytes DDR Memory
- 16M bytes FLASH
- Pcb Version : VER E
- Basic BOOTROM Version : 149 Compiled at Mar 15 2013, 11:02:25
- Software Version : VRP (R) Software, Version 5.70 (V100R006C05)
复制代码
2、配置内容
[SW30]display current-configuration | in info
info-center loghost 192.168.14.210
snmp-agent sys-info version all
二、logstash7.5安装
1、安装JDK
- tar -zxvf jdk-11.0.5_linux-x64_bin.tar.gz -C /usr/local/
复制代码 将java目录信息添加到系统环境变量中
以下目录请按实际安装目录红色部分进行调整
- export JAVA_HOME=<font color="#ff0000">/usr/local/jdk-11.0.5/</font>
- export PATH=$PATH:$JAVA_HOME/bin
- export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
- [root@localhost ~]# source /etc/profile
复制代码
2、解压logstash⼆进制包
- tar -zxvf logstash-7.5.0.tar.gz -C /usr/local/
复制代码
3、添加环境变量
将以下以下目录请按实际安装目录红色部分进行调整
- export PATH=$PATH:<font color="#ff0000">/usr/local/logstash-7.5.0/bin</font>
复制代码 使环境变量,生效
三、logstash7.5配置
1、关闭rsyslog服务,因为这个会占⽤514端⼝
2、添加logstash配置⽂件,根据监听交换机端⼝区分不通⽹络设备型号(直接复制可⽤,修改下IP地址)
- vi /usr/local/logstash-7.5.0/config/switch.conf
复制代码- cat /usr/local/logstash-7.5.0/config/switch.conf
复制代码- input{
- tcp { port => 5002
- type => "Cisco"}
- udp { port => 514
- type => "HUAWEI"}
- udp { port => 5002
- type => "Cisco"}
- udp { port => 5003
- type => "H3C"}
- }
- filter {
- if [type] == "Cisco" {
- grok {
- match => { "message" => "<%{BASE10NUM:syslog_pri}>%{NUMBER:log_sequence}: .%{SYSLOGTIMESTAMP:timestamp}: %%{DATA:facility}-%{POSINT:seve
- match => { "message" => "<%{BASE10NUM:syslog_pri}>%{NUMBER:log_sequence}: %{SYSLOGTIMESTAMP:timestamp}: %%{DATA:facility}-%{POSINT:seve
- add_field => {"severity_code" => "%{severity}"}
- overwrite => ["message"]
- }
- }
- elseif [type] == "H3C" {
- grok {
- match => { "message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP:timestamp} %{YEAR:year} %{DATA:hostname} %%%{DATA:vvmodule}/%{P
- match => { "message" => "<%{BASE10NUM:syslog_pri}>%{SYSLOGTIMESTAMP:timestamp} %{DATA:hostname} %{DATA:ddModuleName}/%{POSINT:seve
- remove_field => [ "timestamp" ]
- add_field => {"severity_code" => "%{severity}"}
- overwrite => ["message"]
- }
- }
- #mutate {
- # gsub => [
- # "severity", "0", "Emergency",
- # "severity", "1", "Alert",
- # "severity", "2", "Critical",
- # "severity", "3", "Error",
- # "severity", "4", "Warning",
- # "severity", "5", "Notice",
- # "severity", "6", "Informational,
- # "severity", "7", "Debug"
- # ]
- # }
- }
- output{
- stdout {
- codec => rubydebug
- }
- elasticsearch {
- index =>
- "syslog-%{+YYYY.MM.dd}"
- hosts => ["<font color="#ff0000">192.168.14.211:9200</font>"]
- user => "elastic"
- password => "password"
- }
- }
复制代码
这⾥为了⽅便查看,直接输出到终端显⽰了,⼯作环境可以删除stdout的配置。并且添加了⽤户名和密码认证
3、启动,在终端可以查看到数据
- logstash -f /usr/local/logstash-7.5.0/config/switch.conf
复制代码
|