centos

CentOS Syslog与ELK Stack集成实践

小樊
34
2025-11-25 20:45:08
栏目: 智能运维

架构与方案选型

服务端 Logstash 配置

input {
  udp {
    port => 514
    type => "system-syslog"
    codec => plain { charset => "UTF-8" }
  }
}
filter {
  # 解析常见内核/系统日志
  grok {
    match => { "message" => "%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:hostname} %{DATA:program}(?:\[%{POSINT:pid}\])?: %{GREEDYDATA:message}" }
    overwrite => ["message"]
  }
  date {
    match => ["timestamp", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601"]
    target => "@timestamp"
  }
  # 可选:按设施/优先级丰富字段
  mutate {
    add_field => { "facility" => "%{syslog_facility}" }
    add_field => { "severity" => "%{syslog_severity}" }
  }
}
output {
  elasticsearch {
    hosts => ["http://127.0.0.1:9200"]
    index => "syslog-%{+YYYY.MM.dd}"
    user => "elastic"
    password => "YourStrongPassword"
  }
  stdout { codec => rubydebug }  # 调试用
}
input {
  syslog { port => 514 type => "system-syslog" }
}

客户端 rsyslog 配置

# /etc/rsyslog.conf 或 /etc/rsyslog.d/50-remote.conf
*.*     @192.0.2.10:514
*.*     @@192.0.2.10:1514
systemctl restart rsyslog
firewall-cmd --permanent --add-port=514/udp
firewall-cmd --permanent --add-port=1514/tcp
firewall-cmd --reload
local6.info    @@192.0.2.10:1514

Kibana 可视化与索引管理

生产优化与安全加固

0
看了该问题的人还看了