2012년 5월 7일 월요일

리눅스 시스템 점검

3.10 시스템 정보보기

1) cpu정보보기  
# more  /proc/cpuinfo 


2) 메모리 정보보기 
#  free  –mt 
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
        -b,-k,-m,-g show output in bytes, KB, MB, or GB          -h show detailed low and high memory statistics
          -o use old format (no -/+buffers/cache line)
        -t display total for RAM + swap

# more /proc/meminfo


3) 하드용량보기      
# df –h 
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2              28G  4.6G   22G  18% /
/dev/hda1              99M  9.2M   85M  10% /boot
none                  251M     0  251M   0% /dev/shm
root]#

4) 인터페이스 ip정보 보기
# ifconfig eth0
# ifconfig  –a

# vi /etc/sysconfig/i18n   (언어 로케일설정)
LANG="ko_KR.eucKR"
SUPPORTED="ko_KR.eucKR:ko_KR:ko"
SYSFONT="lat0-sun16"
SYSFONTACM="iso15"

en_US

# Vi .bashrc
# export LANG=ko_KR.eucKR (자신의 쉘에 언어코드 변경) 
또는 
#  export LANG=en_US
# LANG=en



3.10.1. CPU 문제 점검명령어들  Top, ps, uptime, vmstat, pstree 등

1) CPU 활용량, 프로세스상태, 메모리확용량

# top  
CPU0 states:  0.0% user,  0.2% system,  0.0% nice, 99.3% idle
CPU1 states:  0.0% user,  0.0% system,  0.0% nice, 100.0% idle
Mem:  1033308K av, 1007748K used,   25560K free,       0K shrd,   98256K buff
// 메모리 1Giga , 1Giga가까이 사용중, 남음메모리는 25 Mega
                                                                  


3.10.2. 메모리 문제 점검 명령어들   free, vmstat

1)  # free    -mt
                 total       used       free     shared    buffers     cached
Mem:           501        485         16          0        120        148
-/+ buffers/cache:        216        285
Swap:         1019         13       1006
Total:        1521        498       1022

// 512Mega 메모리에  485M 사용중이고,  16M 여유가 있다.


2) # vmstat 1
   procs                      memory      swap          io     system      cpu
 r  b  w   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id
 1  0  0  13332  16488 123720 152352    0    0     0     5    4     2  0  0     2
 0  0  0  13332  16488 123720 152352    0    0     0     0  106    28  0  0  100
 0  0  0  13332  16488 123720 152352    0    0     0    28  107    39  0  0  100

// 164M 여류가 있다. ,

# vmstat 3 20    (3초마다 20번상태 보기)
procs                      memory      swap          io     system         cpu
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
0  0      0 1746628  82216  83888    0    0     0     1   53     4  0  0 100  0
//1.7 Giga메모리가 남아 있음.

// 프로세스 관련 항목: r  : CPU 접근 대기 중인 실행 가능 프로세스 수,  b : 인터럽트 불가능한 수면 상태인 프로세스 수
// 메모리 관련 항목 : swpd — 사용된 가상 메모리 용량,  free — 여유 메모리 용량, buff — 버퍼에 사용된 메모리 용량, cache — 페이지 캐시에 사용된 메모리 용량
// 스왑 관련 항목 : si — 디스크에서 스왑된 메모리 용량, so — 디스크로 스왑되어 나간 메모리 용량
// 입출력 관련 항목 : bi — 블록 장치로 보내진 블록, bo — 블록 장치에서 받아온 블록
// 시스템 관련 항목 : in — 일초당 인터럽트 수, cs — 일초당 문맥 전환 작업수
// CPU 관련 항목 : us — CPU가 사용자 수준 코드를 실행한 시간 (백분율 단위), sy — CPU가 시스템 수준 코드를 실행한 시간 (백분율 단위),id — CPU가 아무런 작업을 수행하지 않은 시간 (백분율), wa — 입출력 대기


어플리케이션이 메모리 많이 사용할시 점검툴
http://supervisord.org/
http://www.linux.com/feature/146166


3.10.3 메모리에 문제가 없다면 디스크 I/O 점검 : 
#df -h, du, 쿼타 등

3.10.4 디스크와 메모리에 문제가 없는데도 시스템에 문제가 생기면, CPU의 오버헤드에 문제가 있을 가능성이 크다

3.10.5  기타 디렉토리 관련 명령어
1) 현재 디렉토리 총용량보기  
#  du -c -h --max-depth=0
4.6G    합계

2) 현재 디렉토리크기         
# du -h --max-depth=1 .

