Category: Open Source Software & Freeware

  • สร้าง DLNA Media Server ผ่าน Ubuntu ด้วยโปรแกรม MiniDLNA

    อุปกรณ์ที่บ้านรองรับ DLNA (มือถือ, PC, Notebook, TV ฯลฯ) มี Notebook เก่า ๆ อยู่เครื่องไม่รู้เอามาทำอะไรดี จะทำ Stream Media Server ใช้ง่าย ๆ ได้ยังไง

    อยากรู้ DLNA คืออะไรเชิญอ่านได้ที่นี่ครับ

    http://www.deviceacademy.com/forum/th/node/858

    เกี่ยวกับ Project MiniDLNA

    http://sourceforge.net/projects/minidlna/

    https://help.ubuntu.com/community/MiniDLNA

    ขั้นตอนการติดตั้ง DLNA Media Server ผ่าน Ubuntu ด้วยโปรแกรม MiniDLNA

    1. วิธีการขั้นแรกก็ติดตั้ง Ubuntu 14.04 LTS จะ Desktop หรือ Server แล้วแต่ศรัทธา

    2. ติดตั้ง MiniDLNA

    sudo apt-get install minidlna

    3. สร้าง Folder สำหรับทำ Media Server ดังนี้

    mkdir /home/[user]/music
    mkdir /home/[user]/picture
    mkdir /home/[user]/video
    sudo mkdir /var/cache/minidlna

    4. แก้ไขไฟล์ดังนี้

    sudo vim /etc/minidlna.conf

    4.1) ตั้งค่าในส่วนของ folder ที่จะให้ DLNA Server ให้บริการโดยแบ่งเป็น 3 แบบ คือ A = Audio, V= Video, P = Picture

    # If you want to restrict a media_dir to a specific content type, you can
    # prepend the directory name with a letter representing the type (A, P or V),
    # followed by a comma, as so:
    # * "A" for audio (eg. media_dir=A,/var/lib/minidlna/music)
    # * "P" for pictures (eg. media_dir=P,/var/lib/minidlna/pictures)
    # * "V" for video (eg. media_dir=V,/var/lib/minidlna/videos)
    #media_dir=/var/lib/minidlna
    media_dir=A,/home/[user]/music
    media_dir=P,/home/[user]/picture
    media_dir=V,/home/[user]/video

    4.2) ตั้งในส่วนของ network_interface โดยอุปกรณ์ที่จะใช้งานได้ต้องอยู่วงเดียวกับ DLNA Server

    # Network interface(s) to bind to (e.g. eth0), comma delimited.
    # This option can be specified more than once.
    network_interface=eth0

    4.3) ตั้งค่าชื่อที่จะปรากฎที่อุปกรณ์เมื่อจะเข้าใช้งาน DLNA Server

    # Name that the DLNA server presents to clients.
    # Defaults to "hostname: username".
    friendly_name=DLNA Media Server

    4.4) ทำการตั้งค่า Folder ที่ไว้เก็บ Database และ Cache หน้าปก Album Art (อาจจะทำให้การ Update ข้อมูลเมื่อมีการใส่ file ใหม่หน่วงบ้าง แต่เวลาเรียกไฟล์เยอะ ๆ จะได้เร็วขึ้น)

    # Path to the directory that should hold the database and album art cache.
    db_dir=/var/cache/minidlna

    4.5) ตั้งค่าให้เขียน log file เอาไว้ debug software

    # Path to the directory that should hold the log file.
    log_dir=/var/log

    4.6) ตั้งให้ scan file อัตโนมัติเมื่อมีไฟล์ใหม่

    # Automatic discovery of new files in the media_dir directory.
    inotify=yes

    5. ตั้งให้ start โปรแกรมเมื่อเปิดเครื่องโดยทำการแก้ไขไฟล์

    sudo vim /etc/default/minidlna

    – ตรวจสอบค่า START_DAEMON ว่าเป็น yes หรือไม่

    # Start the daemon if set to "yes"
    START_DAEMON="yes"

    5. ทำการ Restart MiniDLNA Server ดังนี้

    sudo service minidlna restart

    ที่เหลือก็แค่เปิด tv notebook pc ดูครับ โดยไฟล์ที่ใส่ลงไป จะโยนผ่าน samba share, ssh, ftp แล้วแต่จะสะดวกครับ โดยข้อจำกัดมีอยู่บ้างครับ คือไฟล์ที่ DLNA Support แน่ ๆ ก็ mp4 แต่พวก flv ไม่ครับส่วน mkv อันนี้รองรับเปิดได้ครับ (จริง ๆ ก็อยู่ที่อุปกรณ์ปลายทางด้วยว่ารองรับ codec ไหม)

    ส่วนอุปกรณ์ที่รองรับมีอีกคำนอกเหนือ DLNA คือ UPnP ลองดูแล้วครับ กล่อง TV Digital หลายกล่องก็รองรับอยู่นะครับ ส่วน SMART TV มีแน่ ๆ ครับ จริง ๆ Windows Media Player ก็ทำเป็น DLNA Server ได้เช่นเดียวกับแต่จะเรียกว่า Media Stream ครับ

    จริง ๆ youtube ก็ทำ stream ได้เช่นกัน แต่ไม่ได้ stream ตรง ๆ แต่เหมือน remote control ซึ่งก็หน่วงพอสมควร แต่ DLNA ที่ผมใช้ก็เพื่อดูหนัง MV การ์ตูนซะมากกว่า ซึ่งจะไม่มีการ remote control ต้องควบคุมที่อุปกรณ์เอง ทำหน้าที่เป็นแค่ share file server แต่ share ทั้งทีก็ทำให้ใช้ได้ทุกรูปแบบ โดยวิธีใช้ประมาณโหลดเสร็จก็โยนใส่ notebook ที่ลง dlna server ไว้ แล้วก็ปิดเครื่องที่โหลดทิ้ง นอนดูผ่านทีวี หรือดูผ่านมือถือได้เลย

  • ติดตั้ง Pykota บน Ubuntu Server 14.04.1 LTS

    1. ติดตั้งโปรแกรมที่จำเป็นก่อน
    sudo apt-get install cups subversion postgresql postgresql-client postgresql-common libX11-dev libxt-dev libxext-dev python-dev python-jaxml python-reportlab python-reportlab-accel python-pygresql python-osd python-egenix-mxdatetime python-imaging python-pysnmp4 python-chardet python-pam python-pysqlite2 python-mysqldb python-ldap apparmor-utils

    2. แก้ config ของ cups
    #sudo vi /etc/cups/cupsd.conf

    ที่ <Location />
    เพิ่ม  allow all

    ที่ <Location /admin>
    เพิ่ม  allow ip_admin

    ที่ <Policy default>
    comment JobPrivateValues default
    เพิ่ม
    JobPrivateValues job-originating-host-name
    ที่ <Policy authenticated>
    comment JobPrivateValues default
    เพิ่ม
    JobPrivateValues job-originating-host-name

    3. แก้ config ของ PostgreSQL
    #sudo pico /etc/postgresql/9.3/main/pg_hba.conf
    เติมข้อความนี้ต่อไปที่ท้ายสุดของแฟ้ม
    host all all 10.0.5.3/24 trust
    ***ให้เปลี่ยนเลข ip จาก 10.0.5.3 เป็นเลข ip ของ server ที่กำลังใช้

    4. ติดตั้งเครื่องพิมพ์
    เปิด Browser ไปที่ url http://ip_server:631
    cups001

    คลิก tab Administration
    cups002

    คลิก Add Printer
    cups003

    เลือก Printer คลิก Continue

    cups004

    ใส่รายละเอียด ของเครื่องพิมพ์
    ติ๊ก เลือก Share This Printe
    คลิก Continue


    cups005

    เลือก Driver ของเครื่องพิมพ์ คลิก Add Printer
    cups006
    คลิก  Set Default Option

    ทดสอบการพิมพ์โดยเลือก Print Test Page
    cups007

    5. ติดตั้งเครื่องพิมพ์บนเครื่อง Client และทดสอบการพิมพ์

    6. ติดตั้งโปรแกรม Pykota
    #cd /usr/share
    #svn co http://svn.pykota.com/pykota/trunk pykota
    #cd pykota
    #python checkdeps.py
    #python setup.py install

    7. สร้างผู้ใช้ pykota ด้วยคำสั่ง
    #sudo adduser –system –group –home /etc/pykota –gecos Pykota pykota
    #sudo adduser lp pykota

    8. จัดการ postgresql ต่อดังนี้
    #sudo su – postgres -c “psql -f /usr/share/pykota/initscripts/postgresql/pykota-postgresql.sql template1”

    9. ทำให้ cups รู้จัก Pykota
    #cd /usr/lib/cups/backend
    #sudo ln -sf /usr/share/pykota/bin/cupspykota
    #sudo chmod -Rf 755 /usr/share/pykota/bin/*
    #sudo chmod -Rf 755 /usr/lib/cups/backend*
    #sudo /etc/init.d/cups restart

    แก้ไขแฟ้ม /etc/cups/printers.conf
    #sudo vi /etc/cups/printers.conf
    <DefaultPrinter abc>
    DeviceURI parallel:/dev/lp0
    ที่บรรทัด DeviceURI parallel:/dev/lp0
    ให้แทรกเพิ่มคำว่า cupspykota:// เข้าไป กลายเป็นดังตัวอย่าง
    DeviceURI cupspykota://parallel:/dev/lp0
    ***abc คือชื่อเครื่องพิมพ์ที่ add ไว้ตามข้อ 4.

    sudo cp /usr/share/pykota/conf/pykota.conf.sample /etc/pykota/pykota.conf
    sudo cp /usr/share/pykota/conf/pykotadmin.conf.sample /etc/pykota/pykotadmin.conf
    sudo chown -Rf pykota.pykota /etc/pykota/

    10. ทำให้ apparmor รู้จัก Pykota
    aa-complain cupsd

    11. แก้ไขแฟ้ม /etc/pykota/pykota.conf
    ไปที่ประมาณบรรทัด 987 แล้วลบบรรทัดข้อความว่า policy: deny ทิ้ง
    แล้วไปที่บรรทัดล่างสุดของแฟ้ม เติมต่อท้ายว่า
    [abc]
    enforcement : strict
    ***abc คือชื่อเครื่องพิมพ์ที่ add ไว้ตามข้อ 4.

    12. เพิ่มเครื่องพิมพ์ให้ Pykota
    #pkprinters –add –charge 1.0 –description “Printer for ITZONE 3nd” abc
    ***abc คือชื่อเครื่องพิมพ์ที่ add ไว้ตามข้อ 4.
    ***charge 1.0 คือคิดค่าพิมพ์หน้าละ 1 บาท

    13. เพิ่ม User ให้ Pykota
    /usr/local/bin/pkusers –add –limitby balance –balance 20 patt.e
    /usr/local/bin/edpykota –add –printer abc patt.e
    ***abc คือชื่อเครื่องพิมพ์ที่ add ไว้ตามข้อ 4.
    ***–add คือเพิ่ม, User
    ***–limitby balance คือ limit การพิมพ์ด้วย balance
    ***–balance 20 คือ กำหนด โควต้าไว้ 20
    ถ้า +20 คือ เพิ่มจากของเดิม 20
    ถ้า -20 คือ ลดจากของเดิม 20
    ถ้า 20 กำหนดให้เป็น 20
    ***patt.e คือ user
    ถ้าไม่กำหนด user คือทำกับทุก user ที่อยู่ใน Pykota

    14. ทดสอบพิมพ์จากเครื่อง Client

  • เรียนรู้วิธีการใช้งาน Cacti เพื่อ Monitor Server

    ท่านสามารถอ่านวิธีติดตั้ง Cacti ได้ที่นี่
    http://sysadmin.psu.ac.th/2014/07/24/cacti-setup/

    วิธีการติดตั้ง SNMP Query MIB เพิ่มเติม รวมถึง MIB ของโปรแกรม SNMP Informant ซึ่งใช้ติดตั้งเป็น Agent ของ Windows Server โดยมีขั้นตอนดังนี้

    วิธีการเพิ่มเติม snmp query template สำหรับ cacti

    1) ทำการ move resource เป็น resource_old

    sudo mv /usr/share/cacti/resource /usr/share/cacti/resource_old

    2) ทำการสร้าง folder resource ขึ้นมาใหม่และทำการโหลดไฟล์ resource ใหม่จาก web มาวาง

    cd /usr/share/cacti
    sudo mkdir resource
    cd resource
    sudo wget http://ftp.psu.ac.th/pub/psu-monitor/resource.tar.gz
    sudo tar -xvzf resource.tar.gz

    3) ทำการเพิ่ม Template ลบไปฐานข้อมูลโหลด Download xml ทำการติดตั้งดังนี้

    cd /home/workshop/Desktop/
    wget http://ftp.psu.ac.th/pub/psu-monitor/template.zip
    unzip template.zip

    ทำการ Import ไฟล์ xml ทั้งหมด

    – ตัวอย่างวิธีการ Import Template2014-07-25_053233

    4) ทำการตั้งค่า Linux Host Template ใหม่ดังนี้2014-07-25_055104

    ทำการ Add Associated Graph Templates และ Data Queries ดังนี้ (หลังจากกด save มันจะไม่ดีดไปไหน แต่ save แล้วครับ)2014-07-25_055500

    5) ทำการตั้งสร้าง Windows Host Template ใหม่ดังนี้2014-07-25_0559182014-07-25_060021

    ทำการ Add Associated Graph Templates และ Data Queries ดังนี้

    2014-07-25_060447

    สำหรับเครื่องที่เป็น Linux เปิดเฉพาะ snmp ก็เพียงพอ แต่เครื่องที่เป็น Windows ต้องลงโปรแกรม informant เพิ่มเติมเพื่อเสมือนเป็น agent ไปดึงค่าจากเครื่องไปสร้าง MIB พิเศษเพื่อให้ Cacti เข้ามาดึงข้อมูล โดยโปรแกรมสามารถ Download ได้ที่นี่

    http://www.wtcs.org/informant/files/informant-std-17.zip

    6) เพื่อไม่ต้อง ตั้งค่า snmp บ่อย ๆ ให้ทำการแก้ไข snmp default ดังรูป2014-07-25_061716

    วิธีการเพิ่ม device

    1) ทำการ Add Device ดังนี้2014-07-25_061537

    2) ใส่ข้อมูลต่าง ๆ ของ Device2014-07-25_062211

    3) หลังจากนั้นให้สังเกตุคำว่า success และมีจำนวน items แสดงว่าเราสามารถดึงค่าได้แล้ว ในกรณีที่ยังไม่ได้ เมื่อให้ทำการทดสอบโดยกดเลือก Verbose Query ทุกครั้ง ถ้ายังไม่ success แนะนำว่าอย่าเพิ่งสร้าง Graph ครับ เพราะเราไม่รู้ว่าเครื่องมีกี่ CPU กี่ interface แรมเท่าไหร่ จึงไม่สามารถสร้าง Graph ล่วงหน้าได้2014-07-25_062403

    – เมื่อกดปุ่ม Verbose Query ระบบจะทำการดึงข้อมูลมาให้ดูดังรูป2014-07-25_062639

    วิธีการสร้าง Graph ประเภท Linux Machine

    – ทำการ Create Graph ในหน้า device ดังนี้

    2014-07-25_062937

    – ให้เลือกทีละหัวข้อจากนั้นทำการกดปุ่ม Create2014-07-25_063048 2014-07-25_0631362014-07-25_0638422014-07-25_063251 2014-07-25_063421 2014-07-25_063456 2014-07-25_063733

    วิธีการสร้าง Graph ประเภท Windows Machine

    – ให้ลองสร้าง Device ประเภท Windows

    – ทำการ Create Graph ในหน้า device ดังนี้ (หลังเลือก Graph Template Name หลังสุดนะครับ ถ้าเลือกเป็น Pack อาจเยอะจนตาลาย)

    – ให้เลือกทีละหัวข้อจากนั้นทำการกดปุ่ม Create2014-07-25_065458 2014-07-25_0656102014-07-25_0659412014-07-25_0700162014-07-25_0656422014-07-25_0700572014-07-25_065813 2014-07-25_065834    2014-07-25_070208

    วิธีการเพิ่ม Graph Tree

    2014-07-25_070622 2014-07-25_070652 2014-07-25_070731

    – เราสามารถดูกราฟได้ที่หัวข้อ Graph2014-07-25_070852

    จบแล้วครับสำหรับการใช้งาน cact ใครอยากลอง template ส่วนอื่น ๆ สามารถลองได้ครับ

  • การติดตั้ง snmpd และการตั้งค่า shorewall บน Ubuntu 14.04 LTS

    ในบทความนี้จะเกี่ยวกับการตั้งค่า snmpd บน ubuntu รวมถึงการเปิด port firewall ด้วยโปรแกรม Shorewall ดังนี้

    วิธีการติดตั้ง snmpd, shorewall บน ubuntu 14.04 LTS

    1) ทำการติดตั้งโปรแกรม snmpd และ shorewall ดังนี้

    sudo apt-get install -y snmp snmpd shorewall

    2) ทำการติดตั้ง mib เพิ่มเติมดังนี้

    sudo apt-get -y install snmp-mibs-downloader

    3) วิธีการทดสอบการว่าการใช้งาน snmp สามารถใช้งานหรือยังดังนี้

    sudo snmpwalk -Os -c public -v 2c localhost HOST-RESOURCES-MIB::hrSystemProcesses.0

    4) ทำการตั้งค่า community เพิ่มเติม (ไม่ควรใช้ public) โดยการแก้ไฟล์ดังนี้

    sudo nano /etc/snmp/snmpd.conf

    – เพิ่มข้อความดังนี้

    ...
    
    # Listen for connections from the local system only
    #agentAddress udp:127.0.0.1:161
    
    ...
    
    view systemonly included .1.3.6.1.2.1.1
    view systemonly included .1.3.6.1.2.1.25.1
    view systemonly included .1
    
                          # Full access from the local $
    #rocommunity public localhost
                          # Default access to basic sys$
    #rocommunity public default -V systemonly
    rocommunity happy default -V systemonly
    
    ...

    5) ทำการ restart snmpd

    sudo service snmpd restart

    6) ทดสอบ snmpwalk อีกครั้งจะพบ Error ดังนี้

    sudo snmpwalk -Os -c public -v 2c localhost HOST-RESOURCES-MIB::hrSystemProcesses.0
    Timeout: No Response from localhost

    7) ลองทดสอบอีกครั้งโดยเปลี่ยน community จาก public เป็น happy ดังนี้

    sudo snmpwalk -Os -c happy -v 2c localhost HOST-RESOURCES-MIB::hrSystemProcesses.0
    hrSystemProcesses.0 = Gauge32: 34

    8) เราสามารถดูค่า mib ทั้งหมดได้ดังนี้ (เรื่องจากเราเปิด view .1 ซึ่งหมายถึงเปิดทั้งหมด โดยปกติ default จะไม่แสดงทั้งหมด)

    sudo snmpwalk -Os -c happy -v 2c localhost

    9) สำหรับ snmpd จะใช้ port 161 UDP ซึ่งจะต้องตั้งค่า shorewall ให้เสร็จก่อน โดยมีขั้นตอนการติดตั้งแบบรวดเร็วดังนี้

    – ทำการสร้าง default config

    sudo cp /usr/share/doc/shorewall/examples/one-interface/zones /etc/shorewall
    sudo cp /usr/share/doc/shorewall/examples/one-interface/interfaces /etc/shorewall
    sudo cp /usr/share/doc/shorewall/examples/one-interface/policy /etc/shorewall
    sudo cp /usr/share/doc/shorewall/examples/one-interface/rules /etc/shorewall

    – ทำการตั้ง startup shorewall อัตโนมัติ

    sudo nano /etc/default/shorewall

    – ทำการแก้ไข startup จาก 0 เป็น 1

    # prevent startup with default configuration
    # set the following varible to 1 in order to allow Shorewall to start
    
    startup=1 
    ...

    – จากนั้นทำการแก้ไข rule เพื่อเพิ่ม port 161 udp ดังนี้

    sudo nano /etc/shorewall/rules

    – เพิ่มข้อความในส่วนท้ายไฟล์ดังนี้

    ...
    # Permit all ICMP traffic FROM the firewall TO the net zone
    
    ACCEPT $FW net icmp
    
    #SSH
    ACCEPT net:192.168.99.0/24 fw tcp 22
    #SNMP
    ACCEPT net:192.168.99.0/24 fw udp 161

    – ทำการ restart shorewall ดังนี้

    sudo service shorewall restart

    8) เราสามารถทดสอบ query snmp จากเครื่องอื่น ได้ดังนี้ (คำสั่งนี้สั่งบนเครื่องอื่นที่ต้องการดึงค่า)

    sudo snmpwalk -Os -c happy -v 2c 192.168.99.10

    สามารถอ่านรายละเอียดการติดตั้งและตั้งค่า shorewall เพิ่มเติมได้ที่
    http://opensource.cc.psu.ac.th/%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87_shorewall_%E0%B8%9A%E0%B8%99_ubuntu

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

    โปรแกรม Cacti เป็นโปรแกรม Monitor แบบหนึ่งแต่จะเน้นการ Monitor ผ่าน snmp ซึ่งจุดเด่นจะอยู่ที่การสร้าง graph ที่ค่อนข้างชัด ดูง่าย ทำให้ช่วยวิเคราะห์ปัญหาย้อนหลังทำได้ง่ายกว่า

    วิธีการติดตั้ง Cacti บน Ubuntu 14.04 LTS

    1) ทำการติดตั้งชุดโปรแกรม Lamp Server (Linux + apache + mysql + php) ดังนี้

    sudo apt-get install lamp-server^

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

    sudo apt-get -y install rrdtool

    3) ทำการติดตั้งโปรแกรม snmp ทั้งโปรแกรม server และ client ดังนี้

    sudo apt-get -y install snmp snmpd

    4) ทำการติดตั้ง mib เพิ่มเติมดังนี้

    sudo apt-get -y install snmp-mibs-downloader

    5) วิธีการทดสอบการว่าการใช้งาน snmp สามารถใช้งานหรือยังดังนี้

    sudo snmpwalk -Os -c public -v 2c localhost HOST-RESOURCES-MIB::hrSystemProcesses.0

    6) ทำการติดตั้งโปรแกรม Cacti และ spine ดังนี้

    sudo apt-get -y install cacti cacti-spine

    2014-07-24_204947 2014-07-24_205027 2014-07-24_205058

    7) ทำการเข้าหน้าติดตั้ง Cacti ผ่าน web ดังนี้

    http://localhost/cacti

    2014-07-24_205323 2014-07-24_205409 2014-07-24_205448

    8) จากนั้นทำการ Login เข้า web โดยมี Default User : admin, Password : admin ดังนี้

    http://localhost/cacti

    2014-07-24_205538

    9) หลังจากนั้นระบบจะบังคับให้เปลี่ยนรหัสผ่านดังนี้

    2014-07-24_205855

     

    เสร็จสิ้นการติดตั้ง Cacti แล้วครับ เหลือการตั้งค่า spine ซึ่งเป็นตัวช่วยให้ทำงานดีขึ้นกว่าแบบที่เป็น cmd.php เนื่องจากโปรแกรมเขียนด้วยภาษา C จึงทำงานได้เร็วกว่า โดยทำการตั้งค่าดังรูป (อย่าลืม save ด้วยนะครับ)

    2014-07-25_071624 2014-07-25_071701

    ส่วนวิธีใช้งานสามารถดูได้ที่บทความนี้ครับ

    http://sysadmin.psu.ac.th/2014/07/25/cacti-howtouse/

     

  • การติดตั้ง 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 บน Ubuntu 14.04

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

    วิธีการติดตั้ง Nrpe บน Ubuntu 14.04

    1) ทำการติดตั้งโปรแกรม nrpe (มองว่าเป็น server ให้ nagios มาเรียกเพื่อดึงค่า) ดังนี้

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

    2) ทำการแก้ config /etc/nagios/nrpe.cfg เพื่อใส่ชื่อเครื่องที่อนุญาตให้มาดึงค่าได้ ดังนี้

    sudo nano /etc/nagios/nrpe.cfg
    ...
    
    #
    # NOTE: This option is ignored if NRPE is running under either inetd or xinetd
    
    allowed_hosts=127.0.0.1,monitor

    3) จากนั้นทำการ Restart nrpe ดังนี้

    sudo /etc/init.d/nagios-nrpe-server restart

    4) ให้กลับไปดูใน web nagios จะพบว่ามีการแสดงข้อมูลในส่วนของ nrpe (ในกรณีที่สร้าง service nrpe เรียบร้อยแล้ว)

    ยกตัวอย่างวิธีการเพิ่ม Plugin ให้กับ nrpe บน Ubuntu 14.04

    plugin ที่ให้มายังไม่มีในส่วนของการ monitor memory โดยให้สร้างใน path /usr/lib/nagios/plugins/ และทำการสร้าง command เพิ่มเติมในไฟล์ /etc/nagios/nrpe.cfg ประมาณนี้

    cd /usr/lib/nagios/plugins
    sudo wget http://ftp.psu.ac.th/pub/psu-monitor/check_mem.sh
    sudo chmod ugo+x check_mem.sh
    sudo nano /etc/nagios/nrpe.cfg
    ...
    
    command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
    command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 
    command[check_mem]=/usr/lib/nagios/plugins/check_mem.sh 85 95
  • วิธีการตั้งค่า 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 ในตัว เอาไว้ดูยามฉุกเฉินครับ