1. 程式人生 > 其它 >ntp時鐘伺服器離線搭建

ntp時鐘伺服器離線搭建

技術標籤:linux

由於centos6.5 yum不到ntp相關元件,特此記錄

ntp:可以為其配置ntp.conf將其設定為自動同步某伺服器時鐘。

ntpd服務只要啟動,自動會在後臺為這臺NTP伺服器同步時間(可能需要等幾分鐘),

不需要我們手動操作,其它機器只需同步這臺NTP伺服器即可。

所以ntp好用些,用ntpdate還得手動寫定時麻煩


ntpdate:可以使用 ntpdate -u ip地址 來手動同步某伺服器的時鐘。

本文主要討論ntp的使用

1、下載ntp的安裝包:

ntp-4.2.6p5-12.el6.centos.2.x86_64.rpm 試用於centos6.5

連結:https://pan.baidu.com/s/18fOYkkmYNGk2jLBpJt04oQ
提取碼:mfpy

2、安裝命令:

方式(1) rpm -ivh ntp-4.2.6p5-12.el6.centos.2.x86_64.rpm
若出現找不到依賴則使用下面的命令:

方式(2)rpm -ivh ntp-4.2.6p5-12.el6.centos.2.x86_64.rpm --nodeps --force

3、伺服器配置:(/etc/ntp.conf)

#然後新增這兩行 ,意思是 允許IPV4 IPV6 查詢 拒絕修改
restrict -4 default kod notrap nomodify   
restrict -6 default kod notrap nomodify 
#新增修改上層時間伺服器,如果能聯通外網,則不需要修改,

#定義使用的上游 ntp伺服器,將原來的註釋。如果聯不通外網,則把不要加了
#server ntp1.aliyun.com
#server time1.aliyun.com
#允許上層時間伺服器主動修改本機時間
#restrict time1.aliyun.com nomodify notrap noquery
#restrict ntp1.aliyun.com nomodify notrap noquery

#然後新增下面兩行,意思是設定成時間伺服器是自己

server 127.127.1.0
fudge 127.127.1.0 stratum 8

4、客戶端配置:(/etc/ntp.conf)

restrict -4 default kod notrap nomodify   
restrict -6 default kod notrap nomodify
#允許上層進行修改本機時間 ,把原來的註釋掉
#restrict 10.4.100.231 nomodify notrap noquery
#配置上層server(要同步的),在這裡配置的是實際的實體地址
server 10.4.100.231  
fudge 10.4.100.231 stratum 8

5、測試

啟動: /etc/init.d/ntpd start

設定開啟自啟動:chkconfig ntpd on

(1)伺服器:

[[email protected] etc]# ntpq -p
 
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           8 l   36   64  377    0.000    0.000   0.000
 
 
[[email protected] etc]# ntpstat
 
synchronised to local net at stratum 9 
   time correct to within 12 ms
   polling server every 64 s

(2)客戶端:


[[email protected] local]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.4.100.231    202.118.1.130    2 u   18   64    1    0.171  -10.820   0.000
+203.107.6.88    100.107.25.114   2 u   16   64    1   15.962   -0.141   0.440
*a.chl.la        131.188.3.222    2 u   14   64    1  182.340   -4.358   0.136
 undefined.hostn 127.67.113.92    2 u   24   64    0    0.000    0.000   0.000

6、日誌設定


[[email protected] sysconfig]# pwd
/etc/sysconfig
 
[[email protected] sysconfig]#cat ntpd
 
# Command line options for ntpd
OPTIONS="-g -l /var/log/ntpstats/ntpd.log"
 
[[email protected] ntpstats]# service ntpd stop
 
[[email protected] ntpstats]# service ntpd start 
 
[[email protected] ntpstats]# service ntpd status
 
[[email protected] ntpstats]# tail -200f /var/log/ntpstats/ntpd.log