2008. 3. 17.

[Linux] iostat lsof netstat top vmstat uptime

▶netstat
라우팅 테이블이나 활성화되어 있는 네트워크 연결같은 네트워크 통계와 정보를 보여 줍니다. 이 유틸리티는 /proc/net에서 정보를 얻어 옵니다.
**********************************************************************************************
# netstat -nap : 열려 있는 모든 포트
# netstat -l 또는 netstat nap | grep LISTEN : LISTEN 되는 모든 포트
# netstat -nap | grep ESTABLISHED | wc-l : 모든 서비스 동시 접속자 수
# netstat -nap | grep :80 | grep ESTABLISHED | wc-l : 모든 서비스 동시 접속자 수

포트 스캔 명령어

# nmap -sT -p 1-65535 localhost :TCP 포트 확인 방법
# nmap -sU -p 1-65535 localhost :UDP 포트 확인 방법
# nmap -sX -p 80,7003,7001 192.168.1.* : 네트워크에 열린 포트 확인



usage: netstat [-veenNcCF] [] -r netstat {-V|--version|-h|--help}
netstat [-vnNcaeol] [ ...]
netstat { [-veenNac] -i[] | [-cnNe] -M | -s } [delay]

라우터 -r, --route display routing table
인터페이스 -i, --interfaces=[] display interface table
그룹간 -g, --groups display multicast group memberships
통계 -s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-c, --continuous continuous listing

-l, --listening display listening server sockets
-a, --all, --listening display all sockets (default: connected)
-o, --timers display timers
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-T, --notrim stop trimming long addresses

: Name of interface to monitor/list.
={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
=Use '-A ' or '--'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
**********************************************************************************************

▶uptime
시스템이 얼마나 오랫동안 돌고 있었는지 관련 통계와 함께 보여줍니다.
**********************************************************************************************
현재시간 돌고있는날짜 사용자 평균전력
ex) 09:29:49 up 2 days, 22:58, 1 user, load average: 0.00, 0.00, 0.00
09:29:16 up 39 days, 1:28, 5 users, load average: 0.00, 0.07, 0.06
**********************************************************************************************

▶top
cpu를 집중적으로 사용하는 프로세스를 중심으로 최신 정보를 계속 보여 줍니다.
-b 옵션은 결과를 텍스트 모드로 보여 주기 때문에 파싱을 하거나 스크립트에서 접근할 수가 있습니다.
**********************************************************************************************
상위 uptime 정보 출력 됨.
top - 11:06:20 up 3 days, 35 min, 3 users, load average: 0.15, 0.05, 0.01
Tasks: 65 total, 1 running, 63 sleeping, 1 stopped, 0 zombie
Cpu(s): 1.0% us, 3.7% sy, 0.0% ni, 0.0% id, 95.0% wa, 0.3% hi, 0.0% si
Mem: 515612k total, 406316k used, 109296k free, 101880k buffers
Swap: 1020088k total, 0k used, 1020088k free, 252884k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10566 root 18 0 3580 560 424 D 4.7 0.1 0:00.44 find
10126 root 16 0 2472 944 752 S 0.3 0.2 0:01.60 top
10352 root 16 0 2688 956 760 R 0.3 0.2 0:00.57 top
1 root 16 0 2756 552 472 S 0.0 0.1 0:00.82 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
3 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 events/0
4 root 5 -10 0 0 0 S 0.0 0.0 0:00.01 khelper
5 root 15 -10 0 0 0 S 0.0 0.0 0:00.00 kacpid
20 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 kblockd/0
38 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pdflush
39 root 15 0 0 0 0 S 0.0 0.0 0:00.02 pdflush
41 root 12 -10 0 0 0 S 0.0 0.0 0:00.00 aio/0
21 root 15 0 0 0 0 S 0.0 0.0 0:00.05 khubd
40 root 15 0 0 0 0 S 0.0 0.0 0:00.14 kswapd0
187 root 25 0 0 0 0 S 0.0 0.0 0:00.00 kseriod
310 root 15 0 0 0 0 S 0.0 0.0 0:01.45 kjournald
1321 root 6 -10 2452 456 380 S 0.0 0.1 0:00.03 udevd
1700 root 6 -10 0 0 0 S 0.0 0.0 0:00.00 kauditd
1767 root 6 -10 0 0 0 S 0.0 0.0 0:00.00 kmirrord
1955 root 19 0 0 0 0 S 0.0 0.0 0:00.00 kjournald
1956 root 15 0 0 0 0 S 0.0 0.0 0:00.00 kjournald
1957 root 15 0 0 0 0 S 0.0 0.0 0:00.00 kjournald
1958 root 15 0 0 0 0 S 0.0 0.0 0:00.19 kjournald
1959 root 15 0 0 0 0 S 0.0 0.0 0:00.25 kjournald
2609 root 16 0 2868 544 456 S 0.0 0.1 0:06.80 syslogd
2613 root 16 0 2720 380 316 S 0.0 0.1 0:00.02 klogd
2642 rpc 15 0 3544 548 452 S 0.0 0.1 0:00.00 portmap
2662 root 15 0 2916 724 624 S 0.0 0.1 0:00.00 rpc.statd
2690 root 16 0 4220 340 172 S 0.0 0.1 0:00.00 rpc.idmapd
2767 root 15 0 2664 508 300 S 0.0 0.1 0:00.16 smartd
2777 root 19 0 2952 440 368 S 0.0 0.1 0:00.00 acpid
2789 root 16 0 10332 1964 1512 S 0.0 0.4 0:00.02 cupsd
2865 root 16 0 4256 1136 836 S 0.0 0.2 0:01.67 sshd
2880 root 16 0 2284 804 672 S 0.0 0.2 0:00.01 xinetd
2900 root 16 0 8404 2020 984 S 0.0 0.4 0:00.05 sendmail
2908 smmsp 16 0 7780 1632 812 S 0.0 0.3 0:00.01 sendmail
2919 root 16 0 2172 352 280 S 0.0 0.1 0:00.00 gpm
**********************************************************************************************

