1.server端:
编辑/etc/rsyslog.conf,
$ModLoad imtcp 引用tcp协议的模块
$InputTCPServerRun 514 设置tcp协议使用端口
$template Remote,"/data/log/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log" 设置远程存放日志的路径和文件格式
*.* ?Remote将格式应用到所有接受到的日志上
& ~
:fromhost-ip, !isequal, "127.0.0.1" ?Remote 过滤掉本机日志
server端创建目录:mkdir -pv /data/log -v
重启:service rsyslog restart
2.client端:
编辑/etc/rsyslog.conf
authpriv. * @@ip:514
重启:systemctl restart rsyslog.service
拓展:
一、系统日志
进程和操作系统内核需要能够为发生的事件记录日志 , 这些日志可用于系统审核和问题的故障排除 , 一般这些日志永久存储 /var/log 目录中
1.日志类型
auth ###pam产生的日志
authpriv ###ssh、ftp等登陆信息的验证信息
cron ###时间任务相关
kern ###内核
lpr ###打印
mail ###邮件
mark(syslog)-rsyslog ###服务内部消息,时间标识
news ###新闻组
user ###用户程序产生相关信息
uucp ###unix to unix copy(unix主机之间相关通信)
local 1~7 ###自定义日志设备
2.日志级别
debug ###有调式信息的,日志信息最多
info ###一般信息的日志,最常用
notice ###最具有重要性的普通条件的信息
warning ###警告级别
err ###错误级别,阻止某功能或模块不能正常工作的信息
crit ###严重级别,阻止整个系统或整个软件不能正常工作的信息
alert ###需要立刻修改的信息
emerg ###内核崩溃等严重信息
none ###什么都不记录
注:
3.日志存储文件
日志永久存储于 /var/log 目录中。各系统文件记录信息如下:
var/log/messages ###大多数系统日志信息记录在此处
/var/log/secure ###安全和身份认证相关的消息和错误的日志文件(系统登陆)
/var/log/maillog ###与邮件服务器相关的日志文件
/var/log/cron ###与定时任务相关的日志文件
/var/log/boot.log ###与系统启动有关的日志文件
4.
# rsyslog v5 configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
$ModLoad imudp 引用udp协议的模块
$UDPServerRun 514 设置udp协议使用端口
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
$ModLoad imtcp 引用tcp协议的模块
$InputTCPServerRun 514 设置tcp协议使用端口
$WorkDirectory /var/lib/rsyslog
$AllowedSender tcp, ip.0/24 此处设置的是允许发送的网段
#### GLOBAL DIRECTIVES ####
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template Remote,"/data/log/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log" 设置远程存放日志的路径和文件格式
:fromhost-ip, !isequal, "127.0.0.1" ?Remote 过滤掉本机日志(此处不是很懂)
# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
#### RULES ####
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$WorkDirectory /var/lib/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###