ntp时间服务器搭建实例

ntp时间服务器采用stratum分级架构来处理时间同步;举例说明:你搭建了一台ntp服务器,然后同步的server为stratum-1,你的ntp则为stratum-2,你的下级ntp则为tratum-3。依此类推,最多为15层。

1.ntp server安装:

[root@localhost ~]# yum -y install ntp tzdata

ntp相关文件说明:

/etc/ntp.conf        ntp server配置文件
/usr/sbin/ntpd       ntp server程序
/usr/sbin/ntpdate    ntp client校正工具
/etc/sysconfig/clock 时区配置文件

2./etc/ntp.conf配置文件说明,主要配置restrict和server

#restrict设置格式:
#restrict [授权同步的网段] mask [netmask] [parameter]
例:restrict 192.168.6.0 mask 255.255.252.0 nomodify

parameter说明:
kod         kod技术可以阻止“Kiss of Death “包对服务器的破坏
nomodity    client可通过ntp进行时间同步,但不能更改server参数
notrap      不提供trap远程登陆功能
nopeer      不与其它同一层的ntp server进行时间同步
noquery     拒绝ntp时间同步
notrust     拒绝无认证的client
ignore      拒绝连接到ntp server

#server设置格式
#server [hostname|ip][parameter]
例:server   server asia.pool.ntp.org prefer
parameter说明:
prefer      最高优先级
burst       当一个运程NTP服务器可用时,向它发送一系列的并发包进行检测。
iburst      当一个运程NTP服务器不可用时,向它发送一系列的并发包进行检测。

3.ntp配置实例 server端

1)配置/etc/ntp.conf
[root@localhost ~]# vim /etc/ntp.conf
  1 # For more information about this file, see the man pages
  2 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
  3 
  4 driftfile /var/lib/ntp/drift
  5 
  6 # Permit time synchronization with our time source, but do not
  7 # permit the source to query or modify the service on this system.
  8 restrict default kod nomodify notrap nopeer noquery
  9 restrict -6 default kod nomodify notrap nopeer noquery
 10 
 11 # Permit all access over the loopback interface.  This could
 12 # be tightened as well, but to do so would effect some of
 13 # the administrative functions.
 14 restrict 127.0.0.1
 15 restrict -6 ::1
 16 
 17 # Hosts on local network are less restricted.
 18 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 19 restrict 192.168.6.0 mask 255.255.252.0 nomodify
 20 
 21 # Use public servers from the pool.ntp.org project.
 22 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 23 #server 0.centos.pool.ntp.org iburst
 24 #server 1.centos.pool.ntp.org iburst
 25 #server 2.centos.pool.ntp.org iburst
 26 #server 3.centos.pool.ntp.org iburst
 27 server asia.pool.ntp.org prefer
 28 server 0.asia.pool.ntp.org
 29 server 1.asia.pool.ntp.org
 30 server 2.asia.pool.ntp.org
 31 server time.nist.gov
 32 
 33 #broadcast 192.168.1.255 autokey        # broadcast server
 ...

2)NTP启动与端口检查:
[root@localhost ~]# service ntpd start
Starting ntpd:
[root@localhost ~]# chkconfig ntpd on
[root@localhost ~]# chkconfig --list |  grep ntp
ntpd           	0:关闭	1:关闭	2:启用	3:启用	4:启用	5:启用	6:关闭
ntpdate        	0:关闭	1:关闭	2:关闭	3:关闭	4:关闭	5:关闭	6:关闭
[root@localhost ~]# netstat -nutlp | grep ntp
udp        0      0 192.168.2.213:123           0.0.0.0:*                               21798/ntpd          
udp        0      0 192.168.6.213:123           0.0.0.0:*                               21798/ntpd          
udp        0      0 127.0.0.1:123               0.0.0.0:*                               21798/ntpd          
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               21798/ntpd          
udp        0      0 fe80::221:f6ff:fed4:d502:123 :::*                                    21798/ntpd          
udp        0      0 fe80::221:f6ff:fed4:d501:123 :::*                                    21798/ntpd          
udp        0      0 ::1:123                     :::*                                    21798/ntpd          
udp        0      0 :::123                      :::*                                    21798/ntpd  

3)ntp server与上联是否同步
#查看server与上联是否同步,时间校正约8279ms,每64s轮循更新一次。
[root@localhost ~]# ntpstat 
synchronised to NTP server (62.201.225.9) at stratum 3   #==>上层ntp
   time correct to within 8279 ms                        #==>校正时间差
   polling server every 64 s                             #==>下次同步时间
   
