2018년 2월 4일 일요일

ncat 을 이용한 원격지 프로세스 체크

프로그램 변경없이 간단하게 Nmap을 이용하여 다른 시스템에서 해당 시스템의 프로세스 정보를 체크

그러나 이건 진짜 땜빵이고 설계때 부터 운영 관점에서 고려되어야되지 않을런지...

(현재 이 땜빵을 14개 어플리케이션 서버에 적용 중..;;)

1. 일단 nmap 패키지를 설치하자.

RedHat 계열이라면 요렇게..

# Installing nmap package
yum install nmap


2. 다음은 쉘스크립트
#!/bin/sh
# defines application name
APP_NAME="net.oopscode.ApplicaitionMain"

# status task
function status(){
    echo "+ Application Status"
    pid=$(ps -ef | grep "java" | grep ${APP_NAME} | awk {'print $2'})
    if [ ! -z ${pid} ]; then
        top -b -n 1 -p ${pid}
    fi
    ps -ef | grep "java" | grep ${APP_NAME}
}

# notify task
function notify() {
    pid=$(ps -ef | grep "ncat" | grep "${0} status" | awk {'print $2'})
    if [ ! -z ${pid} ]
    then
        kill ${pid}
    fi
    nohup ncat -l 30001 --sh-exec "${0} status" --keep-open > /dev/null &
}

# Main process
case ${1} in
    status)
        status
        ;;
    notify)
        notify
        ;;
    *)
        echo "Usage: "${0}" [status|notify]"
        ;;
esac


3. 모니터링 프로세스 구동 및 테스트
# 프로세스 상태 출력 테스트
monitor.sh status

# ncat 프로세스 시작
monitor.sh notify

# 테스트
telnet localhost 30000

댓글 없음:

댓글 쓰기

Creating CRC32 Hex string

public String getCRC32HexaString(String paramString) throws Exception  {   byte bytes[] = paramString.getBytes(DEFAULT_CHARSET);   Che...