NTP服务器搭建
验证NTP软件包是否安装
[root@localhost ~]# rpm -qa ntp*
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
ntp-4.2.6p5-29.el7.centos.2.x86_64
安装ntp包
[root@localhost ~]# yum -y install ntp
配置ntp配置文件
[root@localhost ~]# yum -y install ntp
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 192.168.17.10 nomodify notrap nopeer noquery #当前节点ip地址
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.168.17.2mask 255.255.255.0 nomodify notrap #集群所在网段的网关(Gateway),子网掩码(Genmask)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
#选择一个主节点 在server部分添加一下部分,
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
#主节点以外,在server部分添加如下语句,将server指向主节点。
server 192.168.17.10
Fudge 192.168.17.10 stratum 10
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
启动ntp
systemctl start ntpd.service 或 service ntpd start 启动
systemctl enable ntpd.service
systemctl status ntpd.service 状态
查看ntp服务器有无和上层ntp连通
ntpstat
查看ntp服务器与上层ntp的状态
ntpq -p
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*202.118.1.130 .PTP. 1 u 40 64 377 51.713 2.895 4.108
-sv1.ggsrv.de 192.53.103.103 2 u 32 64 177 268.687 27.531 6.991
+tock.ntp.infoma .GPS. 1 u 29 64 353 183.400 -5.123 4.492
+service0-eth4.d 193.6.222.95 2 u 41 64 167 210.721 -5.117 26.617
LOCAL(0) .LOCL. 5 l 604 64 0 0.000 0.000 0.000
remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid:参考上一层ntp主机地址
st:stratum阶层
when:多少秒前曾经同步过时间
poll:下次更新在多少秒后
reach:已经向上层ntp服务器要求更新的次数
delay:网络延迟
offset:时间补偿
jitter:系统时间与bios时间差
查看ntpd进程的状态
【命令】watch “ntpq -p”
【终止】按 Ctrl+C 停止查看进程。
第一列中的字符指示源的质量。星号 ( * ) 表示该源是当前引用。
remote:列出源的 IP 地址或主机名。
when:指出从轮询源开始已过去的时间(秒)。
poll:指出轮询间隔时间。该值会根据本地时钟的精度相应增加。
reach:是一个八进制数字,指出源的可存取性。值 377 表示源已应答了前八个连续轮询。
offset:是源时钟与本地时钟的时间差(毫秒)。
设置开机启动
chkconfig ntpd on