赞
踩
sudo apt-get install rsyslog
sudo service rsyslog status
sudo vim /etc/rsyslog.conf
# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514")
# provides TCP syslog reception
module(load="imtcp")
input(type="imtcp" port="514")
如果你想限制访问特定子网,IP或域,请添加如下:
$AllowedSender TCP, 127.0.0.1, 192.168.10.0/24, *.example.com
可以在输入input(type=“imtcp” port=“514”)行后添加上面的行,请记住用正确的值替换给定的值。
让我们创建一个模板,指示rsyslog服务器如何存储传入的syslog消息,在GLOBAL DIRECTIVES部分之前添加模板
$template RemoteLogs,"/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log"
*.* ?RemoteLogs
& stop
收到的日志将使用上面的模板进行解析并存储在目录/var/log/remote中,文件命名遵循约定:%HOSTNAME% and %PROGRAMNAME%变量,即:客户端主机名和生成日志消息的客户端工具。
& stop指示rsyslog守护程序仅将日志消息存储到指定的文件(也有人使用& ~)。
可以使用的其它变量包括:
%syslogseverity%, %syslogfacility%, %timegenerated%, %HOSTNAME%, %syslogtag%, %msg%, %FROMHOST-IP%, %PRI%, %MSGID%, %APP-NAME%, %TIMESTAMP%, %
y
e
a
r
year%, %
yearmonth%, %$day%
# /etc/rsyslog.conf Configuration file for rsyslog. # # For more information see # /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html # # Default logging rules can be found in /etc/rsyslog.d/50-default.conf ################# #### MODULES #### ################# module(load="imuxsock") # provides support for local system logging #module(load="immark") # provides --MARK-- message capability # provides UDP syslog reception module(load="imudp") input(type="imudp" port="514") # provides TCP syslog reception #module(load="imtcp") #input(type="imtcp" port="514") # provides kernel logging support and enable non-kernel klog messages module(load="imklog" permitnonkernelfacility="on") $template RemoteLogs,"/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log" *.* ?RemoteLogs & stop ########################### #### GLOBAL DIRECTIVES #### ########################### # # Use traditional timestamp format. # To enable high precision timestamps, comment out the following line. # $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # Filter duplicated messages $RepeatedMsgReduction on # # Set the default permissions for all log files. # $FileOwner syslog $FileGroup adm $FileCreateMode 0640 $DirCreateMode 0755 $Umask 0022 $PrivDropToUser syslog $PrivDropToGroup syslog # # Where to place spool and state files # $WorkDirectory /var/spool/rsyslog # # Include all config files in /etc/rsyslog.d/ # $IncludeConfig /etc/rsyslog.d/*.conf
sudo systemtcl restart rsyslog
ss -tunelp | grep 514
nc -vuz 192.168.3.99 514
如果你的ufw防火墙服务正在运行,请允许rsyslog防火墙端口:
sudo ufw allow 514/tcp
sudo ufw allow 514/udp
sudo vim /etc/rsyslog.conf
$PreserveFQDN on
*.* @ip-address-of-rsysog-server:514
还可以使用FQDN而不是服务器IP地址:
*.* @fqdn-of-rsysog-server:514
以上行将允许通过UDP发送日志,因为tcp使用@@而不是单个@:
*.* @@ip-address-of-rsysog-server:514
或者:
*.* @@fqdn-of-rsysog-server:514
$ActionQueueFileName queue
$ActionQueueMaxDiskSpace 1g
$ActionQueueSaveOnShutdown on
$ActionQueueType LinkedList
$ActionResumeRetryCount -1
sudo service rsyslog restart
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。