十、syslog日志與loganalyzer日志管理-創(chuàng)新互聯(lián)

10.1、rsyslog簡介

目前創(chuàng)新互聯(lián)建站已為超過千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、河西網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

 syslog是一個(gè)歷史悠久的日志系統(tǒng)。幾乎所有的UNIX和Linux操作系統(tǒng)都采用syslog進(jìn)行系統(tǒng)日志的管理和配置。Linux系統(tǒng)內(nèi)核和許多程序會(huì)產(chǎn)生各種錯(cuò)誤信息、警告信息和其他的提示信息。syslog可以根據(jù)信息的來源以及信息的重要程度將信息保存到不同的日志文件中。在默認(rèn)的syslog配置下,日志文件通常都保存在/var/log目錄下,在Centos6中,syslog的守護(hù)進(jìn)程為rsyslog,系統(tǒng)啟動(dòng)時(shí),默認(rèn)會(huì)自動(dòng)運(yùn)行rsyslog守護(hù)進(jìn)程。

 在syslog中定義了一些日志文件,這些日志文件的位置以及說明:

/var/log/dmesg   記錄init進(jìn)程啟動(dòng)之前的信息

/sbin/init     進(jìn)程啟動(dòng)后日志需要滾動(dòng)(日志切割)

/var/log/maillog 郵件系統(tǒng)產(chǎn)生的日志信息

/var/log/secure  安全系統(tǒng)產(chǎn)生的日志信息

/var/log/messages系統(tǒng)標(biāo)準(zhǔn)錯(cuò)誤日志信息;非內(nèi)核產(chǎn)生引導(dǎo)信息;各子系統(tǒng)產(chǎn)生的信息

10.2、rsyslog配置

 syslog的配置文件為/etc/rsyslog.conf,在該文件中指定了rsyslog記錄日志的信息來源、信息類型以及保存位置。

[root@mylinux log]# cat /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 # Provides TCP syslog reception #$ModLoad imtcp #$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/ $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 ###

  該文件以'#'為注釋符,其中每一行的語法格式為:

[消息來源.消息級(jí)別]    [動(dòng)作]

 其中,[消息來源.消息級(jí)別]和[動(dòng)作]之間以Tab鍵進(jìn)行分隔,同一行rsyslog配置中允許出現(xiàn)多個(gè)[消息來源.消息級(jí)別],必須以';'進(jìn)行分隔。

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

rsyslog(facility)消息來源及說明:

auth:  認(rèn)證相關(guān)的      authpriv:  權(quán)限,授權(quán)相關(guān)的

cron:  任務(wù)計(jì)劃相關(guān)的   daemon:   守護(hù)進(jìn)程相關(guān)的

kern:  內(nèi)核相關(guān)的       lpr:     打印相關(guān)的

mail:  郵件相關(guān)的      mark:    標(biāo)記相關(guān)的

news:  新聞相關(guān)的      security:  安全相關(guān)的,與auth 類似

syslog:syslog自己的       user:    用戶相關(guān)的

*       表示所有的facility uucp:    unix to unix cp 相關(guān)的

local0-local7:本地用戶

rsyslog(log level)消息級(jí)別及說明:

debug:     程序或系統(tǒng)的調(diào)試信息       info:    一般信息

notice:    不影響正常功能,需要注意的消息  err/error: 錯(cuò)誤信息

crit:     比較嚴(yán)重的            alert:   必須馬上處理的

emerg/panic: 會(huì)導(dǎo)致系統(tǒng)不可用的        *:      表示所有的日志級(jí)別

none:     跟*相反,表示啥也沒有

warning/warn:可能影響系統(tǒng)功能,需要提醒用戶的重要事件

 rsyslog消息級(jí)別是向上匹配的,即如果指定了一個(gè)消息級(jí)別,那么指定級(jí)別及比該指定級(jí)別更高級(jí)的消息都會(huì)包含進(jìn)去。例如,warning表示大于或等于warning級(jí)別的消息都會(huì)被處理,包括emerg、alert、crit、err和warning。消息級(jí)別越低,消息的數(shù)量就會(huì)越大,如果只想匹配某個(gè)確定等級(jí)的消息,而不希望更高級(jí)的消息,可以使用等號(hào)進(jìn)行指定。

cron.=notice                                                  /var/log/cron

rsyslog(action)處理動(dòng)作:

系統(tǒng)上的絕對(duì)路徑 :將消息保存到普通文件       如: /var/log/xxx

|         :通過管道送給其他的命令處理

終端       :把消息發(fā)送到本地主機(jī)終端     如:/dev/console

@HOST       :把消息轉(zhuǎn)發(fā)到另一臺(tái)syslog服務(wù)器上進(jìn)行處理   如: @10.0.0.1

