1. NTP服务器搭建

 安装ntp yum install -y ntp

2. 外网使用阿里云ntp服务器作为基准

阿里云ntp服务器列表:
time1.aliyun.com
time2.aliyun.com
time3.aliyun.com
time4.aliyun.com
time5.aliyun.com
time6.aliyun.com
time7.aliyun.com

先ntpdate检查能否和以上ntp服务器通信。ntpdate -q time1.aliyun.com

有以下输出表示正常

server 115.28.122.198, stratum 2, offset 53.490757, delay 0.0670913 Sep 15:27:48 ntpdate[16092]: step time server 115.28.122.198 offset 53.490757 sec

3. 修改配置文件

vim /etc/ntp.conf 做出以下修改

# 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 127.0.0.1restrict ::1 # 允许1-4网段的服务器来校时,不允许客户端来修改,登录ntp服务器 restrict 192.168.1.0 mask 255.255.255.0 nomodify notraprestrict 192.168.2.0 mask 255.255.255.0 nomodify notraprestrict 192.168.3.0 mask 255.255.255.0 nomodify notraprestrict 192.168.4.0 mask 255.255.255.0 nomodify notrap  # Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 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 time1.aliyun.comserver time2.aliyun.comserver time3.aliyun.comserver time4.aliyun.comserver time5.aliyun.comserver time6.aliyun.comserver time7.aliyun.com #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 # Enable public key cryptography.#crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted.#trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility.#requestkey 8 # Specify the key identifier to use with the ntpq utility.#controlkey 8 # Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats # Disable the monitoring facility to prevent amplification attacks using ntpdc# monlist command when default restrict does not include the noquery flag. See# CVE-2013-5211 for more details.# Note: Monitoring will not be disabled with the limited restriction flag.disable monitor # Enable Logfilelogfile /var/log/ntp.log

4. 使硬件时间和系统时间一致

修改配置文件 vim /etc/sysconfig/ntpd 添加

 SYNC_HWCLOCK=yes

5. 启动ntpd服务并查看状态

 systemctl start ntpd设置自动启动chkconfig ntpd on

等待10-15分钟后执行 ntpstat 查看同步状态

synchronised to NTP server (182.92.12.11) at stratum 3    time correct to within 470 ms   polling server every 64 s发现已经同步。

执行ntpq -p 查看与阿里云ntp服务器连接状态

     remote           refid      st t when poll reach   delay   offset  jitter==============================================================================+time6.aliyun.co 10.137.38.86     2 u   10   64   77   41.139    8.490   1.523-time4.aliyun.co 10.137.38.86     2 u    5   64   77    3.479   15.026   1.354*time5.aliyun.co 10.137.38.86     2 u   10   64   77   37.243   10.643   1.554+120.25.115.19   10.137.38.86     2 u    5   64   77    3.574    5.228   2.803

*表示目前正在使用的上层NTP,+表示已连线,可提供时间更新的候补服务器

执行一下 hwclock --systohc 使系统时间和硬件时间一致。

6. 打开防火墙

由于ntp服务使用 123端口udp协议 所以需要打开防火墙。
执行firewall-cmd --zone=public --add-port=123/udp --permanent之后,再执行firewall-cmd --reload

7. Linux 客户端使用ntpd服务同步时间

先安装ntp服务执行yum install -y ntp

修改配置文件 vim /etc/ntp.conf 修改server,添加日志

# 允许ntpserver主动修改客户端时间restrict 192.168.1.85 nomodify notrap noqueryrestrict 192.168.1.50 nomodify notrap noquery server 192.168.1.85server 182.168.1.50 logfile /var/log/ntp.log

其他保持默认。

启动 ntpd服务systemctl start ntpd

打开本地放火墙 123 UDP端口

执行 ntpq -p 查看与服务器连接状态。

    remote           refid      st t when poll reach   delay   offset  jitter==============================================================================+192.168.1.50    182.92.12.11     3 u   31   64   77    0.189  -30.963  42.392*192.168.1.85    182.92.12.11     3 u   43   64   77    0.190   -1.903  18.890 LOCAL(0)        .LOCL.          10 l   60   64   77    0.000    0.000   0.000

执行 ntpstat 查看同步状态

synchronised to NTP server (192.168.1.85) at stratum 4
time correct to within 131 ms
polling server every 64 s

8 Windows 使用客户端同步

8.1 组策略配置

win+r 运行gpedit.msc 启用全局配置

20170914-031152.png

启用ntp客户端

20170914-031233.png

win+r 执行 gpupdate /force

8.2. 使用自动配置工具

下载自动配置工具MicrosoftEasyFix50395.msi
下载地址在这个页面中 https://support.microsoft.com/zh-cn/help/816042/how-to-configure-an-authoritative-time-server-in-windows-server

运行自动配置工具,做以下配置,多个服务器用空格隔开。

20170914-031246.png

之后在系统时间日期内执行同步查看结果。

20170914-031302.png