3) 가장 큰 파일 찾기  
#  ls -lR | sort +4n

5) 어떤 프로세서가 가장 많은 메모리를 잡아먹구 있나?  
# ps -aux | sort +4n

6) 원하지 않는 사용자 터미널 접속끊기 ( session )
# w 
# skill -Kill -v pts/11   ( # skill -kill user111 )

7) 날짜 싱크
# date 
# rdate -s time.bora.net
# clock -w

8) 열린포트보기
#  netstat -anp | grep LISTEN

9) 접속자에게 메시지 보내기  
#  wall 지금 서버점검합니다. 로그아웃해주세요. 문제있으면 전화주세요 02-111.1111      Ctrl-D 

10) icmp echo 막기
#   echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

11) 하루동안 만들어진 파일중 hack 들어가는거 찾기 :
# find / -ctime -1 | grep hack


3.10.6  로그온 사용자 점검

과거에 로그온 한 사용자 기록보기 
# Last 

사용자별 마지막 로그온 시간 보기 
# lastlog

콘솔이 아닌곳에서 루트로 로그인한 것 찾기 
# last root |grep -v console  

프로세서 보기  
# Ps –au | more

현재 로그인한 사람 정보 보기  
# Who 

2012년 5월 6일 일요일

DHCP Servers with Multiple NICs

DHCP servers with multiple interfaces pose two configuration challenges. The first is setting up the correct routing and the second is making sure only the required interfaces are listening to serve DHCP. Don’t worry, both will be discussed next.

Routing

When a DHCP configured PC boots, it requests its IP address from the DHCP server. It does this by sending a standardized DHCP broadcast request packet to the DHCP server with a source IP address of 255.255.255.255.
If your DHCP server has more than one interface, you have to add a route for this 255.255.255.255 address so that it knows the interface on which to send the reply; if not, it sends it to the default gateway. (In both of the next two examples, we assume that DHCP requests will be coming in on interface eth0).
Note: More information on adding Linux routes and routing may be found in Chapter 3, "Linux Networking".
Note: You can't run your DHCP sever on multiple interfaces because you can only have one route to network 255.255.255.255. If you try to do it, you'll discover that DHCP serving working on only one interface.

Temporary Solution

You can temporarily add a route to 255.255.255.255 using the route add command as seen below.
[root@bigboy tmp]# route add -host 255.255.255.255 dev eth0
If you want this routing state to be maintained after a reboot, then use the permanent solution that's discussed next.

Permanent Solution

Create a permanent route to 255.255.255.255. This will vary according to your version of Linux
Fedora / RedHat / CentOS: Add the route to your /etc/sysconfig/network-scripts/route-eth0 file if the route needs to be added to your eth0 interface.
#
# File /etc/sysconfig/network-scripts/route-eth0
#

255.255.255.255/32 dev eth0
Ubuntu / Debian: Add the route to your /etc/network/interfaces file. In this case the route is added to the eth0 interface.
#
# File: /etc/network/interfaces
#

iface eth0 inet static

       up route add -host 255.255.255.255 eth0
Simple Linux routing is covered in Chapter 3, "Linux Networking" and will add more clarity to adding permanent static routes.

Listening

Once you have defined the interface for your DHCP routing you should also ensure that your DHCP server only listens on that interface and no others. This methodology to do this varies depending on your versión of Linux.
Fedora / RedHat / CentOS: The /etc/sysconfig/dhcpd file must be edited and the DHCPDARGS variable edited to include the preferred interface. In this example interface eth0 is preferred.
# File: /etc/sysconfig/dhcpd
DHCPDARGS=eth1
Debian / Ubuntu: The /etc/default/dhcp3-server file must be edited and the INTERFACES variable edited to include the preferred interface. In this example interface eth0 is preferred.
# File: /etc/default/dhcp3-server
INTERFACES="eth0"
You will be able to verify success in one of two ways. First the netstat command using the –au options will give the list of interfaces listening on the bootp (DHCP) UDP port.
[root@bigboy-f ~]# netstat -au  | grep bootp
udp        0     0 192.168.1.100:bootps    *:*
[root@bigboy-f ~]#
Secondly, your /var/log/messages file will also reveal the defined interfaces used when the DHCPd daemon was restarted.
Jan  8 17:22:44 bigboy dhcpd: Listening on LPF/eth0/00:e0:18:5c:d8:41/192.168.1.0/24
Jan  8 17:22:44 bigboy dhcpd: Sending on   LPF/eth0/00:e0:18:5c:d8:41/192.168.1.0/24
Success! You can go back to lunch!