在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Linux/ UNIX 系統(tǒng)日志
UNIX 文件權(quán)限/訪問模式
UNIX 系統(tǒng)性能
UNIX 管道和過濾器
UNIX 進(jìn)程管理
Shell 內(nèi)置數(shù)學(xué)函數(shù)
UNIX 環(huán)境
UNIX 文件管理
Unix
UNIX 網(wǎng)絡(luò)實(shí)用工具
UNIX 系統(tǒng)日志
UNIX 目錄管理
vi編輯器教程
Unix 基本工具(打印,電子郵件)
UNIX 用戶管理
UNIX 信號(hào)和陷阱
Unix 正則表達(dá)式SED
Unix 文件系統(tǒng)基礎(chǔ)
Unix是什么?
Unix 有用命令

UNIX 系統(tǒng)日志

Unix 系統(tǒng)有一個(gè)非常靈活和強(qiáng)大的日志系統(tǒng),它可以讓您記錄幾乎任何你能想象和操作日志,以獲取所需要的信息。

許多版本 UNIX 提供了一個(gè)通用的日志工具,稱為:syslog。個(gè)別程序需要有記錄的信息發(fā)送到 syslog 信息。

Unix的系統(tǒng)日志主機(jī)配置,統(tǒng)一的系統(tǒng)日志記錄工具。該系統(tǒng)采用一個(gè)集中的系統(tǒng)運(yùn)行程序  /etc/syslogd 或 /etc/syslog 日志記錄進(jìn)程。.

系統(tǒng)日志的操作是相當(dāng)簡單的。程序日志條目發(fā)送到syslogd,參考的配置文件在/etc/syslogd.conf 或 /etc/syslog,找到一個(gè)匹配時(shí),所需的日志文件寫入日志消息。

有四個(gè)基本的 syslog 條款,你應(yīng)該明白:

Term 描述
Facility The identifier used to describe the application or process that submitted the log message. Examples are mail, kernel, and ftp.
Priority An indicator of the importance of the message. Levels are defined within syslog as guidelines, from debugging information to critical events.
Selector A combination of one or more facilities and levels. When an incoming event matches a selector, an action is performed.
Action What happens to an incoming message that matches a selector. Actions can write the message to a log file, echo the message to a console or other device, write the message to a logged in user, or send the message along to another syslog server.

系統(tǒng)日志設(shè)備:

這里是可用的設(shè)備選擇。并非所有的設(shè)施都存在于所有版本的UNIX。

設(shè)備 描述
auth Activity related to requesting name and password (getty, su, login)
authpriv Same as auth but logged to a file that can only be read by selected users
console Used to capture messages that would generally be directed to the system console
cron Messages from the cron system scheduler
daemon System daemon catch-all
ftp Messages relating to the ftp daemon
kern Kernel messages
local0.local7 Local facilities defined per site
lpr Messages from the line printing system
mail Messages relating to the mail system
mark Pseudo event used to generate timestamps in log files
news Messages relating to network news protocol (nntp)
ntp Messages relating to network time protocol
user Regular user processes
uucp UUCP subsystem

Syslog優(yōu)先級(jí):

該系統(tǒng)記錄的優(yōu)先級(jí)總結(jié)在下面的表中:

優(yōu)先級(jí) 描述
emerg Emergency condition, such as an imminent system crash, usually broadcast to all users
alert Condition that should be corrected immediately, such as a corrupted system database
crit Critical condition, such as a hardware error
err Ordinary error
warning Warning
notice Condition that is not an error, but possibly should be handled in a special way
info Informational message
debug Messages that are used when debugging programs
none Pseudo level used to specify not to log messages.

設(shè)備和級(jí)別的組合,讓你辨識(shí)記錄和信息。

由于每個(gè)程序盡職地發(fā)送它的消息的系統(tǒng)記錄器,記錄器作出決定什么來跟蹤和丟棄的基礎(chǔ)上在選擇器中定義的級(jí)別。

當(dāng)你指定一個(gè)級(jí)別,系統(tǒng)將跟蹤所有在這一水平較高。

/etc/syslog.conf 文件:

/etc/syslog.conf 文件控制,記錄消息的位置。一個(gè)典型的 syslog.conf  文件可能看起來像這樣:

