码迷,mamicode.com
首页 > 其他好文 > 详细

centos7 NTP server

时间:2018-02-14 13:52:38      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:hwclock   跟踪   本地   window   时间同步   query   局域网   更改   设置   

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议

 

安装ntp包

yum install -y ntp

 

修改NTP的配置文件

vim /etc/ntp.conf

driftfile /var/lib/ntp/drift   //服务器系统时间与上级服务器时间的偏差值记录

restrict default kod nomodify notrap nopeer noquery

restrict 127.0.0.1  //允许本服务器一切的操作

restrict 192.168.200.0  mask 255.255.255.0 nomodify notrap  //允许局域网内所有客户端连接到这台服务器同步时间,但不能对ntpserver进行时间上的修改,不提供trap远程登录功能。

server time1.aliyun.com prefer   //首选

server cn.ntp.org.cn

server s1a.time.edu.cn

server 127.127.1.0            //若与上级服务器同步失败,则以自身时间为标准时间

fudge  127.127.1.0 stratum 10 //指定本地服务器的层(1~10)

 

4、启动NTP服务器之前先与上级服务器做一个同步,使得NTP服务器时间尽量接近标准时间

ntpdate time1.aliyun.com

14 Jul 12:10:27 ntpdate[2222]: adjust time server 115.28.122.198 offset 0.002052 sec

 

5、启动管理服务

systemctl restart ntpd

systemctl enable ntpd

ss -ntlu | grep 123

udp    UNCONN     0      0      192.168.200.101:123                   *:*

udp    UNCONN     0      0      127.0.0.1:123                   *:*

udp    UNCONN     0      0         *:123                   *:*

udp    UNCONN     0      0      fe80::20c:29ff:fe08:aa3c%ens32:123                  :::*

udp    UNCONN     0      0       ::1:123                  :::*

udp    UNCONN     0      0        :::123                  :::*

 

服务启动后不能再进行手工同步。

 

7、NTP客户端同步时间

  • Linux客户端

ntpdate 192.168.200.101 && hwclock -w

crontab -e
0 0 * * *  /usr/sbin/ntpdate 192.168.200.101 && /usr/sbin/hwclock -w

    • Windows 客户端

技术分享图片

相关命令

timedatectl       #查看时区

timedatectl set-timezone Asia/Shanghai #更改时区为亚洲上海

timedatectl set-ntp yes                             #启动ntp时间同步

timedatectl      #查看ntp时间设置

date -s "2000/01/01 00:00:00"                  #手动设置日期时间

hwclock --set --date="2000-12-01 00:00:00"  #设置硬件时间

hwclock -r       #查看硬件时间

hwclock -w      #以系统时间为准,修改硬件时间

hwclock -s       #以硬件时间为准,修改系统时间

ntpstat            #服务状态查询

ntpq -p           #同步过程跟踪(ntp服务必须在运行状态)

ntptrace        #ntp跟踪时钟源 (可能需要安装ntp-perl,ntp服务必须在运行状态)

ntpdate -d time1.aliyun.com #延迟、时间差值查询命令

centos7 NTP server

标签:hwclock   跟踪   本地   window   时间同步   query   局域网   更改   设置   

原文地址:https://www.cnblogs.com/liang-yao/p/8448207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!