▶vmstat
가상 메모리 통계를 보여줌.
**********************************************************************************************
usage: vmstat [-V] [-n] [delay [count]]
-V prints version.
-n causes the headers not to be reprinted regularly.
-a print inactive/active page stats.
-d prints disk statistics
-D prints disk table
-p prints disk partition statistics
-s prints vm table
-m prints slabinfo
-S unit size
delay is the delay between updates in seconds.
unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)
count is the number of updates.
**********************************************************************************************

▶lsof
현재 열려 있는 파일들을 보여줍니다. 이명령어는 현재 열려 있는 모든 파일들에 대한 자세한 표와 각각의 파일에 대한 소유자, 크기, 관련 프로세스등의 정보를 보여 줍니다. 당연히, lsof의 출력은 파이프 grep awk로 넘겨서 파싱해서 분석할 수 있다.
************************************************************************************************************************
프로세스아이디/ 사용자 / 확장자
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 2126 w3sli cwd DIR 9,0 4096 2 /
httpd 2126 w3sli rtd DIR 9,0 4096 2 /
httpd 2126 w3sli txt REG 9,12 2197124 2572313 /app1/web/apache2054/bin/httpd
httpd 2126 w3sli mem REG 9,0 214312 589848 /lib/ld-2.3.2.so
httpd 2126 w3sli mem REG 9,12 382636 1409276 /app1/web/apache2054/lib/libaprutil-0.so.0.9.6
httpd 2126 w3sli mem REG 9,0 48400 1261650 /usr/lib/libgdbm.so.2.0.0
httpd 2126 w3sli mem REG 9,0 1812176 589887 /lib/libdb-4.1.so
httpd 2126 w3sli mem REG 9,0 274928 1261648 /usr/lib/libexpat.so.0.4.0
httpd 2126 w3sli mem REG 9,12 553580 1409270 /app1/web/apache2054/lib/libapr-0.so.0.9.6
httpd 2126 w3sli mem REG 9,0 85176 933951 /lib/tls/librtkaio-2.3.2.so
httpd 2126 w3sli mem REG 9,0 621352 933946 /lib/tls/libm-2.3.2.so
httpd 2126 w3sli mem REG 9,0 41112 589857 /lib/libcrypt-2.3.2.so
httpd 2126 w3sli mem REG 9,0 177640 589863 /lib/libnsl-2.3.2.so
httpd 2126 w3sli mem REG 9,0 157056 933948 /lib/tls/libpthread-0.60.so
httpd 2126 w3sli mem REG 9,0 28536 589859 /lib/libdl-2.3.2.so
httpd 2126 w3sli mem REG 9,0 2789888 933944 /lib/tls/libc-2.3.2.so
httpd 2126 w3sli mem REG 9,12 2470954 1916946 /app1/was/bea/weblogic81/server/lib/linux/ia64/mod_wl_20.so
httpd 2126 w3sli mem REG 9,12 214890 2277776 /app1/web/apache2054/modules/mod_security.so
httpd 2126 w3sli mem REG 9,12 53394 2277604 /app1/web/apache2054/modules/mod_url.so
httpd 2126 w3sli mem REG 9,0 106864 589869 /lib/libnss_files-2.3.2.so
************************************************************************************************************************
logname
현재 사용자의 로그인 이름을 /var/run/utmp에서 찾아서 보여줍니다. 위에서 설명한 whoami와 거의 동일한 명령입니다.

