Saturday 28 August 2010

ติดตั้ง NTP Server

ติดตั้ง NTP Server

ติดตั้งระบบ เทียบเวลาเพื่อให้แต่ server ที่ให้บริการอยู่ในองค์กร และเครื่องลูกข่าย มีเวลาที่ตรงกัน ตามพรบระบุว่า ต้องตั้งนาฬิกาให้ต้องกับเวลาอ้างอิงสากล (Stratum 0)

ขั้นตอนการติดตั้ง

  1. ตรวจสอบ package
  2. การทำงานจะทำงานผ่าน port UDP  123 ดังนั้นต้องให้  firewalls ACCEPT port 123 ด้วย
    #rpm -qa | grep ntp*
    หากไม่พบ ก็สามารถติดตั้งได้โดย
    #yum install  ntp  -y
    เปิดพอร์ต สามารถทำได้โดยการ update filewall#vi  /etc/sysconfig/iptables
    ...
    ...
    -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTแทรก สองบรรทัดนี้ ต่อ จากบรรทัดตรงนี้
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
    
    restart iptable อีกครั้ง #service iptables restart
    #netstat  -tulpn
  3. ตรวจสอบ remote server
  4. สถาบันมาตรวิทยาแห่งชาติ           [203.185.69.60]   กรมอุทกศาสตร์ กองทัพเรือ            [time.navy.mi.th]  National Institute of Standards and Technology     [time.nist.gov]   
    #ntpdate  -b  203.185.69.60
    #ntpdate  -b  time.navy.mi.th
    #ntpdate  -b  time.nist.gov
  5. แก้ไขค่า config
  6. ตัวอย่างที่ใช้
    192.168.2.1    คือ  CentOs/Redhat server ของเรา
    203.185.69.60    คือ หมายเลข ip ของ NTP server192.168.2.0/24   คือ วง  network ของเครื่องลูกข่าย
    
    backup config#cp  /etc/ntp.conf   /etc/ntp.conf.ori
    #vi  /etc/ntp.conf
    เพิ่มเติม โดย แทนค่า 192.168.2.0 ด้วย วง network ของคุณเอง
    restrict 192.168.2.0  mask 255.255.255.0 nomodify notrap
    server   time1.nimt.or.th 
    server   time.navy.mi.th
    server   clock.nectec.or.th
  7. restart NTP server
  8. #service ntpd  restart
    #chkconfig ntpd on
    check อีกครั้่ง ด้วยวิธีดังต่อไปนี้
    #chkconfig --list  | grep ntp   
    #ps -ef  | grep ntp        
    #pgrep ntpd                         /*check process id
    #netstat  -ntlup                   /*check synce status
  9. check ตรวจสอบการทำงาน
  10. #ntpq  -pn                            /*firewalls rule  ต้องเปิดรับ UDP port 123
    หลักจาก start รอเวลาให้ time server ของคุณ sync ก่อน ประมาณ 5 นาที
    หลังจากนั้นก็ตรวขสอบ การ sync โดย
    #ntpstat
    #ntpdc
    ntpdc>sysinfo                     /*ระบบจะแสดงข้อมูลของ Time Server
  11. check การทำงานผ่านทาง Logfile ได้ที่
  12. #grep  ntpd   /var/log/messages
    แยก ntp log ออกมาไปเก็บไว้ที่  /var/log/ntp.log โดยการไปเพิ่ม ข้อความด้านล่างนี้ ใน /etc/ntp.conf ที่บรรทัดสุดท้าย
    #vi /etc/ntp.conf
    logfile   /var/log/ntp.log
  13. สั่งให้เครื่อง Client มา sync เวลาที่เครื่อง Timeserver (192.168.2.1)
  14. ต่อไปนี้ทำในเครื่อง server ในลูกข่ายไม่ได้ทำที่ เครื่อง time server#ntpdate  192.168.2.1
    #vi  /etc/ntp.conf
    server 192.168.2.1                        /* ip ของ NTP server
    restrict default  ignore                  /* deny all access จากเครื่องใด
    restrict   127.0.0.1
    
    ให้เครื่องลูกมา update ทุกๆๆ  30 นาที
    #crontrab -e
    30  * * * *  ntpdate 192.168.2.1   > /dev/null  2  > &1
    
    หมายเหตุ   ntpdate ใช้กับ client
  15. lient เป็น window ให้ใช้ nettime โดยสามารถไป Download ได้ที่
  16. http://nettime.sourceforge.net
  17. est result ผลการทำงาน
  18. #service ntpd restart
    #tail -f /var/log/ntp.log
    11 Feb 00:37:49 ntpd[2743]: ntpd exiting on signal 15
    11 Feb 00:41:03 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 00:41:03 ntpd[2764]: kernel time sync enabled 0001
    11 Feb 00:43:10 ntpd[2764]: synchronized to 118.175.67.83, stratum 1
    11 Feb 00:46:26 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 00:48:37 ntpd[2764]: synchronized to 118.175.67.83, stratum 1
    11 Feb 00:52:53 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
    11 Feb 01:03:47 ntpd[2764]: time reset +0.794279 s11 Feb 01:07:31 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 01:08:36 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
    11 Feb 01:12:01 ntpd[2764]: synchronized to LOCAL(0), stratum 10
    11 Feb 01:13:47 ntpd[2764]: synchronized to 203.185.69.60, stratum 1
  19. ตั้งค่าให้เริ่มการทำงานทุกครั้งที่เปิดเครื่อง
  20. # chkconfig ntpd on

No comments:

Post a Comment