ubuntu 14.04 安装ntp

 

 

安装

sudo apt-get install ntp

修改ntp.conf配置文件

sudo vi /etc/ntp.conf

修改为如下内容

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/    #也可以开启NTP log

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server 120.24.166.46   # 阿里云NTP Server-----------
server 127.127.1.0     # 如果公网NTP不可用时,将使用Local时间作为NTP服务提供给NTP Client。

# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 192.168.20.0 mask 255.255.255.0 nomodify   # 允许的NTP Client网段---------------
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

 

重启NTP服务,并在客户端验证

root@ntpserver:~/ceph-cluster# service ntp restart
 * Stopping NTP server ntpd                                           [ OK ] 
 * Starting NTP server ntpd                                           [ OK ] 
root@ntpclient:/etc/ceph# ntpdate ntpserver
14 Jan 10:55:51 ntpdate[5230]: adjust time server 192.168.20.177 offset 0.209691 sec
root@ntpclient:/etc/ceph# 

 

观察时间同步状况:

ntpq -p

remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid:参考上一层ntp主机地址
st:stratum阶层
when:多少秒前曾经同步过时间
poll:下次更新在多少秒后
reach:已经向上层ntp服务器要求更新的次数
delay:网络延迟
offset:时间补偿
jitter:系统时间与bios时间差

 

查看ntpd进程的状态
【命令】watch "ntpq -p"
第一列中的字符指示源的质量。星号 ( * ) 表示该源是当前引用。
remote:列出源的 IP 地址或主机名。
when:指出从轮询源开始已过去的时间(秒)。
poll:指出轮询间隔时间。该值会根据本地时钟的精度相应增加。
reach:是一个八进制数字,指出源的可存取性。值 377 表示源已应答了前八个连续轮询。
offset:是源时钟与本地时钟的时间差(毫秒)。

 

 

设置开机启动

chkconfig ntpd on

 

 


参考:
https://www.cnblogs.com/vincenshen/p/6284933.html
https://blog.csdn.net/willinge/article/details/79928726
https://www.cnblogs.com/quchunhui/p/7658853.html
https://blog.csdn.net/jinyuxiaoqiang/article/details/81634827
https://www.cnblogs.com/quchunhui/p/7658853.html

 

posted @ 2019-05-28 17:24  anobscureretreat  阅读(1599)  评论(0编辑  收藏  举报