用戶       :把消息發(fā)送到指定用戶,用戶名以','進(jìn)行分隔   如: root

*         :登錄到系統(tǒng)上的所有用戶,一般emerg級(jí)別日志這樣定義

配置實(shí)例:

 通過logger命令可以模擬產(chǎn)生各類的syslog消息,從而測試配置是否正確。

 用法:logger [-isd] [-f file] [-p pri] [-t tag] [-u socket][message ...]

[root@mylinux log]# vim /etc/rsyslog.conf  #syslog測試                                       #修改配置文件,添加這兩行 kern.info   /var/log/kern_test.log [root@mylinux log]# /etc/init.d/rsyslog restart   #重啟進(jìn)程 關(guān)閉系統(tǒng)日志記錄器:                                       [確定] 啟動(dòng)系統(tǒng)日志記錄器:                                       [確定] [root@mylinux log]# logger kern.info 'test info'  #模擬內(nèi)核信息 [root@mylinux log]# cat /var/log/kern_test.log    #產(chǎn)生的日至消息 May  3 19:11:30 localhost kernel: imklog 5.8.10, log source = /proc/kmsg started.

10.3、其它日志

 除了rsyslog以外,Linux系統(tǒng)還提供了大量其他的日志文件,這些日志文件中記錄了非常重要的消息 。常用的主要有dmesg、wtmp、btmp和.bash_history等。

  • dmesg日志:記錄內(nèi)核日志信息

 日志文件/var/log/dmesg中記錄了系統(tǒng)啟動(dòng)過程中內(nèi)核日志信息,包括系統(tǒng)的設(shè)備信息,以及在啟動(dòng)和操作過程中系統(tǒng)記錄的任何錯(cuò)誤和問題的信息。

[root@mylinux log]# less /var/log/dmesg Initializing cgroup subsys cpuset Initializing cgroup subsys cpu Linux version 2.6.32-642.11.1.el6.x86_64 (mockbuild@c1bm.rdu2.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Fri Nov 18 19:25:05 UTC 2016 Command line: ro root=/dev/vda1 console=ttyS0 console=tty0 printk.time=1 panic=5 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=zh_CN.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_NO_LVM crashkernel=auto   rd_NO_DM KERNEL supported cpus:   Intel GenuineIntel   AMD AuthenticAMD   Centaur CentaurHauls BIOS-provided physical RAM map:  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
  • 用戶登錄日志

 /var/log/wtmp和/var/log/btmp是Linux系統(tǒng)上用戶保存用戶登錄信息的日志文件。其中,wtmp用于保存用戶成功登錄的記錄,btmp用于保存用戶登錄失敗的日志記錄。這兩個(gè)文件都是二進(jìn)制的,無法直接使用文本編輯工具打開,必須通過last和lastb命令進(jìn)行查看。

[root@mylinux log]# last | less   #查看登錄成功的信息 root     pts/0        192.168.1.120    Wed May  3 18:30   still logged in    root     pts/0        192.168.1.120    Tue May  2 14:47 - 15:40  (00:53)     root     pts/0        192.168.1.120    Fri Apr 28 12:00 - 22:01  (10:00)     root     pts/0        192.168.1.120    Mon Apr 24 08:54 - 17:18  (08:23)     root     pts/0        192.168.1.120    Sun Apr 23 18:48 - 22:00  (03:11)     root     pts/0        192.168.1.120    Sun Apr 23 16:28 - 16:32  (00:03)     root     pts/0        192.168.1.120    Sat Apr 22 12:51 - 13:39  (00:47)     root     pts/0        192.168.1.120    Sat Apr 22 12:03 - 12:51  (00:47)     root     pts/0        192.168.1.120    Fri Apr 21 12:51 - 13:16  (00:24) ... [root@mylinux log]# lastb         #查看登錄失敗的信息 support  ssh:notty    171.212.140.107  Wed May  3 18:27 - 18:27  (00:00)     admin    ssh:notty    78.106.24.79     Wed May  3 13:18 - 13:18  (00:00)     liuyr    ssh:notty    61.147.166.76    Wed May  3 12:53 - 12:53  (00:00)     admin    ssh:notty    124.131.79.205   Wed May  3 12:41 - 12:41  (00:00)     admin    ssh:notty    112.120.73.220   Wed May  3 11:37 - 11:37  (00:00)     support  ssh:notty    2.177.238.135    Wed May  3 10:59 - 10:59  (00:00)     ubnt     ssh:notty    109.161.75.102   Wed May  3 09:33 - 09:33  (00:00)     admin    ssh:notty    181.25.207.227   Wed May  3 09:14 - 09:14  (00:00)     admin    ssh:notty    181.26.181.184   Wed May  3 06:54 - 06:54  (00:00)     admin    ssh:notty    181.26.181.184   Wed May  3 06:54 - 06:54  (00:00)     admin    ssh:notty    167.160.149.47   Wed May  3 05:27 - 05:27  (00:00)     admin    ssh:notty    179.63.255.251   Wed May  3 05:07 - 05:07  (00:00)   ...
  • 用戶操作記錄

 默認(rèn)情況下,在每個(gè)用戶的主目錄下都會(huì)有一個(gè).bash_history文件,該文件中保存了該用戶輸入的所有命令記錄,管理員可以通過該文件查看某個(gè)用戶做過什么操作。