*.err;kern.debug;auth.notice /dev/console
daemon,auth.notice           /var/log/messages
lpr.info                     /var/log/lpr.log
mail.*                       /var/log/mail.log
ftp.*                        /var/log/ftp.log
auth.*                       @prep.ai.mit.edu
auth.*                       root,amrood
netinfo.err                  /var/log/netinfo.log
install.*                    /var/log/install.log
*.emerg                      *
*.alert                      |program_name
mark.*                       /dev/console

文件的每一行包含兩個(gè)部分:

  • 消息選擇器,指定哪種要記錄的消息。例如,所有的錯(cuò)誤消息或內(nèi)核的所有調(diào)試信息。

  • 應(yīng)該做些什么消息,說一個(gè)動(dòng)作域。例如,把它放在一個(gè)文件或消息發(fā)送到用戶的終端上。

以下是對(duì)上述配置的顯著點(diǎn):

  • 消息選擇器有兩個(gè)部分組成:設(shè)備和優(yōu)先級(jí)。例如,kern.debug的選擇由內(nèi)核(設(shè)施)產(chǎn)生的所有調(diào)試消息(優(yōu)先級(jí))。

  • 消息選擇kern.debug的選擇所有優(yōu)先級(jí)大于調(diào)試。

  • 設(shè)施或優(yōu)先的地方中的星號(hào)表示“所有”。例如,*. 調(diào)試是指所有調(diào)試信息,而  kern.*  指由內(nèi)核生成的所有消息。

  • 您還可以使用逗號(hào)指定多個(gè)設(shè)備。兩個(gè)或多個(gè)選擇可以組合在一起使用分號(hào)。

日志操作:

action字段指定的五個(gè)動(dòng)作之一:

  1. 日志消息發(fā)送到一個(gè)文件或設(shè)備。例如,/var/log/lpr.log 或 /dev/console.。

  2. 發(fā)送一條信息給用戶。您可以指定多個(gè)用戶名(如根,amrood)用逗號(hào)將它們分隔開。

  3. 發(fā)送一條信息給所有用戶。在這種情況下,“動(dòng)作”字段中包含一個(gè)星號(hào)(例如,*)。

  4. 管道消息的程序。在這種情況下,程序被指定后,UNIX管道符號(hào)(|)。

  5. 將消息發(fā)送到另一臺(tái)主機(jī)上的系統(tǒng)日志。在這種情況下,行動(dòng)領(lǐng)域包括主機(jī)名,前面有一個(gè)at符號(hào)(例如,@ yiibai.com)

logger命令:

UNIX 提供了命令logger ,這是一個(gè)非常有用的命令處理系統(tǒng)日志。 logger 命令記錄消息發(fā)送到syslogd守護(hù)進(jìn)程,從而引發(fā)系統(tǒng)日志。

這意味著我們可以在命令行檢查隨時(shí)syslogd 守護(hù)進(jìn)程,它的配置。 logger 命令提供系統(tǒng)日志文件,在命令行添加一行條目的方法。

該命令的格式是:

logger [-i] [-f file] [-p priority] [-t tag] [message]...

下面是詳細(xì)的參數(shù):

選項(xiàng) 描述
-f filename Use the contents of file filename as the message to log.
-i Log the process ID of the logger process with each line.
-p priority Enter the message with the specified priority (specified selector entry); the message priority can be specified numerically, or as a facility.priority pair. The default priority is user.notice.
-t tag Mark each line added to the log with the specified tag.
message The string arguments whose contents are concatenated together in the specified order, separated by the space

您可以使用聯(lián)機(jī)幫助幫助檢查完成此命令的語法。

日志切換:

日志文件的增長傾向非???,消耗大量的磁盤空間。要啟用日志切換,大多數(shù)發(fā)行版使用 newsyslog 或 logrotate 工具。

這些工具應(yīng)該被稱為使用cron守護(hù)程序在頻繁的時(shí)間間隔。檢查newsyslog 或 logrotate的更多詳細(xì)信息的手冊(cè)頁。

重要的日志位置

所有的系統(tǒng)應(yīng)用程序創(chuàng)建日志文件在 /var/log 和其子目錄。這里有幾個(gè)重要的應(yīng)用程序及其日志目錄:

應(yīng)用程序 目錄
httpd /var/log/httpd
samba /var/log/samba
cron /var/log/
mail /var/log/
mysql /var/log/


上一篇:UNIX 用戶管理下一篇:Unix