Nagios installation Made-EASY
วิภัทร ศรุติพรหม wipat.s@psu.ac.th
ประวัติการปรับปรุง
ครั้งที่ 0.3 21-07-2547 โดย: วิภัทร
เป็นคำแนะนำติดตั้งโปรแกรม nagios
ต้นแบบทดสอบด้วย linux fedora core 2 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์
วิธีติดตั้ง mrtg
- ดาวน์โหลดโปรแกรมติดตั้งได้จาก ftp://ftp.psu.ac.th/pub/nagios
fedora core 2 ftp://ftp.psu.ac.th/pub/nagios/nagios-1.2-0.1.fc2.dag.i386.rpm
fedora core 1 ftp://ftp.psu.ac.th/pub/nagios/nagios-1.2-0.rhfc1.dag.i386.rpm
redhat 9.0 ftp://ftp.psu.ac.th/pub/nagios/nagios-1.2-0.rh90.dag.i386.rpm
plugins ftp://ftp.psu.ac.th/pub/nagios/nagios-plugins-1.3.1-1.9.i386.rpm
radiusclient ftp://ftp.psu.ac.th/pub/nagios/radiusclient-0.3.1-1.i386.rpm
extra plugins ftp://ftp.psu.ac.th/pub/nagios/nagios-plugins-extras-1.3.1-1.9.i386.rpm
- ให้ติดตัั้งด้วยคำสั่งตัวอย่างสำหรับ fedora core 2
[root@myhost root]# rpm -Uvh nagios-1.2-0.1.fc2.dag.i386.rpm
Preparing...
########################################### [100%]
1:nagios
########################################### [100%]
[root@myhost root]# rpm -Uvh nagios-plugins-1.3.1-1.9.i386.rpm
Preparing...
########################################### [100%]
1:nagios-plugins ########################################### [100%]
[root@myhost root]# rpm -Uvh radiusclient-0.3.1-1.i386.rpm
Preparing...
########################################### [100%]
1:radiusclient
########################################### [100%]
[root@host root]# rpm -Uvh nagios-plugins-extras-1.3.1-1.9.i386.rpm
Preparing...
########################################### [100%]
1:nagios-plugins-extras ########################################### [100%]
- ตำแหน่งของแฟ้มที่สำคัญของ nagios
- ตัวอย่างเอกสารคู่มืออยู่ที่ http://myhost/nagios
- แฟ้มที่เกี่ยวข้องกับ httpd คือ /etc/httpd/conf.d/nagios.conf
- แฟ้มที่เกี่ยวข้องกับโปรแกรมย่อยๆในการตรวจสอบข้อมูลอยู่ที่ /usr/lib/nagios/plugins
- แฟ้มปรับแต่งข้อมูลอยู่ที่ /etc/nagios
- การปรับแก้ไขแฟ้ม /etc/nagios/nagios.conf
- แก้ไขแฟ้ม /etc/httpd/conf.d/nagios.conf เพื่ออนุญาติให้ browser จากเครื่องอื่นๆเข้าไปอ่านได้
ด้วยการเพิ่มข้อความบรรทัดตัวอย่างเช่น
ถ้าต้องการให้อ่านได้ทั้งหมด คือ allow from all
ถ้าต้องการให้อ่านได้ทั้ง network 192.168.30.0 คือ allow from 192.168.30.0/24
ถ้าต้องการให้อ่านได้เฉพาะ ip 192.168.30.6 คือ allow from 192.168.30.6
เมื่อแก้ไขแล้วให้ restart nagios ใหม่ เพื่อให้ httpd รู้จัก nagios ด้วยคำสั่ง
/etc/init.d/httpd reload
- แก้ไขแฟ้ม /etc/nagios/nagios.cfg ให้มีข้อมูลดังนี้
log_rotation_method=w
** เพื่อให้ log rotate ทำงานทุกสัปดาห์
date_format=euro
** เพื่อให้แสดงผลวันที่เป็น วัน-เดือน-ปี
- แก้ไขแฟ้ม /etc/nagios/hosts.cfg
define host{
use
generic-host
; Name of host template to use
host_name myweb
alias My Server
address myserver.mydomain
check_command check-host-alive
max_check_attempts 10
notification_interval 480
notification_period 24x7
notification_options d,u,r
}
- แก้ไขแฟ้ม /etc/nagios/hostsgroup.cfg
define hostgroup{
hostgroup_name server-boxes
alias
My Application Servers
contact_groups app-admins
members myweb
}
- แก้ไขแฟ้ม /etc/nagios/services.cfg
define service{
use
generic-service ; Name
of service template to use
host_name myweb
service_description HTTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 2
** ตรวจสอบทุกประมาณ 2 นาที
retry_check_interval 1
contact_groups app-admins
notification_interval 240
notification_period 24x7
notification_options w,u,c,r
check_command
"/usr/lib/nagios/plugins/check_http host.psu.ac.th -u /nagios/"
}
- แก้ไขแฟ้ม /etc/nagios/contacts.cfg
define contact{
contact_name apps
alias
Application Service Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options c,r
host_notification_options d,u,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email
youremail@your.domain
}
- แก้ไขแฟ้ม /etc/nagios/contactgroups.cfg
define contactgroup{
contactgroup_name app-admins
alias
Linux Administrators
members apps
}
- แก้ไขแฟ้ม /etc/nagios/cgi.cfg
use_authentication=0
** เพื่ออนุญาติให้ทุกคนดูได้โดยไม่ต้องขออนุญาติ
xedtemplate_config_file=/etc/nagios/hostextinfo.cfg
** เพื่อเชื่อมไปยังแฟ้ม hostextinfo.cfg ที่แสดงภาพเพื่อความสวยงาม
default_statusmap_layout=2
** เพื่อเลือกรูปแบบการแสดงผลภาพกราฟฟิก
- ทดสอบ configuration file ด้วยคำสั่ง
nagios -v /etc/nagios/nagios.cfg
- สั่งให้ nagios ทำงานด้วยคำสั่ง
/etc/init.d/nagios start
- แก้ไขแฟ้ม /etc/nagios/hostextinfo.cfg เพื่อแสดงภาพเพื่อความสวยงาม ดังตัวอย่าง
define hostextinfo{
host_name myweb
icon_image linux_server.png
icon_image_alt linux Redhat 9.0
vrml_image linux_server.png
statusmap_image linux_server.gd2
}
** โดยรูปภาพที่แสดงอ้างอิงเก็บไว้ที่ /usr/share/nagios/images/logos