Tag: centos

  • การตั้งค่า IPV6 ให้กับ Lighttpd Web Server สำหรับ CentOS Linux

    “อยากตั้งค่า Lighttpd Web Server ให้เปิดใช้ IPv6 ต้องทำอย่างไร”

    • สำหรับวิธีเปิดใช้งาน IPv6 บน Lighttpd จะขอยกตัวอย่างบน CentOS 6.7 ซึ่งจริง ๆ แล้วสามารถตั้งเป็น IPv6 only ก็ได้ แต่ในที่นี่จะตั้งให้สามารถใช้ได้ทั้ง IPv4 และ IPv6
      1. เปิดไฟล์ /etc/lighttpd/lighttpd.conf
        sudo vim /etc/lighttpd/lighttpd.conf
      2. ทำการแก้ไขโดยเพิ่มในส่วนของ IPv6 Config ดังนี้ (แทนที่ [web-path] ด้วย location จริง ๆ เช่น “/var/www”)
        $SERVER["socket"] == "[::]:80" {
         accesslog.filename = "/var/log/lighttpd/ipv6.access.log"
         server.document-root = [web-path]
        }

        *หมายเหตุ : server.use-ipv6 = “disable” ไม่ต้องแก้ไขนะครับ เพราะ ด้วยชื่อ domain เดียวกันจะไม่สามารถเปิด port 80 สอง port ได้พร้อมกัน ทำได้แค่เพิ่ม SERVER Socket config เข้าไปอย่างที่เห็นข้างบนครับ (จะใช้ก็ตอนที่จะเปิดเฉพาะ IPv6 only ครับ)

      3. สั่ง Restart Web Service เป็นอันเรียบร้อยครับ
        sudo service lighttpd restart
      4. สามารถตรวจสอบผ่านคำสั่ง netstat ได้ดังนี้ครับ
        netstat -na | grep ":80"
    • การทดสอบในกรณียังไม่ได้จด DNS6 เราไม่สามารถพิมพ์ URL เป็น IPv6 ตรง ๆ บน Browser ได้ ถ้าจดแล้วสามารถทดสอบผ่าน http://ipv6-test.com/validate.php ดูได้ครับ
  • การตั้งค่า Interface IPv6 สำหรับเครื่อง CentOS/Redhat Server

    “อยากให้ CentOS/Redhat Server เปิดใช้ IPv6 ต้องทำอย่างไร”

    • สำหรับวิธีเปิดใช้งาน IPv6 บน CentOS/Redhat จะขอยกตัวอย่าง CentOS 6.7 โดยทำการตั้งค่า Interface ในส่วนของ IPv6 ดังนี้
      1. เปิดไฟล์ /etc/sysconfig/network-scripts/[interface-setting-file]
        sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0
      2. ทำการแก้ไขโดยเพิ่มในส่วนของ IPv6 Config ดังนี้ (xxx คือ censor นะครับ)
        IPV6INIT="yes"
        IPV6ADDR=2001:xxxxxxx:34
        IPV6_DEFAULTGW=2001:xxxxxxx::1
        
      3. สั่ง Restart เครื่องเป็นอันเรียบร้อยครับ (ในกรณีที่เป็น CentOS 6 สั่ง sudo service network restart ก็ได้ครับ)
        sudo reboot
      4. สามารถตรวจสอบผ่านคำสั่ง ifconfig ได้ดังนี้ครับ
        ifconfig
    • อย่าลืมตรวจสอบ Firewall ด้วยนะครับ แต่โดยปกติ CentOS จะมี Firewall ตั้งแต่เริ่มติดตั้ง ในกรณีที่ไม่ได้ Disable Firewall ให้เข้าไปแก้ได้ที่
      sudo /etc/sysconfig/ip6tables
    • ในกรณีที่ใช้ Shorewall ลองศึกษาเพิ่มเติมดูครับว่าต้องแก้ไขอย่างไร
  • รวมวิธีการเปิดใช้งาน IPv6

    “บทความนี้เป็นบทความเกี่ยวกับวิธีการเปิดใช้งาน  IPv6 สำหรับบริการที่เป็น Web Server รวมถึงวิธีการตรวจสอบ Client และ Server ว่าพร้อมหรือยังที่จะใช้งาน  IPv6”


    Blog 1 : การตรวจสอบสถานะการใช้งาน IPv6 สำหรับ Client และ Server


    Blog 2การตั้งค่า Interface สำหรับ Windows Server


    Blog 3 : การตั้งค่า Interface สำหรับ Ubuntu Linux


    Blog 4 : การตั้งค่า Interface สำหรับ CentOS/Redhat Linux


    Blog 5 : การตั้งค่า Apache Web Server สำหรับ Ubuntu Linux


    Blog 6 : การตั้งค่า Lighttpd Web Server สำหรับ CentOS Linux


    Blog 7 : การตั้งค่า Nginx Web Server สำหรับ Ubuntu Linux


  • ช่องโหว่ซอฟต์แวร์ Bash Vulnerability วิธีตรวจสอบและแก้ไข

    ช่องโหว่อันตรายของซอฟต์แวร์ Bash
    ————————————————–
    -การตรวจสอบช่องโหว่ซอฟต์แวร์ Bash Vulnerability ในระบบปฎิบัติการ Unix & Linux
    ทดสอบโดยพิมพ์คำสั่ง
    env VAR='() { :;}; echo Bash is vulnerable!' bash -c "echo Bash Test"

    หากปรากฎข้อความว่า Bash is vulnerable! แสดงว่าต้องรีบปรับปรุงซอฟต์แวร์ bash ทันที
    -วิธีการป้องกันและแก้ไขอัปเดตซอฟต์แวร์ bash
    หากใช้ Ubuntu / Debian ปรับแก้ไขอัปเดตเฉพาะปัญหา bash vulnerability

    sudo apt-get update && sudo apt-get install --only-upgrade bash

    ปรับแก้ไขอัปเดตทั้งระบบ

    sudo apt-get update && apt-get upgrade

    หากใช้ CentOS / Redhat / Fedora ปรับแก้ไขอัปเดตเฉพาะปัญหา bash vulnerability

    sudo yum update bash

    ขอบคุณครับ ^_^

  • การติดตั้งโปรแกรมชุด 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


  • How to list linux file permissions in Octal Notation

    วันนี้เนื่องจากทีมผู้ดูแล  Web Hosting ต้องการดูว่ามีไฟล์ไหนบ้างที่มี permission เป็น 777 ก็เลยนั่งหาดูพบว่า สามารถใช้คำสั่ง stat ในการดูได้ เช่น

    $stat -c "%a %n" /var/www

    ผลลัพธ์
    Screenshot from 2013-05-01 11:47:06

    หรือ

    $stat -c "%A (%a) %8s %.19y %n" /var/www

    ผลลัพธ์
    Screenshot from 2013-05-01 11:49:19

    ทั้งนี้เนื่องจากไม่สามารถทำให้มัน recursive ได้ ก็ต้องหาไปทีละโฟลเดอร์ …. จนกระทั่งเจออีกคำสั่ง คือ สร้าง alias ชื่อ lso ดังนี้

    $alias lso="ls -alG | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'"

    เมื่อจะใช้งาน ก็เพียงสั่ง lso ที่คอมมานด์ไลน์ ผลลัพธ์
    Screenshot from 2013-05-01 11:54:27

    สามารถปรับ option ของ ls ใน alias ให้ recursive ได้โดยเพิ่ม R ตัวใหญ่ลงไป ดังนี้

    $alias lso="ls -alGR | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'"

    เมื่อเรียกใช้จะได้ผลลัพธ์
    Screenshot from 2013-05-01 11:57:21

    สามารถใช้ร่วมกับ grep เพื่อค้นหาเฉพาะค่าที่ต้องการ เช่น

    $lso|grep " ^777"

    ผลลัพธ์
    Screenshot from 2013-05-01 13:11:12

    ก็พอจะช่วยได้บ้างครับ Big Smile ขอให้สนุกครับ

    ที่มา

    http://thenubbyadmin.com/2012/02/16/how-to-list-linux-file-permissions-in-octal-notation/

    http://askubuntu.com/questions/152001/how-can-i-get-octal-file-permissions-from-command-line