Ntp时间服务器

    NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

NTP服务器就是利用NTP协议提供时间同步服务的。

     时间对服务器之间的通信,信息交流非常重要

    一般情况下我们可以同步时间服务器,例如:ntp1.aliyun.com

  0.0.0 普通机器时间同步定时任务

crontab -e
#sync time by yanshichneg 2018
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1

1.1.1 Ntp服务器搭建

[root@Linux-node6-example ~]# rpm -qa ntp
ntp-4.2.6p5-28.el7.centos.x86_64

yum -y install ntp

1.1.2 修改ntp配置文件

[root@oldboyedu ~]# vim /etc/ntp.conf
#控制时间服务器同步权限
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# 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 ntp1.aliyun.com
server time.nist.gov

#sed替换
[root@Linux-node6-example ~]# sed -i.bak '8s#restrict.*noquery#restrict default nomodify#;21,24d;20a server ntp1.aliyun.com
server time.nist.gov' /etc/ntp.conf 

1.1.3 启动

[root@Linux-node6-example ~]# systemctl start ntpd
[root@Linux-node6-example ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2018-09-04 20:34:16 CST; 6s ago

1.1.4 检查

#查看上级时间服务器的状态
[root@Linux-node6-example ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   10.137.53.7      2 u   50   64    1   45.899    0.364   0.000
 time-b-wwv.nist .INIT.          16 u    -   64    0    0.000    0.000   0.000
#查看时间同步状态

  [root@Linux-node6-example ~]# ntpstat
  synchronised to NTP server (120.25.115.20) at stratum 3
  time correct to within 980 ms
  polling server every 64 s

 

1.1.5 客户端使用ntp服务器

[root@Linux-node7-example ~]# ntpdate 192.168.10.22
 4 Sep 20:39:55 ntpdate[33164]: adjust time server 192.168.10.22 offset 0.004388 sec

#放入定时任务

crontab -e
#sync time by yanshichneg 2018
*/5 * * * * /usr/sbin/ntpdate 192.168.10.22 >/dev/null 2>&1
原文地址:https://www.cnblogs.com/yanshicheng/p/9588387.html