首页 > 技术文章 > NTP时间服务器

jksbaduen 2017-11-10 15:32 原文

  1. NTP简介

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

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

  1. NTP时间服务器搭建

  2. 实验环境

    1. 操作系统及内核版本

    1. [root@m01 ~]# cat /etc/redhat-release
    2. CentOS release 6.9 (Final)
    3. [root@m01 ~]# uname -r
    4. 2.6.32-696.el6.x86_64
      1. 主机IP地址规划

主机名

操作系统版本

外网IP

内网IP

用途

m01

CentOS release 6.9

10.0.0.71/24

172.16.1.71/24

时间服务器

 

  1. 安装ntp

yum -y install ntp

  1. 修改/etc/ntp.conf:

    1. 在文件中将restrict default kod nomodify notrap nopeer noquery 注释掉(前添加"#"),这个应该是对客户端的限制太多,所以把它去掉。
    2. restrict default kod notrap nomodify
    3. 注释掉默认的server同步,添加新的同步时间服务器
    4. server 0.cn.pool.ntp.org
    5. server 1.cn.pool.ntp.org
    6. server 2.cn.pool.ntp.org
    7. server 3.cn.pool.ntp.org
  2. 启动ntp服务

    1. [root@m01 /]# /etc/init.d/ntpd start
  3. 查看ntp服务状态

    1. [root@m01 /]# ntpstat
    2. synchronised to NTP server (101.6.6.172) at stratum 3
    3. time correct to within 329 ms
    4.  polling server every 64 s
  4. 客户端测试

    1. [root@tomcat ~]# ntpdate 172.16.1.61
    2. 27 Jul 09:16:43 ntpdate[16670]: step time server 172.16.1.61 offset -46031.777540 sec
  5. 添加到定时任务

    1. echo "*/5 * * * * /usr/sbin/ntpdate ntp 172.16.1.71 &>/dev/null"

注释 :配置好服务器后,需要一段时间才能同步 !在客户端测试的时候后会出现一下问题。过 10 到 15 分钟就好了

推荐阅读