如何在 syslog 中禁用 logstash 错误日志记录
Posted
技术标签:
【中文标题】如何在 syslog 中禁用 logstash 错误日志记录【英文标题】:How to Disable logstash error logging in syslog 【发布时间】:2019-11-15 08:38:58 【问题描述】:所有 Logstash 错误记录在 /var/log/logstash/* 中,但 Logstash 的所有错误日志也记录在 /var/log/syslog 中。 有什么方法可以在 /var/log/syslog 中禁用 Logstash 的日志记录错误?
【问题讨论】:
【参考方案1】:我想你从 systemd 运行 logstash。由于未知原因,logstash 打印它在 stdout/stderr 上的日志,因此 journald 将控制台输出转发到 syslog。 像这样在 systemd 单元文件中重定向 stdout/err:
[Service]
Type=simple
Restart=always
WorkingDirectory=/data/logstash
ExecStart=/usr/bin/sudo -u logstashuser bash -c "/opt/logstash/bin/logstash --path.settings /opt/logstash/conf >/dev/null 2>/logs/logstash/logstash.error.log"
然后
systemctl daemon-reload
和
systemctl stop logstash.service
systemctl start logstash.service
【讨论】:
【参考方案2】:另一种解决方案是修改/etc/systemd/system/logstash.service
并将这两个选项更改如下
StandardOutput=null
StandardError=null
# cat /etc/systemd/system/logstash.service
[Unit]
Description=logstash
[Service]
Type=simple
User=logstash
Group=logstash
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
StandardOutput=null
StandardError=null
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384
# When stopping, how long to wait before giving up and sending SIGKILL?
# Keep in mind that SIGKILL on a process can cause data loss.
TimeoutStopSec=infinity
[Install]
WantedBy=multi-user.target
那当然
#systemctl daemon-reload
#systemctl restart logstash
【讨论】:
以上是关于如何在 syslog 中禁用 logstash 错误日志记录的主要内容,如果未能解决你的问题,请参考以下文章
如何从发送到 Logstash 的 syslog 日志中检索标签?