2007년 10월 18일
솔라_log
System Logging Management
1. UNIX Log Overview
(1). 로그 기록 용도
- 사용자 및 서버의 활동 기록
- 시스템 공격에 대한 흔적 기록
- 서버 장애에 대한 흔적 기록
- 로그 기록을 통한 성능 카운트
[Ref.] 로그 기록을 이해하지 못하는 관리자에게는 아무런 쓸모가 없는 파일에 불과하다.
(2). 로그의 위치
- /usr/adm 초기 유닉스, BSD 계열, HP-UX 9.X, SunOS 4.X
- /var/adm 최근 유닉스, SVR 계열, Solaris, HP-UX 10.X 이후
- /var/log 일부 BSD 계열, FreeBSD, Linux,
- /var/run 일부 Linux
(3). 솔라리스 기본 로그 파일
- /var/adm/lastlog : Data, last login log // 사용자들의 로그 시간등...
- /var/adm/messages : ASCII ,System Wild Messages(Log at Boot,dmesg + Regular Log)
- /var/adm/sulog : ASCII ,su CMD //su 성공실패 .에관한
- /var/adm/utmpx : ASCII ,who CMD //who라는 명령어 참조화일 ... // utmp wtmp 라고 써있기도함.
- /var/adm/wtmpx :Data last CMD
- /var/cron/log : Data cron Daemon
- /var/log/syslog : ASCII ,syslogd Daemon //메일의 보냈을때 받았을때 .로그
- /var/adm/loginlog : ASCII ,Login fail log (/etc/default/login) //설치하면 만들어줘야함. ..
- /var/log/authlog : ASCII ,Authentication Log (/etc/syslog.conf) //인증인가에 관한 기록.. #처리가되어있다.
- /var/log/xferlog : ASCII ,FTP Server Log(wu-ftpd, /etc/ftpd/ftpaccess) //기본적으로존재하지 않타 업로드다운로드기록
역시 #처리가되어 있다.
bruters attacks
touch /var/adm/loginlog
chown root:sys /var/adm/loginlog
chmod 644 /var/adm/loginlog
tail -f /var/adm/loginlog
[Ref.] /root/security/4_SystemLog/SystemLog.txt
중요
로그서버는 보안상 두는 경우가 많타...
2. The syslog Concept
kernel Mess. ====> syslogd ====> (a). /dev/console
user process Mess A (b). /var/adm/messages
Daemon Mess. | (c). user(root), all(*) // all(*) 모듈사용자
Mail Mess. | (d). @hostA, @172.16.8.254
logger CMD m4 //m4 프리 프로세서
.... |
"syslog()" /etc/syslog.conf //관리자는 중요한화일이다.
syslog 동작
3. /etc/syslog.conf
Selector [TAB] Action
Facility.Level [TAB] Action
EX) user.notice /var/log/test.log
(1). facility
user Messages generated by user processes. This is the
default priority for messages from programs or facili-
ties not listed in this file.
kern Messages generated by the kernel.
mail The mail system.
daemon System daemons, such as in.ftpd(1M)
auth The authorization system: login(1), su(1M), getty(1M)[로그인창],
among others.
lpr The line printer spooling system: lpr(1B), lpc(1B),
among others.
news Reserved for the USENET network news system.
uucp Reserved for the UUCP system; it does not currently
use the syslog mechanism.
cron Reserved for cron/at messages generated by systems
that do logging through syslog. The current version of
the Solaris Operating Environment does not use this
facility for logging.
local0-7 Reserved for local use. // 테스트용으로 정의해서 쓸수있는것.
mark For timestamp messages produced internally by syslogd. //일정한 타임간격을 통해서 정적으로 생성되는 메세지..
* An asterisk indicates all facilities except for the
mark facility.
(2). level
emerg For panic conditions that would normally be broadcast
to all users.
alert For conditions that should be corrected immediately,
such as a corrupted system database.
crit For warnings about critical conditions, such as hard
device errors.
err For other errors.
warning For warning messages.
notice
For conditions that are not error conditions, but may
require special handling. A configuration entry with a
level value of notice must appear on a separate line.
info Informational messages.
debug For messages that are normally used only when debug-
ging a program.
none Do not send messages from the indicated facility to
the selected file. For example, a selector of
(3). action
* /var/adm/messages - Log File
* /dev/console - Log File
* user01,root, * - All User, Specific User
* @hostA, @172.16.8.254 - Other Host
[EX] /etc/syslog.conf
# cat /etc/syslog.conf
......
mail.crit /var/adm/messages
......
4. /etc/syslog.conf File - Default Setting Analysis
Default Setting
- Custom Messages : Console Window, /var/adm/messages
- System Emergency : root, All User
# cat /etc/syslog.conf
#ident "@(#)syslog.conf 1.5 98/12/14 SMI" /* SunOS 5.0 */
#
# Copyright (c) 1991-1998 by Sun Microsystems, Inc.
# All rights reserved.
#
# syslog configuration file.
#
# This file is processed by m4 so be careful to quote (`') names
# that match m4 reserved words. Also, within ifdef's, arguments
# containing commas must be quoted.
#
*.err;kern.notice;auth.notice /dev/sysmsg // 일반적인 메세지가 있으면 콘솔창에 뿌려라!!라는거
*.err;kern.debug;daemon.notice;mail.crit /var/adm/messages
//일반적인 메세지가 있으면 messages창에 뿌려라!!라는거
*.alert;kern.err;daemon.err operator //위험한 정보는 root 에게 뿌려줘라
*.alert root //위한정보는 root 에게 뿌려줘라
local0.notice /var/adm/testmessages
*.emerg *
# if a non-loghost machine chooses to have authentication messages
# sent to the loghost machine, un-comment out the following line:
auth.notice ifdef(`LOGHOST', /var/log/authlog, @loghost) //주석처리가 됬다 ..솔라리스를 설치하면
주석을제거 해야함.
mail.debug ifdef(`LOGHOST', /var/log/syslog, @loghost)
//ifdef 가 해석을 해서 시스로그쪽으로 넘긴다 .
#
# non-loghost machines will use the following lines to cause "user"
# log messages to be logged locally.
#
ifdef(`LOGHOST', ,
user.err /dev/sysmsg
user.err /var/adm/messages
user.alert `root, operator'
user.emerg *
)
5. Stopping and Starting the syslogd Daemon
/etc/syslog.conf 파일의 내용을 수정한 후 적용하기 위해서는 (a)Startup Script를 사용
할수도 있고, (b)pkill 명령어의 HUP 시그널을 사용할수도 있다.
# /etc/init.d/syslog stop/start // 프로세서의 이상이있다.
# pkill -HUP syslogd // -HUP 프로세서의 종류중에서 스탑이라는게있는데 포그라운드와 백그라운드형태가있는데 ..
프로세서에 이상이없다 ..
tip
fg
jobs
ctrl +s
bg %1
bg
stop %1
[/]#cat /etc/hosts
127.0.0.1 localhost
172.16.8.106 solaris106 loghost // 리눅스에서는 볼수없는 loghost
192.168.1.106 nic2
172.16.8.200 solaris200
[/]#
저기 주소가 다른컴으로되있으면 그쪽으로 메세지를 넘긴다 .loghost
만약 자기컴에있으면 var/logsyslog 로되있고 다른컴퓨터로되있으면 메세지를넘긴다 .
중복해서 설정이 가능하다.
tip
해킹당한 컴퓨터는... 로그는 완전하지 않다 ..
6. logger CMD
# man logger
.....
The logger command provides a method for adding one-line
entries to the system log file from the command line. One or
more message arguments can be given on the command line, in
which case each is logged immediately. If this is unspeci-
fied, either the file indicated with -f or the standard
input is added to the log. Otherwise, a file can be speci-
fied, in which case each line in the file is logged. If nei-
ther is specified, logger reads and logs messages on a
line-by-line basis from the standard input.
.....
# logger System rebooted
Default Value: user.notice
# logger -p user.err System rebooted // syslog 함수를 사용한다.
# logger -p local0.notice "System Messages"
[ex] 백업 시간 측정
- Backup Script : backup.sh
- vi backup.sh
# !/bin/ksh
ufsdump 0uf /dev/rmt/0 /export/home
-----------------------------------------------------------------
(a). backup.sh script + date 명령어 활용 (log file) 을 사용하는경우
# vi backup.sh
-----------------------------------------------------------------
data + '%m%d_%H%M' > /var/adm/backup.log
월 일 시 분
[/]#date
2007년 10월 19일 금요일 오후 08시 27분 14초
------------------------------------------------------------------
echo "Backup Start: 'date + %m%d_%H%M'" > /var/adm/backup.log
ufsdump 0uf /dev/rmt/0 /export/home
if [ $? -eq 0 ] ; then //$ 성공실패를 확인하는거...
echo "backup Stop : 'date + '%m%d_%H%M'" >> /var/adm/backup.log
else
echo "Backup Abnormal stop : 'date + '%m%d_%H%M'" >> /var/adm/backup.log
fi
------------------------------------------------------
echo "backup Stop : 'date + '%m%d_%H%M'"
....
backup.sh script + logger 명령어 활용 (log file)
vi backup.sh
-----------------------------------------------------
.......
DATE='date + '%m%d_%H%M'`
logger -p local0.notice "$DATE"
ufsdump 0uf /dev/rmt/0 /exprot/home
.....
if [$? -eq 0 ] ; then
logger -p local0.notice 'backup stop :$date "
else
logger -p local0.noticce "backup abnomal stop : $date"
.....
7. syslog Practice
[EX1] inetd 활용한 TCP 추적로그
# man inetd
....
The /etc/default/inetd file contains the following default
parameter settings.
.....
ENABLE_CONNECTION_LOGGING
Specifies whether incoming TCP connections are traced.
The value ENABLE_CONNECTION_LOGGING=YES is equivalent
to the -t command-line option. The default value for
ENABLE_CONNECTION_LOGGING is NO.
.....
# cat /etc/default/inetd
ENABLE_CONNECTION_LOGGING=YES
or
# vi /etc/init.d/inetsvc
.....
inetd -s -t &
# pkill -1 inetd
or
# /etc/init.d/inetsvc stop
# /etc/init.d/inetsvc start
TERM 1> Admin Window
# tail -f /var/adm/messages
TERM 2> User Window
# telnet localhost
user01/k (incorrect password)
[Ref.] /var/adm/messages 파일의 분석
Jun 14 13:15:39 host1 inetd[2359]:[ID 317013 daemon.notice] telnet[2361] from 192.9.200.1 45800
A A A A A A A A
| | | | | | | |
(a) (b) (c) (d) (e) (f) (g) (h)
텔넷에 관한 .....것..
(a) Date & Time Jun 14 13:15:39
(b) Local Host host1
(c) Process/PID inetd[2359]
(d) Mess_ID/Selector ID 317013 daemon.notice
(e) Incoming Request telnet
(f) PPID [2361]
(g) Remote IP 192.9.200.1
(h) Port Number 45800
[EX2] syslogd 활용한 로그 모니터링
===메세지 생성=== =======syslogd============ ======로그 모니터링=======
/etc/syslog.conf tail -f /var/adm/local.log
A
local0.notice--+-->local0.notice /var/adm/local.log-----------------+
|
local0.crit-----+
[그림] syslog 메세지 모니터링
# vi /etc/syslog.conf
....
local0.notice /var/adm/local.log
....
# touch /var/adm/local.log
# chmod 777 /var/adm/local.log (Test Perm.)
(Original Perm. : 644 or 640, root:sys)
# pkill -1 syslogd
TERM 1>
# tail -f /var/adm/local.log
TERM 2>
# logger -p local0.notice "System Notice Messages"
# logger -p local0.crit "System Critical Messages"
(at Error check point)
* /etc/syslog.conf 파일 정의시 필드를 [TAB]으로 구분하였는가?
[EX3] Log Server
======== HOSTA ========= ========= HOSTB ==========
Messg. -> syslogd -> @HOSTB -------------------> syslogd
/etc/syslog.conf /etc/syslog.conf
local0.notice @HOSTB local0.notice /var/adm/local.log
[그림] 로그 서버 1
HOSTA)
# vi /etc/hosts
......
172.16.8.254 solaris254
......
# vi /etc/syslog.conf
......
local0.notice @solaris254
......
or
local0.notice @172.16.8.254
# pkill -1 syslogd
# logger -p local0.notice "HOSTA(solarisXXX) Messages"
HOSTB)
# tail -f /var/adm/local.log
======== HOSTA ========= ========= HOSTB ==========
Messg. -> syslogd -> @HOSTB -------------------> syslogd
/etc/syslog.conf /etc/syslog.conf
local0.notice /var/adm/local.log local0.crit /var/adm/local.log
local0.crit @HOSTB
[그림] 로그 서버 2
(At HOSTA)
TERM1>
# vi /etc/syslog.conf
......
local0.notice /var/adm/local.log
local0.crit @HOSTB
# pkill -1 syslogd
# logger -p local0.notice "HOSTA Notice Messages"
# logger -p local0.crit "HOSTA Critical Messages"
TERM2>
# tail -f /var/adm/local.log
(At HOSTB)
# tail -f /var/adm/local.log
[Log Policy]
(1). Log File Name
Log Format : [Name]_[Time].log
EXAMPLE : local_1130.log
[1st study]
# date +'%m%d'
[2nd study]
# crontab -e
Min Hour Day Month Week CMD
59 23 * * * /root/bin/logchecker.sh
/var/adm/messages /var/adm/messages
messages.0 messages_0327.log
messages.1 messages_0326.log
messages.2 messages_0325.log
# cat /root/bin/logchecker.sh
---------------------------------------------------------
#!/bin/ksh
mv /var/adm/messages /var/adm/messages_`date +'%m%d'`.log
touch /var/adm/messages
chown root:sys /var/adm/messages
chmod 644 /var/adm/messages
---------------------------------------------------------
(2). Log File Delete
Log Delete Policy : 30 Days
[1st study]
# crontab -e
Min Hour Day Month Week CMD
0 5 * * 0 find /logdir -name "local*" -mtime +30 -exec rm {} \;
[Ref.] Log Policy move
/logidr -> /logdir_backup : log compress
# by | 2007/10/18 21:27 | 솔라리스 | 트랙백(1) | 덧글(2)






☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
제목 : 솔라리스 로그파일 정보 및 관리
System Logging Management - http://theurgistk.egloos.com/3864759...more
제가 지금 하는것은 syslog를 다른쪽으로 보내는건데...
자료를 보면 로그 호스트를 다른컴으로 하면 보낸다고 나와있네요.
그럼 받는쪽에서 설정해주는 사항은 어찌되나요..?
어디에 남기실껀지 설정만하시면되실껄요 ..