Tag: nagios

  • การติดตั้ง NRPE บน Windows 2012 R2

    เพื่อไม่ให้เสียเวลามาเริ่มกันเลยครับ

    วิธีการติดตั้ง Nrpe บน Windows 2012 R2

    1) Download โปรแกรม Winnrpe ดังนี้ (Version นี้มีช่องโหว่ Heartbleed แนะนำว่าลง Firewall ด้วยอีกชั้น)

    https://www.itefix.net/sites/default/files/winrpe_4.2.0_Installer.zip

    2) ทำการติดตั้งโปรแกรม โดย Next ไปเรื่อย ๆ ระหว่างติดตั้งจะมีการสร้าง User ขึ้นมา พยายามอย่าไปตั้ง Password เอง เดี๋ยว Service จะมีปัญหา Start ไม่ขึ้น

    2014-07-24_063706

    3) ให้เข้าไป ตั้งค่า Services ให้ Start ทุกครั้งหลังจากเปิดเครื่องดังรูป2014-07-24_064105 2014-07-24_064157

    4) ลองทดสอบให้ nagios เข้ามาดึงค่าได้เลย

    * สามารถดูคำสั่งหรือแก้ไข nrpe config ได้ที่

    C:\Program Files (x86)\ICW\nrpe.cfg

    5) ให้ทำการเปิด Firewall ดังนี้

    2014-07-24_065342 2014-07-24_065429 2014-07-24_065503

    จบแล้วครับสำหรับ การติดตั้ง nrpe บน windows แต่การใช้งานจริง จะมีในเรื่องของ script ครับว่าใช้อย่างไร จะมีทั้ง check cpu, mem, disk,service, process ซึ่งจะมีน้อยกว่า linux แต่ก็ครบถ้วนในระดับหนึ่งครับ

  • วิธีการตั้งค่า 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 ที่แตกต่างได้ แล้วแต่ปลายทางจะตั้ง

  • การติดตั้งและการตั้งค่าเบื้องต้น NagiosGraph บน Ubuntu 14.04 LTS

    สำหรับการติดตั้ง NagiosGraph ต้องทำการติดตั้ง 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/

    วิธีการติดตั้ง Nagios Graph

    1) ทำการติดตั้งโปรแกรม Perl-GD Perl-RRDs และ Perl-Nagios รวมถึงโปรแกรม rrdtool ดังนี้

    sudo apt-get install -y rrdtool libgd-perl librrds-perl libnagios-object-perl

    2) ทำการ Download  โปรแกรม NagiosGraph ดังนี้

    cd /usr/src
    sudo wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.1/nagiosgraph-1.5.1.tar.gz

    3) จากนั้นทำการแตกไฟล์ออกมาด้วยคำสั่ง

    sudo tar -xvzf nagiosgraph-1.5.1.tar.gz

    4) จากนั้นทำการตรวจสอบความพร้อมก่อนติดตั้งด้วยคำสั่ง

    cd nagiosgraph-1.5.1
    sudo ./install.pl --check-prereq

    5) ถ้าไม่มี Error อะไรให้ทำการติดตั้งโดยใช้คำสั่ง

    sudo ./install.pl --install

    6) Enter ไปเรื่อย ๆ ก็จะเสร็จสิ้นกระบวนการติดตั้ง (แต่ยังต้องมีการตั้งค่า nagios ต่อไป)

    วิธีการตั้งค่า Config nagios เพื่อเปิดใช้งานตัวเก็บ Log

    1) ทำการเปิด NagiosQL ขึ้นมา หรือทำการแก้ไขไฟล์ /etc/nagios3/nagios.cfg

    2) ทำการแก้ไขไฟล์ของ nagios ให้มาเรียก configuration ของ nagiosql ดังนี้

    Tools -> Nagios config -> Nagios main configuration file

    3) เพิ่มข้อความบรรทัดสุดท้ายดังนี้

    # 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

    4) จากนั้นทำการ Save ข้อมูลและสั่ง Restart nagios ดังรูป

    Tools -> Nagios control -> Check Written configuration files

    2014-07-23_214921

    5) เราสามารถตรวจสอบการทำงานได้ดังนี้ (กด Ctrl-C เพื่อยกเลิกการทำงาน)

    sudo tail -f /tmp/perfdata.log

    6) ถ้ามีการเคลื่อนไหวของข้อมูลถือว่าใช้งานได้

    วิธีการตั้งค่า services ผ่าน NagiosQL

    1) ทำการแก้ไขข้อมูล Service Template ดังนี้

    Supervision -> Service templates

    2014-07-24_040615

    2) ทำการแก้ไข Action URL เพื่อให้สามารถคลิกดูกราฟได้จากหน้า Nagios ดังนี้

    Action URL : /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$

    2014-07-24_041023

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

    Commands -> Definitions

    2014-07-24_045128

    Command : process-service-perfdata-for-nagiosgraph
    Command line : /usr/local/nagiosgraph/bin/insert.pl

    2014-07-24_045234

    4) จากนั้นทำการ Save ข้อมูลและสั่ง Restart nagios เหมือนเดิม

    Tools -> Nagios control -> Check Written configuration files

    วิธีการตั้งค่า Apache Site

    1) ทำการ copy site config ดังนี้

    sudo cp /usr/local/nagiosgraph/etc/nagiosgraph-apache.conf /etc/apache2/sites-available/

    2) ทำการ enable site ขึ้นมาดังนี้

    sudo a2ensite nagiosgraph-apache

    3) เนื่องจากเป็น Apache ใหม่จำเป็นต้องเพิ่ม Require all granted ใน Site config ดังนี้

    sudo nano /etc/apache2/sites-available/nagiosgraph-apache.conf
    # enable nagiosgraph CGI scripts
    ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"
    <Directory "/usr/local/nagiosgraph/cgi">
     Options ExecCGI
     AllowOverride None
     Order allow,deny
     Allow from all
     Require all granted
    # AuthName "Nagios Access"
    # AuthType Basic
    # AuthUserFile NAGIOS_ETC_DIR/htpasswd.users
    # Require valid-user
    </Directory>
    # enable nagiosgraph CSS and JavaScript
    Alias /nagiosgraph "/usr/local/nagiosgraph/share"
    <Directory "/usr/local/nagiosgraph/share">
     Options None
     AllowOverride None
     Order allow,deny
     Allow from all
      Require all granted
    </Directory>

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

    sudo service apache2 restart

    4) หลังจากนั้นทดสอบเข้า web nagios ดูจะพบว่ามี icon เพิ่มขึ้นมาดังนี้ (อาจต้องรอสักพัก เพราะการสร้าง graph ใหม่จะมีรอบการสร้าง)

    2014-07-24_050329

    – หน้าตาโปรแกรม

    2014-07-24_050346

    จบแล้วครับสำหรับการติดตั้ง NagiosGraph ดีเลยมีทั้ง Monitor มีทั้ง Graph ในตัว เอาไว้ดูยามฉุกเฉินครับ

  • วิธีการตั้งค่าและการใช้งาน 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 ปกติแต่จะสบายกว่าในกรณีที่มีเครื่องเยอะ ๆ แล้วจะติดใจครับ ^ ^

  • การติดตั้งและการตั้งค่าเบื้องต้น Nagios บน Ubuntu 14.04 LTS

    มาเริ่มขั้นตอนการติดตั้งกันเลยครับ โดยก่อนจะติดตั้ง Nagios
    ต้องทำการติดตั้ง Apache2 ก่อนนะครับ

    วิธีการติดตั้ง Apache2 Web Server

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

    sudo apt-get install -y apache2 
    

    2) ติดตั้ง SSL ให้พิมพ์คำสั่งเพื่อเปิด site ดังนี้

    sudo a2enmod ssl
    sudo a2ensite default-ssl

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

    sudo service apache2 restart

    วิธีการติดตั้ง Nagios

    1) ติดตั้ง Nagios ดังนี้

    sudo apt-get -y install nagios3

    2) จะปรากฎหน้าต่างถามเกี่ยวกับการตั้งค่าส่งเมล์ให้เลือกใช้เป็น Internet with smarthost เพื่อส่งเมล์ผ่าน mail relay ดังรูป
    2014-07-23_054238

    3) จะปรากฎหน้าต่างถามว่าจะใส่ email ผู้ส่งว่าอะไรก็ให้ใส่ไปครับ ไม่ต้องมีอยู่จริงก็ได้ครับ

    2014-07-23_054257

    4) ในหน้าต่างต่อไปจะให้ใส่ว่าจะให้ Relay ไปยัง Mail Server ใดให้ใส่ mail server ที่ต้องการ relay
    2014-07-23_054357

    5) จากนั้นจะให้ตั้งรหัสผ่าน ทำการตั้งรหัสผ่านตามที่ต้องการ (User ตั้งต้นชื่อ nagiosadmin)

    2014-07-23_054430

    6) ทำการตั้งรหัสผ่านเพิ่มเติมได้ที่ไฟล์ /etc/nagios3/htpasswd.users ยกตัวอย่างการเพิ่ม  User ชื่อ workshop (ไม่เกี่ยวข้องกับ user ของระบบใช้เข้า web nagios เท่านั้น) ดังนี้

    sudo htpasswd /etc/nagios3/htpasswd.users workshop

    จะปรากฎข้อความให้ใส่รหัสผ่านดังนี้

    New password: 
    Re-type new password: 
    Adding password for user workshop

    7) สามารถตรวจสอบไฟล์ได้โดยคำสั่ง

    sudo cat /etc/nagios3/htpasswd.users

    8) ทดสอบเปิด Website ดูดังนี้

    http://localhost/nagios3

    9) จะปรากฎหน้าต่างให้กรอก username และ password ให้กรอกไปตามที่ตั้งไว้
    วิธีการ Logout คือปิด browser เท่านั้น

    2014-07-23_060534

    10) จะปรากฎหน้าแรกของ Nagios

    2014-07-23_060555

    วิธีการให้ Redirect ไปยัง SSL อัตโนมัติเพื่อความปลอดภัยของรหัสผ่าน

    1) ทำเปลี่ยนชื่อไฟล์ หน้า default เก่าของ apache จาก index.html เป็น index.html.ori ดังนี้

    sudo mv /var/www/html/index.html /var/www/html/index.html.ori

    2) สร้างไฟล์ /var/www/html/index.html ใหม่ ดังนี้

    sudo nano /var/www/html/index.html
    

    3) เพิ่มข้อความในไฟล์ดังนี้ (วิธีการ save ให้กด Ctrl-X แล้วกด y แล้ว enter) โดยการใช้งานจริงให้แทนที่ localhost ด้วยชื่อเครื่องจริง

    <!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://localhost/nagios3"></HEAD>
    <BODY>
    Please Wait.....
    </BODY>
    </HTML>

    4) ทดสอบเปิด Website อีกรอบดังนี้ จะเห็นได้ว่าระบบจะ redirect ไปยังหน้า nagios3 ที่เป็น ssl อย่างที่ต้องการ

    http://localhost

    วิธีการเพิ่มสิทธิ์ให้กับ User ที่เพิ่มมาใหม่

    1) ทดสอบเข้าเครื่องโดยใช้ User ที่สร้างขึ้นมาใหม่ ลองเข้าดูหน้าต่าง ๆ จะเห็นว่าจะขึ้นบอกว่าไม่สิทธิ์ในการใช้งาน

    2) ทำการแก้ไขไฟล์ /etc/nagios3/cgi.cfg ดังนี้

    sudo nano /etc/nagios3/cgi.cfg

    3) ทำการแก้ไขไฟล์ /etc/nagios3/cgi.cfg ในหัวข้อที่ต้องการจะเปิดสิทธิ์ให้ user นั้น ๆ ยกตัวอย่างกำหนดสิทธิ์ให้ username ชื่อ workshop การเข้าถึงได้ทุกหัวข้อ

    authorized_for_system_information=nagiosadmin,workshop
    authorized_for_configuration_information=nagiosadmin,workshop
    authorized_for_all_services=nagiosadmin,workshop
    authorized_for_all_hosts=nagiosadmin,workshop
    authorized_for_all_service_commands=nagiosadmin,workshop
    authorized_for_all_host_commands=nagiosadmin,workshop
    

    4) จากนั้นให้สั่ง Restart Nagios ดังนี้

    sudo service nagios3 restart

    วิธีการตั้งค่าเสียงเตือน

    1) ทำการแก้ไขไฟล์ /etc/nagios3/cgi.cfg ดังนี้

    sudo nano /etc/nagios3/cgi.cfg

    2) ทำการเปิด comment ดังนี้ (ลบ # ออก) และแก้จาก .wav เป็น .mp3 ดังนี้

    host_unreachable_sound=hostdown.mp3
    host_down_sound=hostdown.mp3
    service_critical_sound=critical.mp3
    service_warning_sound=warning.mp3
    #service_unknown_sound=warning.mp3
    #normal_sound=noproblem.mp3

    3) ทำการโหลดไฟล์เสียงมาเก็บไว้ที่ /usr/share/nagios/htdocs/media ดังนี้

    cd /usr/share/nagios3/htdocs/media
    sudo wget http://ftp.psu.ac.th/pub/psu-monitor/sound.tar.gz
    sudo tar -xvzf sound.tar.gz

    *สามารถโหลดเสียงเพิ่มเติมได้ที่
    http://www.4shared.com/archive/Cr5UBS_W/Nagios-Sound-Pack1.html
    http://www.4shared.com/archive/pJsbVw0v/Nagios-Sound-Pack2.html

    4) จากนั้นให้สั่ง Restart Nagios ดังนี้

    sudo service nagios3 restart
  • 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