日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux日志系统-01:什么是rsyslog?

發布時間:2025/6/15 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux日志系统-01:什么是rsyslog? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄:

一、rsyslog是什么?

二、rsyslog的配置文件/etc/rsyslog.conf

三、詳解rsyslog的配置文件/etc/rsyslog.conf

------------------------------------------------------------------------------------------------------

一、rsyslog是什么?

在linux系統中日志可以分為:
(1)klogd:kernel,記錄內核相關的日志
(2)syslogd:service,記錄應用程序的日志
(3)rsyslog:是CentOS 6以后的系統使用的日志系統,rsyslog是用來管理、記錄日志的程序。rsyslog是一個C/S架構的服務,可監聽于某套接字,幫其它主機記錄日志信息。

二、rsyslog的配置文件/etc/rsyslog.conf

# rsyslog 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 ##### The imjournal module bellow is now used as a message source instead of imuxsock. $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) $ModLoad imjournal # provides access to the systemd journal #$ModLoad imklog # reads kernel messages (the same are read from journald) #$ModLoad immark # provides --MARK-- message capability# Provides UDP syslog reception #$ModLoad imudp #$UDPServerRun 514# Provides TCP syslog reception #$ModLoad imtcp #$InputTCPServerRun 514#### GLOBAL DIRECTIVES ##### Where to place auxiliary files $WorkDirectory /var/lib/rsyslog# 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/ $IncludeConfig /etc/rsyslog.d/*.conf# Turn off message reception via local log socket; # local messages are retrieved through imjournal now. $OmitLocalLogging on# File to store the position in the journal $IMJournalStateFile imjournal.state#### 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. #$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 ###

三、詳解rsyslog的配置文件/etc/rsyslog.conf

(1)日志級別

1)debug:調試級別(程序調試信息)

2)info:通知消息(程序的正常輸出)

3)notice:注意級別(程序可能有錯誤)

4)warning:警告級別(警告錯誤)

5)error:錯誤級別

6)crit:嚴重錯誤級別

7)alter:發出嚴重報警級別

8)emerg:系統級別故障

PS:記錄日志的時候會把本級別以及高于本級別的日志信息都會記錄下來。

例子1:

mail.info info和info以上級別mail.!info 除了info以外的全部級別mail.=info 僅僅記錄info級別的日志mail.* 記錄mail設施全部級別的日志*.info 記錄所以設施的info及其以上級別的日志mail,auth.info 記錄mail和auth兩個設施的info及其以上級別的日志mail.none 不記錄任何級別的日志

例子2:

將mail的全部日志記錄到/var/log/mail.log

mail.* /var/log/mail.log

(2)日志設施

日志設施(facility)就是對日志信息分類,將不同類別的日志記錄到不同的位置,比如系統安全級別的日志記錄和用戶認證的日志在/var/log/secure,常見日志類別:
?

1)auth:用戶認證相關的日志2)authpriv:記錄授權相關的日志3)mail:郵件相關的日志4)cron:計劃任務的日志5)daemon:守護進程相關的日志6)user:系統系統相關的日志7)kernel:內核相關的日志8)rsyslog:syslog自己的日志9)local0~local7:8個用戶自定義設施PS:定義日志級別的時候可以使用通配符,比如,*表示全部級別;,表示多個級別(debug,info,notice);!表示某個級別除外;=表示僅僅某個級別的日志

(3)日志的保存位置

1)保存到本地

情況1:如果在messages文件前加一個”-“表示異步寫入。異步寫入就是把日志先寫到內存中,如果內存滿了再將內存的數據寫入磁盤。例如:

# Log all the mail messages in one place.mail.* -/var/log/maillog

情況2:none的使用

下面rsyslog的配置文件/etc/rsyslog.conf中使用了none,并用分號隔開,下面規則含義是把所有info級別的日志寫入 /var/log/messages,但是不寫入mail、authpriv、cron的日志。

# 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

2)保存到mysql數據庫其格式為:

facility.priority :ommysql:DBHOST,DB,DBUSER,DBUSERPASS

3)發送給指定的用戶:如果將日志發送給所有用戶用*表示,例如:

rybody gets emergency messages*.emerg :omusrmsg:*

4)保存到日志服務器

#### RULES ####*.* @日志服務器地址

PS:日志配置格式--》設施.級別???? 日志位置

(4)日志默認保存格式

日志默認保存格式可參考系統日志信息/var/log/messages

時間 pid 用戶 事件May 9 10:21:14 192 journal: horizontal-workspaces@gnome-shell-extensions.gcampax.github.com unknown type 3May 9 10:21:14 192 journal: alternate-tab@gnome-shell-extensions.gcampax.github.com unknown type 3May 9 10:21:15 192 gnome-shell: GNOME Shell started at Sun May 09 2021 10:20:11 GMT+0800 (CST)May 9 10:21:18 192 journal: Only 5 apps for popular list, hiding

?

總結

以上是生活随笔為你收集整理的Linux日志系统-01:什么是rsyslog?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。