[root@mylinux log]# cat /root/.bash_history  #1493001194 htop #1493352081 pip3 install Numpy #1493707660 LS #1493707661 ls #1493707664 ls #1493707668 cd /selinux/ #1493707669 ls #1493707869 cat /etc/selinux/config  #1493708491 ls #1493708497 ...

10.4、loganalyzer日志分析工具

 LogAnalyzer 是一款syslog日志和其他網(wǎng)絡(luò)事件數(shù)據(jù)的Web前端。它提供了對(duì)日志的簡單瀏覽、搜索、基本分析和一些圖表報(bào)告的功能。數(shù)據(jù)可以從數(shù)據(jù)庫或一般的syslog文本文件中獲取,所以LogAnalyzer不需要改變現(xiàn)有的記錄架構(gòu)?;诋?dāng)前的日志數(shù)據(jù),它可以處理syslog日志消息,Windows 事件日志記錄,支持故障排除,使用戶能夠快速查找日志數(shù)據(jù)中看出問題的解決方案。

 LogAnalyzer 獲取客戶端日志會(huì)有兩種保存模式,一種是直接讀取客戶端/var/log/目錄下的日志并保存到服務(wù)端該目錄下,一種是讀取后保存到日志服務(wù)器數(shù)據(jù)庫中,推薦使用后者。LogAnalyzer采用php開發(fā),所以日志服務(wù)器需要php的運(yùn)行環(huán)境,這里采用LAMP。

1)安裝配置好mysql數(shù)據(jù)庫服務(wù)

[root@mylinux home]# yum install mysql  mysql-server -y [root@mylinux home]#/etc/init.d/mysqld start

2)安裝rsyslog-mysql包

[root@mylinux log]# yum install rsyslog-mysql -y

3)創(chuàng)建rsyslog依賴的數(shù)據(jù)庫:

[root@mylinux doc]# mysql < /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql  [root@localhost home]# mysql   Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;    #查看數(shù)據(jù)是否導(dǎo)入 +--------------------+ | Database           | +--------------------+ | information_schema | | Syslog             | | mysql              | | test               | +--------------------+ 4 rows in set (0.00 sec)

4)配置rsyslog啟用模塊,/etc/rsyslog.conf

 在#### Modules #####啟用模塊:

 $ModLoad ommysql

 在####rules####段中定義記錄日志信息于數(shù)據(jù)庫中

 facility.priority :ommysql:SERVER_IP,DATABASE,USERNAME,PASSWORD

[root@mylinux rsyslog.d]# vim /etc/rsyslog.conf  #### MODULES #### $ModLoad ommysql ... #### RULES #### facility.priority :ommysql:SERVER_IP,DATABASE,USERNAME,PASSWORD [root@localhost home]# /etc/init.d/rsyslog restart Shutting down system logger: [  OK  ] Starting system logger: [  OK  ]

5)搭建lamp環(huán)境,安裝loganalyzer

# yum -y install httpd php php-mysql php-gd [root@localhost home]# httpd httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [root@mylinux home]# wget     [root@mylinux home]# tar xf loganalyzer-3.6.6.tar.gz [root@mylinux home]# mkdir /var/www/html/loganalyzer [root@mylinux home]# cp -R loganalyzer-3.6.6/src/* /var/www/html/loganalyzer/ [root@mylinux home]# cp -R loganalyzer-3.6.6/contrib/* /var/www/html/loganalyzer/ # cd /var/www/html/loganalyzer/ # chmod +x configure.sh secure.sh # ./configure.sh # ./secure.sh # chmod 666 config.php # chown -R apache.apache ./*

6)在瀏覽器輸入網(wǎng)站地址,按照提示就可以完成配置。

十、syslog日志與loganalyzer日志管理

十、syslog日志與loganalyzer日志管理

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

文章題目:十、syslog日志與loganalyzer日志管理-創(chuàng)新互聯(lián)
分享路徑:http://muchs.cn/article44/ddsihe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化ChatGPT、虛擬主機(jī)、做網(wǎng)站、品牌網(wǎng)站制作、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司