NTP和NTPD設置

ntp客戶端安裝

#yum install ntp -y

手動時間同步

#/usr/sbin/ntpdate pool.ntp.org
26 Feb 17:45:00 ntpdate[14681]: adjust time server 85.199.214.100 offset 0.004657 sec

添加計劃任務

#vim /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root


# For details see man 4 crontabs


# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
0  0  *  *  * /usr/sbin/ntpdate pool.ntp.org &&  /usr/sbin/hwclock --systohc 


注:ntp使用的是udp 123端口 在防火牆上一定要放開

#firewall-cmd --zone=public --add-port=123/udp --permanent

#firewall-cmd --reload


Ntp服務器的安裝配置

ntpd安裝

#yum install ntp -y

#systemctl start ntpd
您在 /var/spool/mail/root 中有新郵件
#systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 日 2017-02-26 17:53:24 CST; 7s ago
  Process: 14877 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 14878 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─14878 /usr/sbin/ntpd -u ntp:ntp -g


2月 26 17:53:24 ftp ntpd[14878]: Listen and drop on 1 v6wildcard :: UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 2 lo 127.0.0.1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 3 ens160 10.1.41.54 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 4 lo ::1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 5 ens160 fe80::250:56ff:fe85:598c UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listening on routing socket on fd #22 for interface updates
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c016 06 restart
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c011 01 freq_not_set
2月 26 17:53:31 ftp ntpd[14878]: 0.0.0.0 c614 04 freq_mode

查看ntp服務器有無和上層ntp連通

#ntpstat
synchronised to NTP server (51.15.41.135) at stratum 3 
   time correct to within 165 ms
   polling server every 64 s

 檢查時間服務器的同步狀態

#ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp3.itcomplian 5.103.128.88     2 u   20   64  377  206.590    4.816   0.801
+ntp4.flashdance 77.40.226.114    2 u   24   64  361  261.990   24.804   5.351
+ntp3.flashdance 194.58.202.148   2 u   27   64  173  234.689   17.706   1.152

到客戶端去測試

#ntpdate 10.1.41.54
26 Feb 17:55:37 ntpdate[12641]: adjust time server 10.1.41.54 offset -0.009717 sec


OK ntp的教程完成



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章