#查看server与上联的状态
[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.iqnet.com  62.201.214.162   2 u  146   64  124  393.411  -101.29  40.435
-220.231.122.105 123.204.45.116   4 u   20   64  377  341.475   58.745  47.945
+vps.jre655.com  10.84.87.146     2 u   24   64  377  211.095    0.177  38.002
 web10.hnshostin 158.43.128.33    2 u   17   64  177  392.506  -134.76  39.146
+24.56.178.140   .ACTS.           1 u   27   64  377  282.739  -59.521  42.959

参数说明:
reomte    server上联的ntp主机名或ip;
          注意最左端符号;*表示当前正使用的上层ntp;+代表与本机server也有连接,作为侯选ntp
refid     给上层ntp提供时间校对的服务器
st        上层npt stratum级别
when      上一次与上层ntp同步的时间,单位为秒。
poll      下一次与上层ntp同步的时间
reach     已经同上层ntp同步更新的次数
delay     网络传输过程中的延迟时间,单位为10^(-6)s
offset    时间补偿,单位为10^(-3)s
jitter    系统时间与bios硬件时间差,单位为10^(-6)s

4.ntp配置实例client端

通过crontab设置更新时间
[root@dns-2-253 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate 192.168.6.213 &> /dev/null

client测试是否同步成功
[root@dns-2-253 ~]# ntpdate 192.168.6.213
10 Nov 21:25:43 ntpdate[26381]: step time server 192.168.6.213 offset 1.318393 sec

备注:如果无法同步,需查是否开启了防火墙。

原创文章,作者:老鼠上了猫,如若转载,请注明出处:http://www.178linux.com/9226

(0)
老鼠上了猫老鼠上了猫
上一篇 2015-11-10
下一篇 2015-11-10

相关推荐

  • 压缩及解压工具

    通过算法压缩数据,时间换空间。文本文件的压缩比更大,二进制文件的压缩比较小。 压缩工具占用cpu时钟。 compress/uncompress .Z gzip/gunzip .gz bzip2/bunzip2 .bz2 压缩比比gz大但是也没取代gz xz/unxz .xz 压缩比大,现在较流行。 zip/unzip .zip 归档工具,既能归档又能压缩 t…

    Linux干货 2016-08-21
  • Linux 用户、用户组及权限管理

    一、Linux用户及用户组的基本概念 用户:用户是实现能够将有限的资源在多个使用者之间进行分配;、 用户组:用户组是指多个用户的集合,方便对一类需要同样权限的用户授权 Linux是多用户、多任务的操作系统。     多用户指:多人同时使用系统资源;多任务:同时运行多个进程 二、用户及用户组类别 1、用户:名称解析库 /…

    Linux干货 2016-03-20
  • 系统基础之shell脚本编程详解3(函数)

    shell脚本编程详解3:    在前两节我们分别介绍了shell脚本编程的基础和循环,判断的知识,今天我们分享脚本的另一种用法,函数. 概论:     函数function是由若干条shell命令组成的语句块,实现代码重用和模块化编程。    它与shell…

    Linux干货 2016-08-22
  • 软链接和硬链接的区别

    文件管理 前言 Linux的一则哲学:一切皆文件。既然入坑,那么管理linux就是管理一堆文件,操作文件这是展示个人十八般武艺的时候,功夫高下一招下。怎么成为高手,高手的招式都有哪些,拳脚掌刀枪棍棒,一招一式如何练就。 1文件存储 文件存储就好比每个练武人必备的技能——挨打,在你耍十八般武艺前,必须先扛住对方的一掌。我们不必拥有金刚罩铁布衫,至少要学会如何躲…

    Linux干货 2016-10-20
  • Linux网站架构系列之Mysql—-部署篇

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1321079   MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。MySQL所使用的SQL语言是用于…

    Linux干货 2015-04-01
  • 权限管理和文本过滤

    1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限 [root@study ~]# cp -r /etc/skel/ /home/tuser1|chmod -R 700 tuser1/ [root@…

    Linux干货 2016-11-20

评论列表(2条)

  • stanley
    stanley 2015-11-10 22:41

    非常有参考价值,上次我们部署crond的时候遇到不少问题,一个crond不生效,一个报错已有进程运行中

    • 老鼠上了猫
      老鼠上了猫 2015-11-13 20:44

      @stanley这样配置有个奇怪的地方,restrict明明只放行了内网,但在机房外部却可通过服务器的外网ip进行ntp同步。