参考资料
CentOS搭建NTP服务器http://msiyuetian.blog.51cto.com/8637744/1712561
Windows客户端同步NTP服务http://4921679.blog.51cto.com/4911679/914473
如何在 Windows Server 中配置权威时间服务器 https://support.microsoft.com/zh-cn/help/816042/how-to-configure-an-authoritative-time-server-in-windows-server

作者:若有所思11
链接:http://www.jianshu.com/p/199505ceebb1
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

ntp服务器搭建及客户端配置-使用阿里云相关推荐

  1. ubuntu20.4服务器搭建ftp并连接(阿里云服务器)

    首先在控制台添加ftp防火墙规则: 然后进入服务器安装ftp(安装vsftpd): sudo apt update sudo apt install vsftpd 使用以下命令检查其状态: sudo ...

  2. php对接AliGenie天猫精灵服务器控制智能硬件esp8266① 在阿里云购买搭建私有云服务器,配置 SSL 证书 ,做好准备工作!

    本系列博客学习由非官方人员 半颗心脏 潜心所力所写,仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 1. php对接AliGenie天猫精灵服务器控制智能硬件esp82 ...

  3. 离线NTP服务器搭建(Linux)

    离线NTP服务器搭建(Linux) 如果没能帮你解决问题,请在下方留言 实例: 服务端-192.168.111.143 客户端-192.168.111.170 1. 获取rpm包 解压操作系统的镜像文 ...

  4. 自有NTP服务器搭建

    1. ntp和ntpdate区别 NTP 全名 network time protocol,可以为其他主机提供时间校对服务.安装包名是ntp,守护进程为ntpd,配置文件是/etc/ntp.conf. ...

  5. linux 建立 ntp 服务器,NTP服务器搭建

    1.NTP(Network Time Protocol) 在计算机世界中,NTP(Network Time Protocol,网络时间协议)被广泛用于对时间的统一性和准确性要求非常高的场景,是用来使网 ...

  6. centos7 NTP服务器搭建

    NTP服务器搭建 验证NTP软件包是否安装 [root@localhost ~]# rpm -qa ntp* ntpdate-4.2.6p5-29.el7.centos.2.x86_64 ntp-4. ...

  7. Windows下安装NTP服务器——搭建时间同步服务器

    Windows下安装NTP服务器--搭建时间同步服务器 NTP服务器介绍 NTP服务器[Network Time Protocol(NTP)]是用来使计算机时间同步化的一种协议,它可以使计算机对其服务 ...

  8. 七日杀开服架设教程开服配置服务器搭建需要什么配置的服务器Linux系统

    七日杀开服架设教程开服配置服务器搭建需要什么配置的服务器Linux系统 新开放世界僵尸游戏 <七日杀>是由The Fun Pimps Entertainment研发的集合第一人称射击.恐怖 ...

  9. LINUX NTP 服务器搭建

    LINUX NTP 服务器搭建 ╮(╯▽╰)╭ , 这一生让我感到悲剧,关于LINUX NTP 服务器搭建,网上的资料太多了,但是有几个能详细的说明一下ntp.conf 文件呢,几乎都是千篇一律,同样 ...

最新文章

  1. 劣质代码评析——《写给大家看的C语言书(第2版)》附录B之21点程序(一)
  2. JS中的null和undefined,undefined为啥用void 0代替?
  3. 读过的好书[技术类]
  4. 模拟spring - 简单实现spring IOC
  5. WINCE设备开机灰屏问题(很怪异)
  6. LLLYYY的数字思维
  7. 高淇python讲义百度文库_python 面向对象01
  8. c# 插入树形数据#_C#数据类型能力问题 套装1
  9. oracle底层执行顺序,select语句结构与执行顺序-Oracle
  10. Django:模型层ORM
  11. Javascript 的模块化编程及加载模块【转载+整理】
  12. linux文件描述符有什么用,linux上的文件描述符3有什么特别之处?
  13. csdn学院的python培训怎么样_这段 Python 代码让程序员赚 300W,公司已确认!网友:神操作...
  14. 编译原理完整学习笔记(三):词法分析
  15. Android Studio下载、安装和配置+SDK+tools下载(无敌超级详细版本)
  16. c盘python27文件夹可以删除嘛_c盘哪些目录可以删除
  17. 串口屏和并口屏的区别?
  18. 华硕笔记本电池软件_成色配置都还不错的二手华硕7代 i5 笔记本电脑 只卖1599元 想要的 快进来看看...
  19. 大淘客cms源码修改二次开发实现淘京拼三合一功能
  20. python爬虫一:爬虫简介

热门文章

  1. Oracle的概念理解
  2. python滑动窗口求回归——OLS和WLS
  3. cocos2dx实现单机版三国杀(二)
  4. c51c语言编程的音乐程序,51单片机唱歌C51音乐程序.doc
  5. Progressive Downloader for Mac(mac不限速下载器)
  6. 2018年TI杯电子设计竞赛感悟
  7. 最新职教云自动签到PHP源码
  8. 组态王或SCADA与西门子200Smart通讯配置流程
  9. pandas读取excel-xlrd相关
  10. Java api 操作 kubernetes