sudo yum install rsyslog
mysql
不幸的是,发行版一般提供至关旧的rsyslog版本。能够经过官网下载rpm或deb包来安装新版,或使用docker容器安装。sql
通常来讲,这句也不用执行,系统已经默认安装过了!docker
这是rsyslog下载连接 例如:安全
cd /etc/yum.repos.d/
wget http://rpms.adiscon.com/v8-stable/rsyslog.repo
yum install rsyslog
复制代码
rsyslogd -ver
bash
别说版本仍是很新的,v8: app
docker run -ti rsyslog/syslog_appliance_alpine
elasticsearch
一般在/etc/rsyslog.conftcp
配置语法有三种,见名知义的:模块化
basic
模式仍被建议使用对于大多数由简单语句组成的配置仍然建议使用该格式ui
# 把mail的info级别的日志写入到mail.log
mail.info /var/log/mail.log
# 把mail的error级别的日志使用tcp协议转发到远端server上
mail.err @@server.example.net
复制代码
advanced
格式优点:
对于上面的例子,好比你想在远端server目标掉线时不丢数据,使用以下如法:
mail.err action(type="omfwd" protocol="tcp" queue.type="linkedList" target="server")
高端大气上档次
module(load="module-name")
module(load="imtcp" maxSessions="500")
使用 &
连接出一个行动链条
*.error /var/log/errorlog
& @remote
复制代码
完整写法:
*.error {
action(type="omfile" file="/var/log/errorlog")
action(type="omfwd" target="remote" protocol="udp")
}
复制代码
这样易于拓展,模块化不易出错。 stop
阻止进一步的处理,符号为~
:
:msg, contains, "error" @remote
& ~
复制代码
高级写法为:
:msg, contains, "error" {
action(type="omfwd" target="remote" protocol="udp")
stop
}
复制代码
或:
if $msg contains "error" then {
action(type="omfwd" target="remote" protocol="udp")
stop
}
复制代码
语法为:选择器字段 (空格或TAB) 行动字段
选择器由facility
和priority
组成,用.
链接起来。这两者遵循syslog(3)描述。 可直接经过系统文件/usr/include/sys/syslog.h
查看相应值。
facility: auth, authpriv, cron, daemon, ftp, kern, lpr, mail, mark, news, security (same as auth), syslog, user, uucp and local0 through local7.
priority: debug, info, notice, warning, err, crit, alert, emerg.
warn, error and panic 已被弃用!
“*”表明所有,none
表明没有,“,”分隔多个设施,“;”分隔多规则
行动抽象了一个“日志文件”。
# Store critical stuff in critical
#
*.=crit;kern.none /var/adm/critical
#########
# Kernel messages are stored in the kernel file,
# critical messages and higher ones also go
# to another host and to the console
#
kern.* /var/adm/kernel
kern.crit @finlandia
kern.crit /dev/console
kern.info;kern.!err /var/adm/kernel-info
#########
# The tcp wrapper logs with mail.info, we display
# all the connections on tty12
#
mail.=info /dev/tty12
############
# Write all mail related logs to a file except for the info priority.
#
mail.*;mail.!=info /var/adm/mail
########
# Log all mail.info and news.info messages to info
#
mail,news.=info /var/adm/info
# Log info and notice messages to messages file
#
*.=info;*.=notice;\
mail.none /var/log/messages
复制代码