上一篇我们把日志服务器搭建和配置讲解完成,这节讲rsyslog客户端配置。因为系统默认已经安装rsyslo就不在复数了。只讲配置。
?
1
2
| # rpm -qa | grep rsyslog //#查看系统默认已经安装软件包
# rpm -ql rsyslog ///显示rsyslog相关信息
|
注:教程配置文件下载。
在rsyslog.conf 中配置,在文件末尾添加如下,全局远程提交路径:
如果客户端所有日志都提交到一个服务器,可以把IP定义在全局变量里,反之则在相关脚本中定义。
@代表UDF方式传输,@@代表是TCP方式传输。
*.* 左边的*是设备,右边*是类型(正常、一般、紧急等),这个不要理解成系统里的文件名和后缀。
1
| vi /etc/rsyslog.conf //编辑rsyslog全局文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| # 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)#Unix套接字,包括系统日志socket
$ModLoad imklog # provides kernel logging support(previously done by rklogd)
#module(load"immark") # provides --MARK-- message capability
# Provides UDP syslog reception
# UDP传输,只在rsyslog作服务器时候使用
#$ModLoad imudp
#$UDPServerRun 514
#Provides TCP syslog reception
# TCP传输,只在rsyslog作服务器时候使用
#$ModLoad imtcp
# tcp接收信息的端口
#$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# 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/
#模块化配置文件存放,默认加载全部.conf后缀的文件
$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 :omusrmsg:*
# 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 ###
#日志如非本地存储,需指定远程收集日志服务器IP:Port
*.* @@192.168.1.251:514 //表示所有类型的日志都提交
|
重启日志服务,修改完配置文件一定要重启服务才能生效
1
| # service rsyslog restart
|
测试:
一、查看rsyslog配置是否正确
1
| #rsyslogd -N1 -f rsyslog.conf
|
显示配置成功
二、查看看能否产生日志
打开两个终端ssh窗口,可以通过观察系统中的Rsyslog日志,确定是否正常工作。
1
| #cat /var/log/messages |grep rsyslog
|
或
1
| #tail -f /var/log/messages |grep rsyslog
|
客户端手动产生日志
1
| #logger -p local5.info test123
|
rsyslog配置文件说明: 在其它的节点的 Linux 上配置syslog日志功能,收集系统各方面日志主要包括以下日志内容
格式::
日志设备(类型).(连接符号)日志级别 日志处理方式(action)
日志设备(可以理解为日志类型):
———————————————————————-
auth –pam产生的日志
authpriv –ssh,ftp等登录信息的验证信息
cron –时间任务相关
kern –内核
lpr –打印
mail –邮件
mark(syslog)–rsyslog服务内部的信息,时间标识
news –新闻组
user –用户程序产生的相关信息
uucp –unix to unix copy, unix主机之间相关的通讯
local 1~7 –自定义的日志设备
日志级别:
———————————————————————-
debug –有调式信息的,日志信息最多
info –一般信息的日志,最常用
notice –最具有重要性的普通条件的信息
warning –警告级别
err –错误级别,阻止某个功能或者模块不能正常工作的信息
crit –严重级别,阻止整个系统或者整个软件不能正常工作的信息
alert –需要立刻修改的信息
emerg –内核崩溃等严重信息
none –什么都不记录
从上到下,级别从低到高,记录的信息越来越少
详细的可以查看手册: man 3 syslog
连接符号
———————————————————————-
.xxx: 表示大于等于xxx级别的信息
.=xxx:表示等于xxx级别的信息
.!xxx:表示在xxx之外的等级的信息
Actions
———————————————————————-
rsyslog配置文件.zip
(1.65 KB, 下载次数: 2)
|