ntp时间服务器

前言

  ntp(Network Time protocol)是网络时间协议,是用来使网络中的各个计算机时间同步的一种协议。

ntp配置

 1)ntp是由ntp软件提供,如果没有可以使用yum进行安装

 2)ntp配置文件介绍:/etc/ntp.conf

  利用restrict来管理权限控制;语法格式:restrict IP mask MASK [parameter]

   常用的parameter有以下几类:

     ignore:拒绝所类型的ntp连接

     nomodify:客户端只能通过此服务器进行时间同步;不能使用ntpc或ntpq这两种方式来修改时间;

     noquery:不提供网络时间校验功能

     notrap:不支持远程登录的时间戳

     notust:拒绝认证不通过的客户端

   注意:如果parameter没有任何参数,表示来接受自任何网络的时间同步请求  

  利用server定义上层ntp服务器;语法格式 server SERVER_IP [prefer];prefer表示首先使用此服务器地址

  利用driftfile记录时间差异;默认记录位置是/var/lib/ntp/drift;

   注意:若果要修改保存路径,要确保ntpd用户对目标文件有写入权限

  利用key提高安全性;语法格式: key  key_file 

 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 kod nomodify notrap nopeer noquery \\拒绝所有ipv4用户
restrict -6 default kod nomodify notrap nopeer noquery \\拒绝所有ipv6用户

# 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  202.120.2.101  \\放行来自202.120.2.101地址进入本服务器
restrict 127.0.0.1     \\放行本机来源
restrict -6 ::1       \\放行本机来源

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 172.16.2.0 mask 255.255.255.0 nomodify \\放行本地局域网络进入本机

# 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 202.120.2.101 prefer   \\定义此服务器为首先使用的时间服务器
server s1b.time.edu.cn      \\定义备用的时间服务器
server s1c.time.edu.cn      \\定义备用的时间服务器
#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

 4)启动ntpd服务;查看监听端口

# service ntpd start
#netstat -upln
Proto Recv-Q Send-Q Local Address   Foreign Address      State       PID/Program name 
udp   0    0   172.16.2.13:123    0.0.0.0:*                        11303/ntpd
udp   0    0      0.0.0.0:123     0.0.0.0:*                 11303/ntpd

 5)等待大约15分钟左右,使用ntpstat查看,自己定义的ntp服务器已经开始与网络时间服务器进行同步

 # ntpstat
synchronised to NTP server (202.120.2.101) at stratum 4 
   time correct to within 176 ms
   polling server every 64 s

 6)  使用ntpq -p可以查看ntp服务器状态

# ntpq -p
  remote          refid    st t when poll reach   delay   offset  jitter
==================================================================================================
*dns.sjtu.edu.cn 202.118.1.130 3  u  60  64  275   34.939   -5.211   4.329
 ntpa.nic.edu.cn  .STEP.   16 u  -  1024   0    0.000    0.000   0.000
 202.112.7.150   .STEP.   16 u  -  1024   0    0.000    0.000   0.000

 remote: ntp服务器的上层服务器;如果前面有*代表是正在使用的ntp服务器,+代表ntp服务端已连接,可做为备用ntp服务器

 refid:上层ntp服务器的校准服务器

 st:NTP上层服务器的级别

 when: 多少秒之前与上层服务器同步过时间

 poll:多长时间之后与上层服务器再次进程同步时间   

 reach:已经向上层ntp服务器同步的次数

 delay:时延;单位 10^(-3)秒

 offset:时间补偿的结果;单位与 10^(-3)秒                               

 jitter:linux系统时间与BIOS硬件的差异时间;单位与10^(-3)秒

详情请参考:http://linux.vbird.org/linux_server/0440ntp.php

原创文章,作者:马行空,如若转载,请注明出处:http://www.178linux.com/5569

(1)
马行空马行空
上一篇 2015-06-24
下一篇 2015-06-24

相关推荐

  • linux中用ACL实现灵活的权限管理

    ACL是什么?? ACL英文原意是Access Control List(访问控制列表).它能够实现灵活的权限管理,除了文件的所有者,所属组和其他人,设置相应的权限外,ACL允许你给任何用户或是用户组设置任何文件/目录的访问权限(注意的是有些不支持数字模式的权限给定) ACL有什么用?? 作为UGO权限管理的补充,acl有GUO办不到或者是难以办到的功能 &…

    Linux干货 2016-08-05
  • 系统基础之shell脚本编程详解2

    shell脚本编程2:   在上节我们介绍了shell脚本编程,但只是介绍了基础的内容,下面将为大家介绍shell的脚本的高级用法,判断与循环.判断分为两种:if语句和case语句;循环分为三种:for语句,while语句,until语句,select语句 判断语句:  在脚本的编写中,我们要使用大量的数据和命令,但对于使用的数据,我们要…

    Linux干货 2016-08-19
  • 逻辑卷管理

    逻辑卷管理 一 创建逻辑卷 1 准备分区或硬盘 这里使用/dev/sdb、/dev/sdc两块硬盘和/dev/sda9、/dev/sda10两个分区,大小都为1G,磁盘有限,我也不想这么抠的。 添加分区/dev/sda9、 /dev/sda10 [root@centos7 ~]# fdisk /dev/sda Welcome to fdisk (u…

    Linux干货 2017-05-02
  • 数学集合–德摩根定律

    初中数学学过集合的概念: ~表示补集 ∩表示交集 ∪表示并集 ∈表示属于 !表示取反 条件: x属于C集合中之外的部分:~C 证明:   ∵x∈~C    x属于集合c的补集     x∈~(A∩B)    想属于a和b…

    Linux干货 2016-08-15
  • ​20151208完成了第二天课程中的第一课:Osey Linux发行版(01)

    完成了第二天课程中的第一课:Osey Linux发行版(01) 今天公司晚上有加班,回来晚了。只完成了第一课:Osey Linux发行版(01) 简要笔记如下: Linux哲学思想:    1、一切皆文件:             把几乎所有的资源,包括硬件设备都组织为文件格式;…

    Linux干货 2015-12-10
  • 设计模式(十一)代理模式Proxy(结构型)

    1.概述        因为某个对象消耗太多资源,而且你的代码并不是每个逻辑路径都需要此对象, 你曾有过延迟创建对象的想法吗 ( if和else就是不同的两条逻辑路径) ? 你有想过限制访问某个对象,也就是说,提供一组方法给普通用户,特别方法给管理员用户?以上两种需求都非常类似,并且都需要解决一个更大的问题:你如何提供…

    Linux干货 2015-07-09

评论列表(1条)

  • jemmy
    jemmy 2015-11-19 15:00

    学习了,谢谢分享!