Tag: nagiosql

  • วิธีการตั้งค่า NRPE เพื่อใช้งานกับ NagiosQL บน Ubuntu 14.04 LTS

    สำหรับการใช้งาน NRPE ต้องทำการติดตั้ง Nagios และ NagiosQL มาก่อนดังนี้
    Nagios : http://sysadmin.psu.ac.th/2014/07/23/nagios-ubuntu1404/
    NagiosQL : http://sysadmin.psu.ac.th/2014/07/23/nagiosql-ubuntu/
    Setup NagiosQL : http://sysadmin.psu.ac.th/2014/07/23/setup-nagiosql-ubuntu/

    วิธีการติดตั้ง Nrpe และการตั้งค่าบน NagiosQL

    1) ทำการติดตั้งโปรแกรม nrpe ดังนี้

    sudo apt-get install -y nagios-nrpe-plugin

    2) ทำการ Login เข้า Web NagiosQL โดยจะยกตัวอย่างการเพิ่ม nrpe เกี่ยวกับการ Check Load Linux

    3) ทำการเพิ่ม command ใหม่ดังนี้

    Commands -> Definitions

    2014-07-24_045128

    Command : check_linux_load
    Command line : $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_load
    Command type : check command

    2014-07-24_052707

    4) ทำการเพิ่มข้อมูล Service ให้กับ Host ชื่อ Linux-Server

    Supervision -> Services

    2014-07-23_230036

    5) ทำการตั้งค่า Service โดยคราวนี้จะเลือก Add Service เพิ่มเข้าไปใน Host groups linux-server แทน เมื่อเพิ่มเครื่องเข้าไปใน Host groups จะได้ service นี้ติดไปด้วยเสมอ (เป็นการบังคับว่าต้องลง nrpe agent ไม่งั้นจะฟ้องว่า service down)

    2014-07-24_053553

    6) ทำการเพิ่ม เครื่อง Linux-Server ใน Host Groups -> linux servers โดยให้เอา localhost ออกจาก Host Groups ด้วย (กันความสับสน)

    2014-07-24_055017

    7) จากนั้นทำ Save และทดสอบ เข้าไป Restart Nagios

    Tools -> Nagios control -> Check Written configuration files

    8) หลังจากนั้นทดสอบเข้า web nagios ดูจะพบว่า Service CPU Load เพิ่มขึ้นมาเรียบร้อยแล้ว

    ตอนนี้ยังไม่สามารถใช้งานได้ต้องทำการลง Agent ที่เครื่อง Linux ปลายทางก่อนซึ่งจะอยู่ในหัวข้อต่อไป ในส่วนของ Windows วิธีการจะคล้าย ๆ กัน ต่างกันที่ Command ซึ่งจะเป็นการเรียกเพื่อรันโปรแกรมที่อยู่ปลายทาง ซึ่งแต่ละ Command อาจต้องใส่ argument ซึ่งบาง command สามารถแก้ที่ตัวปลายทางได้เลย ทำให้ command เดียวกันแต่ตั้งค่า warning critical ที่แตกต่างได้ แล้วแต่ปลายทางจะตั้ง

  • วิธีการตั้งค่าและการใช้งาน NagiosQL บน Ubuntu 14.04 LTS

    สามารถอ่านวิธีติดตั้ง NagiosQL บน Ubuntu 14.04 LTS ได้ที่
    http://sysadmin.psu.ac.th/2014/07/23/nagiosql-ubuntu/

    หลังจากการติดตั้งจะต้องมีการตั้งค่าให้สามารถควบคุม Nagios ได้ดังนี้

    วิธีการตั้งค่า Nagiosql configuration

    1) หลังจาก Login ให้ทำการเข้าไปแก้ไข config path ดังนี้

    Administrator -> Config targets -> Configuration directories
    Nagios base directory -> /etc/nagios3
    Import Directory -> /etc/nagios3/conf.d
    
    Nagios command file -> /var/lib/nagios3/rw/nagios.cmd
    Nagios binary file -> /usr/sbin/nagios3
    Nagios process file -> /var/run/nagios3/nagios3.pid
    Nagios config file -> /etc/nagios3/nagios.cfg
    

    2) จากนั้นทำการ save config โดยการกดปุ่ม Save ตามรูป

    3) หลังจากทำการ save จะปรากฎข้อความดังรูป

    2014-07-23_200526

    4) ทำการแก้ไขไฟล์ของ nagios ให้มาเรียก configuration ของ nagiosql (ยกเว้น nagios config, cgi config ที่ยังใช้ของ nagios อยู่ เนื่องจากเป็น config ของโปรแกรม nagios)

    Tools -> Nagios config -> Nagios main configuration file

    5) ทำการเพิ่มข้อความดังภาพ

    ...
    
    log_file=/var/log/nagios3/nagios.log
    
    cfg_file=/etc/nagiosql/contacttemplates.cfg
    cfg_file=/etc/nagiosql/contactgroups.cfg
    cfg_file=/etc/nagiosql/contacts.cfg
    cfg_file=/etc/nagiosql/timeperiods.cfg
    cfg_file=/etc/nagiosql/commands.cfg
    cfg_file=/etc/nagiosql/hostgroups.cfg
    cfg_file=/etc/nagiosql/servicegroups.cfg
    
    cfg_dir=/etc/nagiosql/hosts
    cfg_dir=/etc/nagiosql/services
    
    cfg_file=/etc/nagiosql/hosttemplates.cfg
    cfg_file=/etc/nagiosql/servicetemplates.cfg
    cfg_file=/etc/nagiosql/servicedependencies.cfg
    cfg_file=/etc/nagiosql/serviceescalations.cfg
    cfg_file=/etc/nagiosql/hostdependencies.cfg
    cfg_file=/etc/nagiosql/hostescalations.cfg
    cfg_file=/etc/nagiosql/hostextinfo.cfg
    cfg_file=/etc/nagiosql/serviceextinfo.cfg
    
    # Commands definitions
    #cfg_file=/etc/nagios3/commands.cfg
    
    # Debian also defaults to using the check commands defined by the debian
    # nagios-plugins package
    #cfg_dir=/etc/nagios-plugins/config
    
    # Debian uses by default a configuration directory where nagios3-common,
    # other packages and the local admin can dump or link configuration
    # files into.
    #cfg_dir=/etc/nagios3/conf.d
    
    ...

    6) ทำการแก้ค่า check_external_command จาก 0 เป็น 1 ดังนี้

    ...
    
    # EXTERNAL COMMAND OPTION
    # This option allows you to specify whether or not Nagios should check
    # for external commands (in the command file defined below). By default
    # Nagios will *not* check for external commands, just to be on the
    # cautious side. If you want to be able to use the CGI command interface
    # you will have to enable this.
    # Values: 0 = disable commands, 1 = enable commands
    
    check_external_commands=1
    
    ...

    7) จากนั้นทำการ save config โดยการกดปุ่ม Save ตามรูป

    2014-07-23_203407

    8) เนื่องจาก Nagios มี config ของตัวเองอยู่แล้ว ให้ทำการ Import Data ของ Nagios มาไว้ด้วยดังนี้

    8.1) ทำการ Import Data จาก /etc/nagios3/conf.d ซึ่งได้ตั้งค่า Import directory ไว้แล้วตามข้อ 1)

    Tools -> Data import -> Configuration Import

    – จากนั้นทำการ กดปุ่ม Import ดังรูป

    8.2) ทำการ Import Data จาก /etc/nagios-plugins/config ซึ่งต้องทำการตั้งค่า Import directory ใหม่ดังรูป

    – จากนั้นทำการ กดปุ่ม Import ดังรูป

    Administrator -> Config targets -> Configuration directories

    2014-07-23_204140– จากนั้นกลับไป Import Data อีกครั้งดังนี้

    Tools -> Data import -> Configuration Import

    – จากนั้นทำการ กดปุ่ม Import ดังรูป

    2014-07-23_204610

    9) จากนั้นทำการ Save ข้อมูลจากฐานข้อมูลทั้งหมดลง config file และทำการทดสอบ config และสั่ง Restart nagios ดังรูป

    Tools -> Nagios control -> Check Written configuration files

    2014-07-23_214921

    10) ทดสอบเข้า web nagios เพื่อตรวจสอบผลการ Import configuration

    การตั้งค่า Alert mail

    1) ทำการแก้ไข Contact name : nagiosadmin

    Alerting -> Contact data

    2014-07-23_222435

    2) ทำการเพิ่มข้อมูลดังรูป โดยรายละเอียกที่ต้องการให้ส่งสามารถเลือกได้ที่ Host command และ Service command สำหรับ profile default ของ nagiosadmin จะส่งทั้งหมด

    2014-07-23_222616

    การเพิ่ม Host

    1) ทำการเพิ่มข้อมูล Host

    Supervision -> Host

    2014-07-23_223609

    2) ทำการตั้งค่าทั่วไปและทำการเลือก Host Template ทำให้เราไม่ต้องตั้งค่าเยอะ เพราะจะ Inherite มาจาก Template

    2014-07-23_224822

    3) ทำการตั้งค่าในกรณีที่ต้องการแสดงข้อมูลเพิ่มเติมในกรณีเครื่องมีปัญหาให้ติดต่อใคร

    2014-07-23_224927
    4) จากนั้นทำ Save และทดสอบ เข้าไป Restart Nagios

    Tools -> Nagios control -> Check Written configuration files

    จะพบว่าในขั้นตอน Check configuration files มีข้อความฟ้องเป็น Warning ว่า Linux-Server ยังไม่มี Service ให้ทำการเพิ่ม Service ให้กับ Host ในขั้นตอนต่อไป

    การเพิ่ม Service

    1) ทำการเพิ่มข้อมูล Service ให้กับ Host ชื่อ Linux-Server

    Supervision -> Services

    2014-07-23_230036

    2) ทำการตั้งค่าทั่วไปและทำการเลือก Service Template เพื่อดึงค่าต่าง (Monitor Period, Retry, Interval ฯลฯ) โดยเฉพาะเมื่อติดตั้ง NagiosGraph จะทำที่ Template ที่เดียวจะสามารถขึ้น Graph ให้กับทุก Service โดยไม่ต้องไปไล่ใส่ทุก Service

    2014-07-23_230809

    3) จากนั้นทำ Save และทดสอบ เข้าไป Restart Nagios

    Tools -> Nagios control -> Check Written configuration files

    จะพบว่าจะไม่มี Warning ฟ้องแล้ว ให้ลองใช้งานดูครับ ตัว NagiosQL จริง ๆ ก็คือเป็นแค่ Web ที่เขียน config แทนที่เราจะต้องแก้ไขด้วยมือ Function การใช้งานก็เหมือน Nagios ปกติแต่จะสบายกว่าในกรณีที่มีเครื่องเยอะ ๆ แล้วจะติดใจครับ ^ ^

  • การติดตั้ง NagiosQL บน Ubuntu 14.04 LTS

    สำหรับการติดตั้ง NagiosQL ต้องการทำการติดตั้ง PHP5 และ Mysql-Server ก่อนครับ

    วิธีการติดตั้ง PHP5, MySQL 5.5

    1) ทำการติดตั้ง Apache ผ่าน apt-get ดังนี้ครับ

    sudo apt-get install -y php5 mysql-server php5-mysql 
    

    2) จะปรากฎข้อความถามว่าจะให้ตั้งรหัสผ่าน root ให้ใส่รหัสผ่านที่ต้องการ

    3) จากนั้นให้สั่ง Restart Apache ตามปกติ

    sudo service apache2 restart

    4) ทำการแก้ไขไฟล์ /etc/php5/apache2/php.ini เพื่อแก้ไข timezone ดังนี้

    sudo nano /etc/php5/apache2/php.ini

    5) ทำการเพิ่มข้อความในส่วนของ [Date] ดังนี้ (ประมาณบรรทัดที่  879)

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    ;date.timezone =
    date.timezone = Asia/Bangkok

    6) จากนั้นให้สั่ง Restart Apache อีกครั้ง

    sudo service apache2 restart

    ขั้นตอนการเตรียมการติดตั้ง NagiosQL

    1) ทำการ Download โปรแกรม 3 File ดังนี้

    cd /usr/src

    Download Nagios 3.2.0 Main File

    sudo wget http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz

    Nagios 3.2.0 Service Pack 1

    sudo wget http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320_service_pack_1_additional_fixes_only.zip

    Nagios 3.2.0 Service Pack 2

    sudo wget http://downloads.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320_service_pack_2_additional_fixes_only.zip

    2) ทำการแตกไฟล์ทั้ง 3 ไฟล์ ดังนี้

    sudo tar -xvzf nagiosql_320.tar.gz
    sudo unzip nagiosql_320_service_pack_1_additional_fixes_only.zip
    sudo unzip nagiosql_320_service_pack_2_additional_fixes_only.zip

    3) ทำการสร้าง folder nagiosql และ copy ไฟล์ทั้งหมดไปใส่ดังนี้

    sudo mkdir /var/www/html/nagiosql
    sudo cp -R /usr/src/nagiosql32/* /var/www/html/nagiosql/
    sudo cp -R /usr/src/NagiosQL_3.2.0_SP1/* /var/www/html/nagiosql/
    sudo cp -R /usr/src/NagiosQL_3.2.0_SP2/* /var/www/html/nagiosql/

    4) ทำการสร้าง directory สำหรับ เก็บ config ไฟล์ดังนี้

    sudo mkdir /etc/nagiosql
    sudo mkdir /etc/nagiosql/hosts
    sudo mkdir /etc/nagiosql/services
    sudo mkdir /etc/nagiosql/backup
    sudo mkdir /etc/nagiosql/backup/hosts
    sudo mkdir /etc/nagiosql/backup/services

    5) ทำการแก้ Permission และ Owner ในแต่ละ Folder ดังนี

    Nagios configuration

    sudo chgrp www-data /etc/nagios3
    sudo chgrp -R www-data /var/lib/nagios3
    sudo chgrp -R www-data /var/run/nagios3
    sudo chgrp www-data /etc/nagios3/nagios.cfg 
    sudo chgrp www-data /etc/nagios3/cgi.cfg
    sudo chgrp www-data /etc/nagios3/resource.cfg
    sudo chmod 775 /etc/nagios3
    sudo chmod -R 775 /var/lib/nagios3
    sudo chmod g+s /var/lib/nagios3/rw
    sudo chmod 664 /etc/nagios3/nagios.cfg
    sudo chmod 664 /etc/nagios3/cgi.cfg
    sudo chmod 664 /etc/nagios3/resource.cfg
    sudo usermod -G nagios www-data

    NagiosQL configuration

    sudo chmod 6755 /etc/nagiosql
    sudo chown www-data.nagios /etc/nagiosql
    sudo chmod 6755 /etc/nagiosql/hosts
    sudo chown www-data.nagios /etc/nagiosql/hosts
    sudo chmod 6755 /etc/nagiosql/services
    sudo chown www-data.nagios /etc/nagiosql/services
    

    NagiosQL backup configuration

    sudo chmod 6755 /etc/nagiosql/backup
    sudo chown www-data.nagios /etc/nagiosql/backup
    sudo chmod 6755 /etc/nagiosql/backup/hosts
    sudo chown www-data.nagios /etc/nagiosql/backup/hosts
    sudo chmod 6755 /etc/nagiosql/backup/services
    sudo chown www-data.nagios /etc/nagiosql/backup/services
    

    Nagios Permission

    sudo chgrp www-data /etc/nagios3
    sudo chgrp www-data /etc/nagios3/nagios.cfg
    sudo chgrp www-data /etc/nagios3/cgi.cfg
    sudo chmod 775 /etc/nagios3
    sudo chmod 664 /etc/nagios3/nagios.cfg
    sudo chmod 664 /etc/nagios3/cgi.cfg
    
    

    NagiosQL for setup config

    sudo chown -R www-data:www-data /var/www/html/nagiosql

    6) ทำการติดตั้ง php extension เพิ่มเติมดังนี้

    sudo apt-get install libssh2-1-dev libssh2-php

    การติดตั้ง NagiosQL ผ่าน Web Browser

    1) เริ่มขั้นตอนการติดตั้งผ่าน Web ทำการเปิด URL ดังนี้

    https://localhost/nagiosql

    – กดปุ่ม Start Installation

    2014-07-23_111928

    2) หลังจากนั้นระบบจะตรวจสอบความพร้อม ถ้าระบบพร้อมแล้วจะปรากฎดังภาพ

    2014-07-23_135438

    3) จากนั้นกด Next จะปรากฎหน้าต่างตั้งค่าเกี่ยวกับฐานข้อมูล ให้ใส่ข้อมูลดังภาพ

    2014-07-23_142113

    4) จากนั้นจะปรากฎหน้าจอแสดงผลการติดตั้ง ดังนี้

    2014-07-23_142256

    5) ทำการลบ installation folder ดังนี้

    sudo rm -rf /var/www/html/nagiosql/installation

    6) ทำการกด Finish หรือเข้า URL ใหม่ดังนี้

    https://localhost/nagiosql

    7) ทำการ Login โดยใช้ Username Password ที่ตั้งไว้ดังรูป

    2014-07-23_142756

    สามารถอ่านต่อไปในส่วนของการตั้งค่าให้สามารถควบคุม Nagios ได้ที่นี่
    http://sysadmin.psu.ac.th/2014/07/23/setup-nagiosql-ubuntu

  • WorkShop : Server Monitoring

    “อาว Server ตายตอนไหนไม่เห็นจะรู้เลย โหลดเยอะละม้าง หรือไม่ก็แรมหมด เสถียรไหมไม่รู้สิ อาวเมื่อคืน disk หมดหรอกเหรอ สงสัย Backup อยู่ม้าง”

    ถ้าเรามีระบบ Monitor ที่ดีพบคงสามารถตอบคำถามเหล่านี้ได้ง่ายขึ้น
    และไม่ต้องเจอเหตุการณ์เดิม ๆ ซ้ำ ๆ อีกต่อไป

    มาถึงอีก 1 workshop เคยเขียนไปแล้วรอบหนึ่ง แต่ตอนนั้นสอนแค่ครึ่งวัน ได้แค่ลง Nagiosql ยังไม่ได้ทำอะไรเป็นชิ้นเป็นอันสักเท่าไหร่ รอบนี้เลยจัดเต็ม 2 วัน ถ้ามีเนื้อหาผิดพลาดประการใดแจ้งได้เลยครับ เดี๋ยวจะแก้ไขให้ครับ (งานร้อน ^.^)

    Workshop Outline
    ftp://ftp.psu.ac.th/pub/psu-monitor/workshop-outline.pdf

    VirtualBox Installation

    เครื่องที่ใช้ในการทดสอบ (Oracle VM VirtualBox)
    *แนะนำให้เปิดกับโปรแกรม version ล่าสุด
    Monitor
    ** User : workshop , Password : 123456
    Linux-Server
    ** User : monitor , Password : 123456
    MS-Server
    ** User : administrator, Password : 123456

    รายละเอียด URL
    Monitor
    Linux-Server
    MS-Server
    http://ftp.psu.ac.th/pub/psu-monitor/workshop.ova

    โดยจะแบ่งเป็น 11 ตอนโดยแยกเป็น 11 Blog ดังนี้

    ตอนที่ ชื่อตอน
    ตอนที่ 1 การติดตั้งและการตั้งค่าเบื้องต้น Nagios บน Ubuntu 14.04 LTS
    ตอนที่ 2 การติดตั้ง NagiosQL บน Ubuntu 14.04 LTS
    ตอนที่ 3 วิธีการตั้งค่าและการใช้งาน NagiosQL บน Ubuntu 14.04 LTS
    ตอนที่ 4 การติดตั้งและการตั้งค่าเบื้องต้น NagiosGraph บน Ubuntu 14.04 LTS
    ตอนที่ 5 วิธีการตั้งค่า NRPE เพื่อใช้งานกับ NagiosQL บน Ubuntu 14.04 LTS
    ตอนที่ 6 การติดตั้ง NRPE บน Ubuntu 14.04
    ตอนที่ 7 การติดตั้ง NRPE บน Windows 2012 R2
    ตอนที่ 8 การติดตั้งโปรแกรมและการตั้งค่าเบื้องต้น Cacti บน Ubuntu 14.04 LTS
    ตอนที่ 9 การติดตั้ง snmpd และการตั้งค่า shorewall บน Ubuntu 14.04 LTS
    ตอนที่ 10 การติดตั้ง snmp service และการตั้งค่า firewall บน Windows 2012 R2
    ตอนที่ 11 เรียนรู้วิธีการใช้งาน Cacti เพื่อ Monitor Server
    บทความเพิ่มเติม
    ยังไม่มี

     

  • การติดตั้งโปรแกรมชุด Monitor Server (CentOS 6 + Epel + NRPE + NagiosQL + NagiosGraph)

    เนื้อหา

    วิธีการติดตั้ง 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