Thursday, January 28, 2010

การปรับแต่ง Nagios ให้สามารถ monitor เครื่อง Client ที่ลงระบบปฏิบัติการ Linux

การปรับแต่ง Nagios ให้สามารถ monitor เครื่อง Client ที่ลงระบบปฏิบัติการ Linux

หลังจากที่เราทำการติดตั้ง Nagios เรียบร้อยแล้ว สิ่งที่ Nagios ทำคือ ระบบจะสามารถ monitor ตัว Nagios server เอง ดังรูป



ซึ่งหากเราจะต้องการ Monitor client เครื่องอื่น ๆ ก็จะต้องทำการปรับแต่งระบบเพิ่มเติมอีกเล็กน้อย โดยเราจะต้องใช้ Nagios plugins ตัวหนึ่งที่ชื่อว่า NRPE - Nagios Remote Plugin Executor

สำหรับรายละเอียดของ NRPE สามารถหาอ่านได้ที่ http://wiki.nectec.or.th/ntl/Project/NRPE

การติดตั้ง NRPE นั้น แบ่งออกเป็น 2 ส่วน คือการติดตั้งที่ Client และการติดตั้งที่ Server

Client ที่ใช้จะเป็น Debian5 ซึ่งถ้าใครจะใช้ Linux ตระกูล Redhat ก็สามารถทำการปรับแต่งได้ไม่ต่างกันครับ

การติดตั้งที่ Client

1. Download Nagios-plugins จาก http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz

2. Download nrpe จาก http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

3. สร้าง Nagios account

[client]# useradd nagios
[client]# passwd nagios

4. ติดตั้งNagios-plugin

[client]# tar xvfz nagios-plugins-1.4.11.tar.gz
[client]# cd nagios-plugins-1.4.11
[client]# export LDFLAGS=-ldl
[client]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[client]# make
[client]# make install
[client]# chown nagios.nagios /usr/local/nagios
[client]# chown -R nagios.nagios /usr/local/nagios/libexec/


5. ติดตั้ง NRPE

[client]# aptitude install libssl-dev libkrb5-dev zliblg-dev e2fsprogs
[client]# tar xvfz nrpe-2.12.tar.gz
[client]# cd nrpe-2.12
[client]# ./configure
[client]# make all
[client]# make install-plugin
[client]# make install-daemon
[client]# make install-daemon-config
[client]# aptitude install xinetd
[client]# make install-xinetd

6. ปรับแต่งค่าของ /etc/xinetd.d/nrpe โดยเพิ่ม ip-address ของ Nagios server (สมมติให้ IP ของ Nagios server คือ: 10.1.1.1)

only_from = 127.0.0.1 10.1.1.1

7. เพิ่มค่าใน /etc/services

nrpe 5666/tcp # NRPE

8. เปิดการใช้งาน

[client]#service xinetd restart

9. ตรวจสอบว่า nrpe ทำงานอยู่หรือไม่

[client]# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN

10. ตรวจสอบว่า nrpe ทำงานได้ถูกต้องหรือไม่

[client]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

11. ปรับแต่งค่าของ nrpe ที่ /usr/local/nagios/etc/nrpe.cfg

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 80,50 -c 90,90

-------------------------------------------------------------------------------------------------

การติดตั้งที่ Nagios Server

1. Download nrpe จาก http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

2. ติดตั้ง NRPE

[Server]# aptitude install libssl-dev libkrb5-dev zliblg-dev e2fsprogs
[Server]# tar xvfz nrpe-2.12.tar.gz
[Server]# cd nrpe-2.12
[Server]# ./configure
[Server]# make all
[Server]# make install-plugin

3. ตั้งค่า Host และ Service

ที่ /etc/nagios3/conf.d/ ให้เราสร้างไฟล์ host ใหม่ขึ้นมา ตามชื่อของ Client เช่น client.cfg แล้วใส่ค่าลงไป ตัวอย่างเช่น

define host{
use linux-server
host_name client
alias Debian5 Server
address 10.10.10.10
contact_groups admins
}

# Service to check load
define service{
use generic-service
host_name client
service_description Load
notifications_enabled 0
check_command check_nrpe!check_load
}

4. reload การทำงานของ Nagios

[Server]# /etc/init.d/nagios3 reload

5. เมื่อเข้าไปดูที่หน้าจอก็จะพบว่ามี Client เพิ่มขึ้นมาแล้ว ดังรูป