วิธีการติดตั้ง CentOS และ EPEL Repository
OS : CentOS 6.3 Nagios : 3.4.X
1) ติดตั้ง CentOS 6.3
2) ตั้งค่า Network
3) ทำการ Update CentOS ให้ใหม่สุดดังนี้
# yum update
4) ทำการเปิด Repository EPEL โดยโหลดไฟล์จากดังตัวอย่าง ในตัวอย่างเป็น Version 6.8
อาจโหลดไม่ได้ถ้ามี Version ใหม่กว่าออกมา
# wget http://mirrors.thzhost.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
5) ทำการติดตั้ง EPEL rpm ดังนี้
# rpm -ivh epel-release-6-8.noarch.rpm
6) ทำการ Update CentOS อีกครั้ง
Top
วิธีการตั้งค่า Time Sync
1) ติดตั้ง ntpd ดังนี้
# yum install ntp
2) ติดตั้งโปรแกรม vim เพื่อใช้ในการแก้ไขไฟล์ ดังนี้
# yum install vim
3) แก้ไขไฟล์ /etc/ntp.conf ดังนี้
...
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server time.psu.ac.th
server ntp.ku.ac.th
...
4) ทำการ update เวลาให้ตรงก่อน Start Service ntp ดังนี้
# ntpdate time.psu.ac.th
5) ทำการ Start Service ntp และตั้งให้รันตอนเปิดเครื่อง ดังนี้
# service ntpd start
# chkconfig ntpd on
6) คำสั่งสำหรับ Check สถานะการ Sync ต้องรอหลัง Start Service สักพัก * หน้าชื่อ Server
เป็นตัวบอกว่าเป็น Server ที่กำลัง Sync เวลาด้วยล่าสุด (Service จะเลือกเองว่าจะเลือกใช้ Server ไหน)
# ntpq -p
Top
วิธีการปิด selinux และ firewall
1) ทำการแก้ไขไฟล์ /etc/selinux/config ดังนี้
...
# disabled - No SELinux policy is loaded.
# SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
...
2) สั่งปิด service firewall ดังนี้
# service iptables stop
# service ip6tables stop
# chkconfig iptables off
# chkconfig ip6tables off
3) ทำการ Restart เครื่องเพื่อทดสอบ
# reboot
Top
ตัวอย่างวิธีการ เปิด rule โดยไม่ปิด Firewall
แก้ไขไฟล์ /etc/sysconfig/iptables ดังนี้
# Generated by iptables-save v1.4.7 on Mon Feb 18 10:13:39 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:480]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Mon Feb 18 10:13:39 2013
Top
วิธีการติดตั้ง Nagios
1) ติดตั้ง Nagios และสั่งเปิดใช้งานอัตโนมัติที่เปิดเครื่องดังนี้
# yum install nagios
# chkconfig nagios on
# service nagios start
2) สั่ง Start Apache Web Server อัตโนมัติดังนี้
# chkconfig httpd on
# service httpd start
3) ติดตั้ง Plugin ของ Nagios ดังนี้
# yum install nagios-plugins*
4) ทำการตั้งรหัสผ่าน User Nagiosadmin ดังนี้
# htpasswd -c /etc/nagios/passwd nagiosadmin
5) เปิดใช้งาน https ดังนี้
# yum install mod_ssl
# service httpd restart
6) ทำการสร้างไฟล์ /var/www/html/index.html เพื่อให้ Redirect อัตโนมัติเข้าไปยัง /nagios ดังนี้
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Auto Redirect to nagios</title>
<meta http-equiv="REFRESH" content="0;url=https://<server-name>/nagios"></HEAD>
<BODY>
Please Wait.....
</BODY>
</HTML>
7) เพื่อความปลอดภัยให้ปิด Signature เพื่อไม่ให้บอก Version ของ Apache โดยแก้ไขไฟล์ /etc/httpd/conf/httpd.conf ดังนี้
...
# Set to one of: On | Off | EMail
#
#ServerSignature On
ServerSignature Off
#
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
...
8) ทำการ Restart Service Apache ดังนี้
# service httpd restart
Top
ขั้นตอนการเตรียมการติดตั้ง NagiosQL
1) เบื้องต้นต้องทำการติดตั้ง php5 mysql-server
# yum install php mysql-server php-mysql
2) ทำการ config /etc/php.ini ในส่วนของ Timezone ดังนี้
...
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
;date.timezone =
date.timezone = Asia/Bangkok
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-latitude
...
3) ทำการ Start Mysql Server และ ตั้งให้รันอัตโนมัติเมื่อเปิดเครื่อง
# service mysqld start
# chkconfig mysqld on
4) ทำการตั้ง password root mysql-server ดังนี้ (ไม่แนะนำให้ใช้ mysqladmin เพราะจะค้างอยู่ใน history
4.1) เข้าไปยัง mysql console ดังนี้
# mysql -u root
4.2) ทำการตั้งรหัสผ่าน ดังนี้ (ระวัง password มี ‘ ให้ใส่ \’ ถ้าจะตั้ง password ที่มี ‘)
mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret_password');
5) สร้าง directory ดังนี้
# mkdir /etc/nagiosql
# mkdir /etc/nagiosql/hosts
# mkdir /etc/nagiosql/services
# mkdir /etc/nagiosql/backup
# mkdir /etc/nagiosql/backup/hosts
# mkdir /etc/nagiosql/backup/services
6) เปลี่ยนเจ้าของ directory ข้างต้นเป็น [webserver_account].nagios ดังนี้
# chown -R apache.nagios /etc/nagiosql
7) ทำการเปลี่ยน Owner ของ Config nagios ให้เป็นดังนี้
# chown -R apache:nagios /etc/nagios/nagios.cfg
# chown -R apache:nagios /etc/nagios/cgi.cfg
# chown -R apache.nagios /var/spool/nagios/cmd/nagios.cmd
# chmod 640 /etc/nagios/nagios.cfg
# chmod 640 /etc/nagios/cgi.cfg
# chmod 660 /var/spool/nagios/cmd/nagios.cmd
8) สร้าง directory เพิ่มเติมดังนี้
# mkdir /opt/nagiosql
# chown apache /opt/nagiosql
9) ทำการสร้างไฟล์ apache config สำหรับ nagiosql ดังนี้
# touch /etc/httpd/conf.d/nagiosql.conf
10) ทำการแก้ไขไฟล์ /etc/httpd/conf.d/nagiosql.conf โดยเพิ่มข้อความดังนี้
Alias /nagiosql "/opt/nagiosql"
<Directory "/opt/nagiosql">
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "NagiosQL Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</Directory>
11) ทำการติดตั้ง extension ssh2 ดังนี้
# yum install php-pecl-ssh2
12) ทำการ Restart Apache อีกรอบ
# service httpd restart
13) ทำการโหลดโปรแกรมตาม URL ดังนี้
# cd /opt
# wget http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
14) แตกไฟล์วางใน /opt/nagiosql ดังนี้
# gunzip -c nagiosql_320.tar.gz | tar -xf -
# cd nagiosql32
# mv * ../nagiosql
# cd ..
# rm -rf nagiosql32
# chown -R apache /opt/nagiosql
# chmod 750 /opt/nagiosql/config
Top
วิธีการติดตั้ง NagiosQL
1) เปิด Web Browser https://nagios.in.psu.ac.th/nagiosql เพื่อเข้าสู่หน้าติดตั้ง
2) กดปุ่ม START INSTALLATION เพิ่มไปยังหน้าถัดไป
3) ตรวจสอบหน้า Checking requirements ถ้าพบข้อความ Environment test completed successfully ให้กดปุ่ม Next
4) ในหน้า Setup ให้ทำการกรอกข้อมูล User Password Mysql-Server รวมถึง User Password ตั้งต้นของ NagiosQL
5) จากนั้นกด Finish
6) ทำการลบ directory install ทิ้ง
*หมายเหตุ พบว่าระหว่างติดตั้ง แต่การใช้งานถ้ารหัสผ่านมี ‘ จะลงไม่ผ่าน
7) หลังจากนั้นทำการ Login เข้าไปในหัวข้อ Admnistrator->Config targets
8) แก้ Path ของ Nagios ดังนี้
Nagios command file : /var/spool/nagios/cmd/nagios.cmd
Nagios binary file : /usr/sbin/nagios
Nagios process file : /var/run/nagios.pid
Nagios config file : /etc/nagios/nagios.cfg (เหมือนเดิม)
Top
วิธีการติดตั้ง NagiogGraph
1) เปิด Web Browser http://nagiosgraph.sourceforge.net/ เพื่อโหลดโปรแกรม
# cd /tmp
# wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz
2) แตกไฟล์ zip ออกมาดังนี้
# tar -xvzf /nagiosgraph-1.4.4.tar.gz
# cd nagiosgraph-1.4.4
3) ติดตั้ง Perl-GD และ Perl-CGI ดังนี้
# yum install perl-GD perl-CGI
4) ทำการตรวจสอบโปรแกรมที่ต้องการสำหรับการติดตั้ง ดังนี้
# ./install.pl --check-prereq
5) ทำการติดตั้งโปรแกรม nagiosgraph ดังนี้
# ./install.pl --install
* Enter ไปเรื่อย ๆ ให้แก้เฉพาะในส่วนของ username or userid of Nagios user? [nagios] เป็น user ที่ใช้งานจริง
6) ทำการแก้ไขไฟล์ /etc/nagios/nagios.cfg โดยเพิ่มท้ายไฟล์ดังนี้
# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/tmp/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
7) ทำการเพิ่ม command ใน web nagiosql ให้รันคำสั่งดัง config ไฟล์นี้
define command {
command_name process-service-perfdata-for-nagiosgraph
command_line /usr/local/nagiosgraph/bin/insert.pl
}
8) ทำการเพิ่มท้ายไฟล์ /etc/httpd/config/httpd.conf ให้ include config ไฟล์นี้
include /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf
9) ทำการสร้าง Service ชื่อ nagiosgraph ใน web nagiosql โดยไฟล์ config มีข้อความประมาณนี้
define service {
name nagiosgraph
action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
register 0
}
10) เพิ่ม Service ดังกล่าวไปยังเครื่องที่ต้องการ
Top