centos rsyslog mysql_centos7+rsyslog+loganalyzer+mysql 搭建rsyslog日志服务器

一、简介

在centos7系统中,默认的日志系统是rsyslog,它是一类unix系统上使用的开源工具,用于在ip网络中转发日志信息,rsyslog采用模块化设计,是syslog的替代品。

1、rsyslog特点

实现了基本的syslog协议

直接兼容syslogd的syslog.conf配置文件

在同一台机器上支持多个rsyslogd进程,支持多线程

丰富的过滤功能,可以实现过滤日志信息中的任何部分,可将消息过滤后在转发

灵活的配置选项,配置文件中可以写简单的逻辑判断,自定义输出格式等

增加了重要的功能,如使用tcp进行消息传输,支持UDP,TCP,SSL,TLS,RELP

有现成的前端web展示程序

可以使用MySQL,PGSQL,Oralce实现日志存储

默认安装的rsyslog软件包提供的守护进程是rsyslog,它是一项系统的基础服务,应该设置开机运行

2、核心组成

facility(设施,收集管道),priority(级别),target(路径)

facility:从功能或程序上对日志进行分类

auth:认证相关

authpriv:认证权限相关

cron:计划任务相关

daemon:守护进程相关

kern:内核相关

lpr:打印相关

mail:邮件相关

news:新闻相关

security:安全相关

syslog:自身日志

user:用户相关

uucp:unix to unix copy,早期系统文件共享服务

local0-local7:用户自定义facility

priority:日志级别也可以叫loglevel

debug:调试

info:除去debug外的所有信息

notice:注意

warn,warning:警告

err,error:错误信息

crit:蓝色警报

alert:橙色警报

emerg,panic:红色警报

指定级别的方式:

*:所有级别

none:没有级别

priority:比此级别高的(包含)所有级别的日志信息都会记录

=priority:仅记录指定级别

target:路径

文件路径:将日志记录于指定的文件中;在文件路径之前使用”-“,表示异步写入;

用户:将日志信息通知给文件

*:所有用户

日志服务器:@SERVER

管道:| COMMAND

3、配置文件明细

vim /etc/rsyslog.conf

48304ba5e6f9fe08f3fa1abda7d326ab.png

1 # rsyslog configuration file

2

3 # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html

4 # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

5

6 #### MODULES ####                  #模块部分 7

8 # The imjournal module bellow is now used as a message source instead of imuxsock.

9 $ModLoad imuxsock #支持本地系统 provides support for local system logging (e.g. via logger command)

10 $ModLoad imjournal # provides access to the systemd journal

11 #$ModLoad imklog # reads kernel messages (the same are read from journald)

12 #$ModLoad immark # provides --MARK-- message capability

13

14 # Provides UDP syslog reception

15 #$ModLoad imudp

16 #$UDPServerRun 514

17

18 # Provides TCP syslog reception

19 #$ModLoad imtcp

20 #$InputTCPServerRun 514

21

22

23 #### GLOBAL DIRECTIVES ####             #全局指定 24

25 # Where to place auxiliary files

26 $WorkDirectory /var/lib/rsyslog

27

28 # Use default timestamp format

29 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

30

31 # File syncing capability is disabled by default. This feature is usually not required,

32 # not useful and an extreme performance hit

33 #$ActionFileEnableSync on

34

35 # Include all config files in /etc/rsyslog.d/

36 $IncludeConfig /etc/rsyslog.d/*.conf

37

38 # Turn off message reception via local log socket;

39 # local messages are retrieved through imjournal now.

40 $OmitLocalLogging on

41

42 # File to store the position in the journal

43 $IMJournalStateFile imjournal.state

44

45

46 #### RULES ####                #规则部分 47

48 # Log all kernel messages to the console.

49 # Logging much else clutters up the screen.

50 # 本地物理终端,比如启动引导的时候,打印在屏幕上的日志,可以用dmesg看

51 #kern.* /dev/console

52

53 # Log anything (except mail) of level info or higher.

54 # Don't log private authentication messages!

55 #可以使用分号隔开,”*.info“所有的info,排除mail ,authpriv,cron

56 *.info;mail.none;authpriv.none;cron.none /var/log/messages

57

58 #如果想给发给日志服务器只需要指定服务器

59 #*.info;mail.none;authpriv.none;cron.none @192.168.216.53

60

61

62

63 # The authpriv file has restricted access.

64 #authpriv.* ,authpriv的任何级别

65 authpriv.* /var/log/secure

66

67 # Log all the mail messages in one place.

68 #任意的mail,-/var/log/maillog 减号是异步的意思,因为不是特别关键,所以异步,节省效率

69 mail.* -/var/log/maillog

70

71

72 # Log cron stuff

73 cron.* /var/log/cron

74

75 # Everybody gets emergency messages

76 #所有登陆到系统上的用户的信息

77 *.emerg :omusrmsg:*

78

79 # Save news errors of level crit and higher in a special file.

80 #”,“代表uucp和news都使用一个级别crit警告

81 uucp,news.crit /var/log/spooler

82

83 # Save boot messages also to boot.log

84 #自定义日志,比如说添加一个local2,对应修改sshd配置文件

85 local7.* /var/log/boot.log

86 #local2.* /var/log/sshd.log

87 # ### begin forwarding rule ###

88 # The statement between the begin ... end define a SINGLE forwarding

89 # rule. They belong together, do NOT split them. If you create multiple

90 # forwarding rules, du

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值