Rsyslog的远程传输日志(系统日志篇)

ip.10作为server
ip.11和ip.12作为client

编辑server端ip.10的/etc/rsyslog.conf文件

# 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 ###

汉字标注部分是修改过或者添加过的配置
在server端创建目录/data/log
mkdir -pv /data/log -v的作用,创建完目录后会有文字提示
然后重启服务
service rsyslog restart
编辑client1端ip.11的/etc/rsyslog.conf文件
*. * @@ip.10:514
client端的配置只增加了一行,指定日志发送的远程主机(ip)和端口。
然后重启服务
service rsyslog restart
编辑client1端ip.11的/etc/rsyslog.conf文件
*. * @@ip.10:514
client端的配置只增加了一行,指定日志发送的远程主机(ip)和端口。
然后重启服务
service rsyslog restart

进行验证
tailf /data/log/ip.11/nameOfFile
日志里面没有报错信息,证明配置正确,可以进行远程传输日志。

然后进行写日志测试
logger “The second mes from wyk12”
可以在这里收到日志信息

而且在/var/log/messages里面也可收到相同信息,这里的信息是包括11和12以及10本身的日志信息。

至此,系统日志的远程发送和接收日志信息就搞定了,接下来就该是非系统服务的应用了。
未完待续!

尚未解决的错误记录(之所以尚未解决是因为后来的配置没有用到这些东西,所以没有报错,但是随着以后学习的深入,这些问题肯定会遇到,到时候在慢慢解决吧。):
1、Apr 25 10:40:50 p11-wangyini rsyslogd-2066: could not load module ‘/lib64/rsyslog/imjournal.so’, dlopen: /lib64/rsyslog/imjournal.so: cannot open shared object file: No such file or directory
2、Apr 25 10:40:50 p11-wangyini rsyslogd: the last error occured in /etc/rsyslog.conf, line 3:”$ModLoad imjournal # provides access to the systemd journal”
3、Apr 25 10:40:50 p11-wangyini rsyslogd-3003: invalid or yet-unknown config file command - have you forgotten to load a module? [try http://www.rsyslog.com/e/3003 ]
4、Apr 25 10:45:07 p11-wangyini rsyslogd: the last error occured in /etc/rsyslog.conf, line 9:” OmitLocalLoggingon5Apr2510:45:07p11wangyinirsyslogd:thelasterroroccuredin/etc/rsyslog.conf,line10: IMJournalStateFile imjournal.state”
6、Apr 25 10:45:07p11-wangyini rsyslogd-2124: CONFIG ERROR: could not interpret master config file ‘/etc/rsyslog.conf’. [try http://www.rsyslog.com/e/2124 ]
7、Apr 25 10:51:28 p11-wangyini rsyslogd: imuxsock does not run because we could not aquire any socket

你可能感兴趣的:(日志分析)