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 09:48
下一篇 2015-06-24 10:03

相关推荐

  • DNS配置案例 二

    DNS配置案例 二 DNS配置案例 二 1 §·DNS的配置与案例 1 §·测试工具 3 §·主配置文件格式:/etc/named.conf 7 §·缓存名称服务器的配置: 8 §·配置解析一个正向区域 : 以loveme.com域为例: 10 §·配置解析一个反向区域 : 以loveme.com域为例: 15 §·配置从DNS服务器 19 §·问…

    Linux干货 2016-09-26
  • N28-第三周

    1. 列出當前系統上所有已經登入的用戶的用戶名,注意:同一個用戶登入多次,則只顯示一次即可。
    2. 取出最後登入到當前系統的用戶的相關信息。
    3. 取出當前系統上被用戶當做其默認shell的最多的那個shell。
    4. 將/etc/passwd中的第三個字段數值最大的後10個用戶的信息全部改為大寫後保存至/tmp/maxusers.txt文件中。
    5. 取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
    6. 列出/etc目錄下所有以.conf結尾的文件的文件名,並將其名字轉換為大寫後保存至/tmp/etc.conf文件中。
    7. 顯示/var目錄下一級子目錄或文件的總各數。
    8. 取出/etc/group文件中第三個字段數值最小的10個組的名字。
    9. 將/etc/fstab和/etc/issue文件的內容合併為同一個內容後保存至/tmp/etc.test文件中。
    10. 請總結描述用戶和組管理類命令的使用方法並完成以下練習:
    (1) 創建組distro,其GID為2016。
    (2) 創建用戶mandriva,其ID號為1005,基本組為distro。
    (3) 創建用戶mageia,其ID號為1100,家目錄為/home/linux。
    (4) 給用戶mageia添加密碼,密碼為mageedu。
    (5) 刪除mandriva,但保留其家目錄。
    (6) 創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin。
    (7) 修改slackware的默認shell為/bin/tcsh。
    (8) 為用戶slackware新增附加組admins。

    2017-12-19
  • 网络配置——CentOS7

    CentOS 7 网络属性配置 使用传统命名方式: (1) 编辑/etc/default/grub 配置文件 GRUB_CMDLINE_LINUX ="rhgb quiet net.ifnames=0" 或:修改/boot/grub2/grub.cfg (2) 为grub2 生成其配置文件 grub2-mkconfig -o /etc/g…

    Linux干货 2016-09-11
  • linux磁盘管理及文件系统

    linux磁盘管理及文件系统 硬盘存储术语    head:磁头          track:磁道          cylinder: 柱面    &nbsp…

    Linux干货 2016-08-26
  • 马哥教育网络班21期+第1周课程练习

    一、计算机原理及组成部分 数学家冯·诺依曼,按不同功能把计算机分成了五大组成部分:运算器、控制器、存储器、输入设备、输入出设备。 现代计算机把运算器和控制器集成在一起,称为CPU,主要进行各种数据运算和对各种命令进行解释;存储器被分为两类,一类以内存为代表的随机存储设备,主要特点是速度快,容量有限,断电后信息就消失,另一类是硬盘为代表的外部存储设备,容量大,…

    Linux干货 2016-06-26
  • Linux运维学习历程-第十天-文件查找工具

    概述:本篇主要讲解locate命令和find命令,来帮助我们在linux中完成文件查找,方便我们快速定位文件。 一、文件查找    即在文件系统上查找符合条件的文件,常用工具有locate和find  1、locate命令    locate命令其实是find -name的另一种写法,但是要比后者快得多,原因…

    Linux干货 2016-08-21

评论列表(1条)

  • jemmy
    jemmy 2015-11-19 15:00

    学习了,谢谢分享!