[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 安全技術 > 工具 > 正文
Swatch的安裝和使用
本文出自:http://www.china-pub.com/ 作者: 李國莉 (2001-08-10 15:00:00)
  Swatch程序的作用在監視系統的日志文件,並根據用戶設置的配置信息,及時的將用戶感興趣的事件發生情況通知用戶。Swatch有兩種運行方式:批處理方式,即檢查日志文件立刻退出;監控方式,連續監視日志文件,檢查每一條新記錄是否符合用戶的設置條件。在監控狀態下,Swatch對事件的更新和通知實時性很好。在Swatch中,提供了多種通知選項,例如:在終端顯示板上以不同的顏色顯示不同的日志信息;終端振鈴;轉發到用戶的email地址等等。
一、 獲得Swatch
Swatch是一個免費的軟件包。一般可以在國內各個ftp站點上找到。用戶可以從以下幾個站點下載Swatch的rpm包,它的安裝十分方便快捷。
ftp://freesoft.cei.gov.cn/mirror2/ftp.redhat.com/contrib/noarch/SRPMS
ftp://ftp.bjnet.edu.cn/pub/linux/linux/FreeBSD-2.2.6/packages/All
可以下載的站點很多,就不一一列舉了。
二、 安裝Swatch
Swatch的安裝十分簡單。下面以Swatch-2.2-2.src.rpm為例,說明Swatch的安裝過程。在安裝前,首先確定安裝用戶以root的身份登陸。安裝過程分為以下幾個步驟:
1. 解rpm包
敲入命令行:rpm -Uvh Swatch-2.2-2.src.rpm 。該命令行自動將Swatch-2.2-redhat.patch 和Swatch-2.2.tar.gz拷貝到/usr/src/ redhat/SOURCES/目錄下。
2. 解壓縮文件Swatch-2.2.tar.gz
到/usr/src/ redhat/SOURCES/目錄下,運行命令行:tar xvfz Swatch-2.2.tar.gz,系統將文件解壓拷貝。內容如下:
Swatch-2.2/
Swatch-2.2/Changes
Swatch-2.2/Contents
Swatch-2.2/README
Swatch-2.2/config_files/
Swatch-2.2/config_files/syslog.conf-master
Swatch-2.2/config_files/syslog.conf-server
Swatch-2.2/config_files/Swatchrc.personal
Swatch-2.2/config_files/Swatchrc.monitor
Swatch-2.2/config_files/syslog.conf-client
Swatch-2.2/install.pl
Swatch-2.2/install.sh
Swatch-2.2/lisa93_paper.ps
Swatch-2.2/sw_actions.pl
Swatch-2.2/sw_history.pl
Swatch-2.2/Swatch.pl
Swatch-2.2/Swatch.conf.man
Swatch-2.2/Swatch.prog.man
Swatch-2.2/utils/
Swatch-2.2/utils/call_pager.pl
Swatch-2.2/utils/badloginfinger.pl
檢查所有的文件是否以完整解壓,準備安裝。
3. 運行install.sh開始安裝
在提示符下輸入執行命令:
[root@ice Swatch-2.2]# ./install.sh
安裝程序會提問關安裝環境的設置,提問內容如下:
Enter the directory where Swatch
is to be installed (default '/usr/local/etc')
What user should own the installed Swatch files?
(default 'root')
What group should own the installed Swatch files?
(default 'wheel')
What should the permissions be for the installed Swatch script?
(default '755')
What should the permissions be for the installed Swatch libraries and man pages?
(default '444')
Enter the name of the directory where the
perl library files are located (default '/usr/local/lib/perl')
Enter the name of the directory where you wish to
install the Swatch library files (default '/usr/local/lib/perl')
What directory should the Swatch man pages be installed (default '/usr/local/man')
What should the extension be for the Swatch program manual page? (default '8')
What should the extension be for the Swatch configuration file manual page?
(default '5')
所有的問題都設有默認值,推薦使用默認值安裝。直接按Enter鍵繼續。環境變量設置完畢之,在安裝程序的提示下,就可以完成整個Swatch的安裝。
三、 配置Swatch
配置文件是用來告訴Swatch哪些事件需要想用戶報告,採用什樣的方式通知用戶。Swatch配置文件的格式為:模式以及模式匹配採取的動作。其中模式必須是Perl語言認識的正則表達式。正則表達式由關鍵字和'='組成。下表列出了部分關鍵字和可能值。
關鍵字 鍵值
watch=regular_expression 監控日志文件中的正則表達式
ignore= regular_expression 忽略正則表達式
waitfor= regular_expression 在該正則表達式之前忽略其他正則表達式
echo[=mode] 輸出報刊匹配模式的行,缺省為normal。
bell[=n] 在終端振鈴n次
mail[=address:address:…] 指定郵件發送的email地址,多個地址間用"":"隔開
throttle=options 限制匹配行的動作。
exec=command 模式匹配時,執行command命令。
下面給出用戶ice的個人Swatch配置文件實例。
#
# Ice's Personal Swatch configuration file
#

# Alert me of bad login attempts and find out who is on that system
/INVALID|REPEATED|INCOMPLETE/ echo=inverse,bell=3

# Important program errors
/LOGIN/ echo=inverse,bell=3
/passwd/ echo=bold,bell=3
/ruserok/ echo=bold,bell=3

# Ignore this stuff
/sendmail/,/nntp/,/xntp|ntpd/,/faxspooler/ ignore

# Report unusual tftp info
/tftpd.*(ncd|kfps|normal exit)/ ignore
/tftpd/ echo,bell=3

# Kernel problems
/(panic|halt|SunOS Release)/ echo=bold,bell
/file system full/ echo=bold,bell=3
/vmunix.*(at|on)/ ignore
/vmunix/ echo,bell

/fingerd.*(root|[Tt]ip|guest)/ echo,bell=3
/atkins/ echo=inverse,bell=3

/su:/ echo=bold
/.*/ echo
四、運行Swatch
運行Swatch時,主要是命令行選項的使用。下面主要介紹一個常用的選項。
-c filename 指定Swatch的配置文件。
-r restart_time 在特定的時間自動重啟。時間格式有兩種:+hh:mm表示hh小時mm分,自動重啟;hh:mm[am|pm]表示在指定的時間點重啟。
-P pattern_separator 告訴Swatch使用pattern_separator作為配置文件中莫時匹配的分隔符,默認為冒號":"。
下面幾個選項只能選用其中之一。
-f filename Swatch檢查filename文件的內容,並退出。
-p command 先執行command命令,其輸出作為Swatch的輸入。
-t filename 檢查加入filename文件的新內容。
當執行Swatch命令,不帶任何參數時,Swatch命令等效下面的執行方式:
Swatch -c ~/.Swatchrc -t /var/log/syslog
下面介紹幾個Swatch運行結果的例子。
命令行:Swatch -c ~/.Swatchrc -t /var/log/syslog
運行結果:
*** Swatch-2.2 (pid:1661) started at Sun Nov 26 12:23:03 CST 2000

Nov 24 12:01:05 ice in.telnetd[993]: refused connect from 202.112.13.211
Nov 24 20:19:45 ice inetd[445]: pid 1003: exit status 1
Nov 25 14:07:33 ice inetd[445]: pid 1140: exit status 1
Nov 25 20:39:05 ice inetd[445]: pid 1194: exit status 1
Nov 26 12:03:25 ice inetd[445]: pid 1350: exit status 1
Nov 26 12:14:41 ice inetd[445]: pid 1410: exit status 1
Caught a SIGINT -- shutting down
Caught a SIGINT -- shutting down
命令行:Swatch -c ~/.Swatchrc -t /var/log/ messages
運行結果:
*** Swatch-2.2 (pid:1666) started at Sun Nov 26 12:23:42 CST 2000

Nov 26 11:41:41 ice PAM_pwdb[1374]: (su) session opened for user root by zy(uid)
Nov 26 11:48:02 ice PAM_pwdb[1411]: (login) session opened for user wu by (uid=)
Nov 26 11:48:08 ice PAM_pwdb[1434]: authentication failure; wu(uid=510) -> roote
Nov 26 11:48:13 ice PAM_pwdb[1435]: (su) session opened for user root by wu(uid)
Nov 26 12:03:25 ice inetd[445]: pid 1350: exit status 1
Nov 26 12:03:25 ice PAM_pwdb[1374]: (su) session closed for user root
Nov 26 12:14:41 ice inetd[445]: pid 1410: exit status 1
Nov 26 12:14:41 ice PAM_pwdb[1435]: (su) session closed for user root
Nov 26 12:16:21 ice PAM_pwdb[1580]: (login) session opened for user wu by (uid=)

好了,Swatch的安裝,配置和使用說明都介紹完了。接下來就請你試著用用看。Swatch是一個很好的日志文件管理工具,它能確實的保証你的日志文件的完整性,可用性以及實時的通知你系統的安全問題。


(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章
 

★  樊強制作 歡迎分享  ★