last
사용자가 마지막으로 로그인 한 시간을 /var/log/wtmp에서 읽어서 보여줍니다. 이명령어는 외부에서 로그인 한 정보도 보여줄 수 있습니다.

lastlog
시스템의 모든 사용자가 마지막으로 로그인한 시간을 보여줍니다. 이 명령어는 /var/log/lastlog 파일을 참조 합니다.

logrotate
이 유틸리티는 시스템 로그 파일들을 적당하게 로테이트 시키고, 압축하고, 지우고, 메일을 보내는 일들을 처리해 줍니다.
보통 crond은 logrotate를 가장 기본적인 하루 일과로 삼습니다.
/etc/logrotate.conf에 적당한 내용을 적어주면 시스템 전체 로그뿐만 아니라 개인용 로그 파일을 관리할 수 있습니다.

▶iostat 시스템 파일의 정보 [디스크 이용률 보고서]
중앙 연산 처리장치 (CPU)통계, 비동기 입출력 및 전체 시스템, 어댑터, tty 장치, 디스크 및 CD-ROM에 대한 입출력 통계를 보고 합니다.

sysstat version 4.0.7
(C) S. Godard
Usage: iostat [ options... ]
Options are:
[ -c | -d ] [ -k ] [ -t ] [ -V ] [ -x [ ] ]
[ [ ] ]
# iostat -c
# iostat -d Block
# iostat -k KByte
# iostat -t
# iostat -v
# iostat -x

Linux 2.6.9-42.EL (www.myserver.com) 04/19/07

avg-cpu: %user %nice %sys %iowait %idle
0.16 0.01 0.18 0.06 99.60

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
hda 1.08 2.02 7.52 546381 2035663
hda1 0.00 0.00 0.00 873 24
hda2 0.56 0.58 1.10 157889 298079
hda3 0.10 0.07 0.32 19041 86180
hda4 0.00 0.00 0.00 1 0
hda5 0.62 0.32 2.24 85590 607013
hda6 0.03 0.02 0.02 6626 6029
hda7 1.02 1.02 3.83 275257 1038338
hda8 0.00 0.00 0.00 544 0
hdb 0.00 0.00 0.00 876 0

ex)
-d : 드라이브 보고서
드라이브명 초당평균 요청횟수
# iostat -d hda1 2 2

Kbps : 드라이브에 전송된 데이터의 양을 초당 KB 단위로 나타냅니다.

bkread : 호스팅 서버로부터 이 어댑터에 수신된 초당 블록 갯수.
bkwrtn : 이 어댑터에서 호스팅 서버로 전송된 초당 블록 갯수.
tps : 어댑터에 발행된 초당 전송 수
Kb_read : (전체 시스템으로부터 or 어댑터로 부터) 읽여진 KB의 총수
Kb_wrtn : (전체 시스템으로부터 or 어댑터에) 기록된 KB의 총수

----------------------------------------------------------------------------
EXAMPLES
To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely

To see every process on the system using BSD syntax:
ps ax
ps axu

To print a process tree:
ps -ejH
ps axjf

To get info about threads:
ps -eLf
ps axms

To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM

To see every process except those running as root (real & effective ID)
ps -U root -u root -N

To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -eopid,tt,user,fname,tmout,f,wchan

Odd display with AIX field descriptors:
ps -o "%u : %U : %p : %a"

Print only the process IDs of syslogd:
ps -C syslogd -o pid=

Print only the name of PID 42:
ps -p 42 -o comm=

댓글 없음: