2016년 10월 13일 목요일

Nagios 모니터링 연동방안

Nagios 모니터링 연동방안

최근 게임을 OPEN 준비하면서 Mysql 의 확장성을 고려하여 서버를 많이 분할 하게 되었다. 하나의 게임이 게임서버와 DB 서버가 많다보니, 이를 한눈에 장애를 파악하고자 모니터링 툴이 필요하였다.  일반적으로 Zabbix 로 모니터링을 하고 있으나, 추가적인 모니터링 강화를 위해 Nagios 를 연동해 보았고, 이에 대한 연동 방안을 공유 하고자 합니다.


1. Nagios 란 ?
   Nagios 는 시스템 모니터링 프로그램으로, 기본적으로 호스트, PING, 서비스, 네트워크를 모니터링 하고 있으며, 추가적인 스크립트나 프로그램들을 구글상에서 쉽게 구할 수 있다. (사용자가 쉽게 쉘로 작성해도 된다 .)
   이 수집된 정보를 CSS,PHP 등을 통해 웹으로 뿌려주기 때문에, 편리한 툴인듯 보인다.

nagios core - 로컬 호스트를 모니터링 할 수 있다 cpu사용량 메모리 사용량 등 다양하게 많다
nagios plugin - 모니터링할 수 있는 다양한 옵션들. 이 플러그인을 사용해서 원하는 모니터링을 설정할 수 있다. ssh를 통해 원격지의 정보를 주고받는다
nrpe - 원격 서버를 모니터링 할 수 있다. 두개의 서버 모두 nagios가 설치되어 있어야 하고, 모니터링 할 서버의 nrpe.cfg를 보고 그 항목을 감시할 수 있다

2. Nagios 설치 

 일단 서버로 볼수 있는 Nagios Core 를 설치하자 
 a. dependency 설치 
    yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

 b. 유저 생성/그룹생성 
    useradd nagios
    groupadd nagcmd
    usermod -G nagcmd nagios

 c. Nagios 다운로드 
    # wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.8/nagios-4.0.8.tar.gz/download
    # wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

 d. Nagios 설치 
    # tar vzxf nagios-4.0.8.tar.gz
    # tar vzxf nagios-plugins-2.0.3.tar.gz

   # cd nagios-4.0.8
   # ./configure --with-command-group=nagcmd
   # make all
   # make install
   # make install-init  ## /etc/init.d/에 등록됨
   # make install-commandmode   ##nagios라는 유저가 없으면 여기서 에러남
   # make install-config  ## /usr/local/nagios에 설정파일 생성됨
   # make install-webconf  ## /etc/httpd/conf.d/nagios.conf 생성됨

  e. alert 을 받을 메일 주소 입력 
   # vi /usr/local/nagios/etc/objects/contacts.cfg

   define contact {
        contact_name          nagiosadmin         
        use                    generic-contact      ##template에 정의되어 있는 기본정보들
        alias                     Nagios Admin      ## 상세한 이름
        email                    dupont3031@naver.com  ## 여기다 email 주소 입력
        }

  f. 웹 인터페이스 접속시 사용할 패스워드 생성
    # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

  g. nagios-plugin 컴파일
    # cd /src/nagios-plugins-2.0.3
    # ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    # make && make install 

  h. 컨피그 파일 검사
    # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

  i. 서비스 기동 
     # service nagios start.


3. Nagios Client 설치
  성능이 수집되야 할 서버에 Client 를 설치해서 Nagios 서버로 전송하는 방식을 사용하였다.  NRPE 를 사용하여 
  서버가 원격에 있는 스크립트를 수행하여 결과를 전송받는 형태로 Client 에서 발생할 수 있는 부하를 최소화 할 수 있다 .

1. dependency 설치

yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel --skip-broken

2. 유저 생성 
$> useradd nagios

3. 폴더 생성 
$> mkdir -p /home/dba_admin/justin 

4. 패키지 다운로드 
$> scp ~~ 

5. 압축 해지
$> gzip -cd nagios-plugins-2.1.3.tar.gz | tar -xvf -
$> gzip -cd nrpe-2.13.tar.gz | tar -xvf -  

6. plugin 설치 
$> cd nagios-plugins-2.1.3
$> ./configure 
$> make && make install 



7. 권한 부여
$> chown nagios.nagios /usr/local/nagios
Cd ..
$> mv check_mem /usr/local/nagios/libexec/
$> mv check_cpu /usr/local/nagios/libexec/
$> mv check_iostat  /usr/local/nagios/libexec/

$> chown -R nagios.nagios /usr/local/nagios/libexec

8. xinetd 설치
$> yum install xinetd -y


9. nrpe 설치
$> cd nrpe-2.13
$> ./configure --enable-command-args
$> make all && make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd 
$>  vi /usr/local/nagios/etc/nrpe.cfg
dont_blame_nrpe=1
allowed_hosts=127.0.0.1, 192.118.222.44

10. xinetd 에 nrpe 세팅 
$> vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1 localhost [ 이부분에 서버 IP 세팅 ]

11. nrpe service 등록
$>  chkconfig --level 2345 xinetd on
$> chmod 600 /etc/services
$>  vi /etc/services       
nrpe            5666/tcp                        # nagios NRPE
$> chmod 400 /etc/services
$> service xinetd restart

12. nrpe 확인
$> netstat -at | grep nrpe 

# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13

13. DB 에 nagios 유저 생성 
mysql > create user nagios@'192.118.222.44' identified by 'nagios'; 
mysql > grant all privileges on *.* to nagios@'192.1168.222.44'


14. 원격서버에서 실행할  명령 등록
Cd /usr/local/nagios/etc
#> vi /usr/local/nagios/etc/nrpe.cfg
command[check_data]=/usr/local/nagios/libexec/check_disk -w 30% -c 10% -p /dev/sdc1
command[check_log]=/usr/local/nagios/libexec/check_disk -w 30% -c 10% -p /dev/sdb1
command[check_root]=/usr/local/nagios/libexec/check_disk -w 30% -c 10% -p /dev/sda3
command[check_cpu]=/usr/local/nagios/libexec/check_cpu -w 60 -c 90 
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 70 -c 90 
command[check_disk_util]=/usr/local/nagios/libexec/check_iostat -w 50 -c 80 -d sdc

$> service xinetd restart



  3. 각종 팁

1. Nagios 의 웹화면 접속 (80포트)
   http://nagios 서버 접속Ip/nagios 
2. nagios 웹하면 갱신 주기를 변경하려면 cgi.cfg 파일 변경 (초단위) 
   $ > vi /usr/local/nagios/etc/cgi.cfg
    refresh_rate=30

3. Server Host 부분에 Group 단위를 모니터링 할때 3개의 단위만 CSS 로 정렬되는데 4개 Group 을 한화면에 봐야 할경우 Nagios 소스를 수정하고 다시 컴파일 해야함. 
   소스폴더에서 cgi/status.c 파일을 열어 int overview_columns = 3 부분을 4로 변경하고, 서버를 컴파일 해서 nagios 를 기동하면 한화면에 4개의 그룹, 5개의 그룹등을 볼수 있음.  


  

   

   


댓글 없음:

댓글 쓰기