利用chrony和ntp搭建时间同步服务器

环境说明

系统版本    CentOS 6.9 x86_64

Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务。NTP服务器将本地系统的时钟与一个公共的NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时钟。

同步时钟最大的好处就是相关系统上日志文件中的数据,如果网络中使用中央日志主机集中管理日志,得到的日志结果就更能反映真实情况。在同步了时钟的网络中,集中式的性能监控、服务监控系统能实时的反应系统信息,系统管理员可以快速的检测和解决系统错误。

利用chrony搭建步骤

1、安装

  1. [root@m01 ~]# yum install chrony –y  

 

2、配置

修改默认配置,设置上游时间服务器地址、允许同步时间的客户端ip地址范围

  1. [root@m01 ~]# vim /etc/chrony.conf  
  2. # Use public servers from the pool.ntp.org project.  
  3. # Please consider joining the pool (http://www.pool.ntp.org/join.html).  
  4. server ntp1.aliyun.com iburst       #上游时间服务器的地址  
  5. server ntp2.aliyun.com iburst  
  6. server ntp3.aliyun.com iburst  
  7. server ntp4.aliyun.com iburst  
  8. # Ignore stratum in source selection.  
  9. stratumweight 0  
  10.   
     
  11. # Record the rate at which the system clock gains/losses time.  
  12. driftfile /var/lib/chrony/drift  
  13.   
     
  14. # In first three updates step the system clock instead of slew  
  15. # if the adjustment is larger than 10 seconds.  
  16. makestep 10 3  
  17.   
     
  18. # Enable kernel synchronization of the real-time clock (RTC).  
  19. rtcsync  
  20.   
     
  21. # Allow NTP client access from local network.  
  22. allow 192.168.1.0/24            #允许同步时间的ip范围  

 

3、启动

  1. [root@m01 ~]# /etc/init.d/chronyd start  
  2. Starting chronyd:                                          [  OK  ]  
  3. 端口  
  4. udp        0      0 0.0.0.0:123                 0.0.0.0:*                               21133/chronyd  

 

4、测试

4.1、服务端测试

修改时间同步服务器的时间,等待片刻再查看时间

  1. [root@m01 ~]# date -s 20170514  
  2. Sun May 14 00:00:00 CST 2017  
  3. [root@m01 ~]# date  
  4. Tue May 15 17:52:39 CST 2018  

4.2、在其他机器测试

修改db01的时间,执行命令ntpdate 192.168.1.61(即自己搭建的时间同步服务器的内网ip)同步时间

  1. [root@db01 ~]# date -s 20170501  
  2. Mon May  1 00:00:00 CST 2017  
  3. [root@db01 ~]# ntpdate 192.168.1.61  
  4. 15 May 17:55:18 ntpdate[2414]: step time server 192.168.1.61 offset 32810061.803564 sec  
  5. [root@db01 ~]# date  
  6. Tue May 15 17:55:21 CST 2018  

 

利用ntp搭建步骤

1、安装

  1. [root@m01 ~]# yum install ntp ntpdate -y

 

2、配置

  1. [root@m01 ~]# vim /etc/ntp.conf  
  2. # For more information about this file, see the man pages  
  3. # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).  
  4.   
     
  5. driftfile /var/lib/ntp/drift  
  6.   
     
  7. # Permit time synchronization with our time source, but do not  
  8. # permit the source to query or modify the service on this system.  
  9. restrict default kod nomodify notrap nopeer noquery           
  10. #restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器(默认即可)  
  11. restrict -6 default kod nomodify notrap nopeer noquery  
  12. #配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(默认即可)  
  13. # Permit all access over the loopback interface.  This could  
  14. # be tightened as well, but to do so would effect some of  
  15. # the administrative functions.  
  16. restrict 127.0.0.1  
  17. restrict -6 ::1  
  18. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap  
  19. #指定的192.168.1.0--192.168.1.254的服务器都可以使用ntp服务器来同步时间  
  20. server 192.168.1.61     #指定本机作为局域网中的ntp服务器  
  21. # Hosts on local network are less restricted.  
  22. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap  
  23.   
     
  24. # Use public servers from the pool.ntp.org project.  
  25. # Please consider joining the pool (http://www.pool.ntp.org/join.html).  
  26. server ntp1.aliyun.com iburst           #指定上游时间服务器  
  27. server ntp2.aliyun.com iburst  
  28. server ntp3.aliyun.com iburst  
  29. server ntp4.aliyun.com iburst  
  30. 后面内容省略  

 

3、启动

  1. [root@m01 ~]# /etc/init.d/ntpd start        #启动  
  2. Starting ntpd:                                             [  OK  ]  
  3. 端口  
  4. udp        0      0 192.168.1.61:123            0.0.0.0:*                               21345/ntpd            
  5. udp        0      0 10.0.0.61:123               0.0.0.0:*                               21345/ntpd            
  6. udp        0      0 127.0.0.1:123               0.0.0.0:*                               21345/ntpd            
  7. udp        0      0 0.0.0.0:123                 0.0.0.0:*                               21345/ntpd            
  8. udp        0      0 fe80::20c:29ff:fe1b:6ae:123 :::*                                    21345/ntpd            
  9. udp        0      0 fe80::20c:29ff:fe1b:6b8:123 :::*                                    21345/ntpd            
  10. udp        0      0 ::1:123                     :::*                                    21345/ntpd            
  11. udp        0      0 :::123                      :::*                                    21345/ntpd    

 

4、测试

4.1、服务端执行ntpq -p检查

  1. [root@m01 ~]# ntpq -p  
  2.      remote           refid      st t when poll reach   delay   offset  jitter  
  3. ==============================================================================  
  4.  192.168.1.61    .INIT.          16 u    -   64    0    0.000    0.000   0.000  
  5. *time5.aliyun.co 10.137.38.86     2 u   59   64    3   23.174   15.665   9.655  
  6. +120.25.115.19   10.137.53.7      2 u   58   64    3   52.023   14.674   9.927  
  7. +203.107.6.88    10.137.55.181    2 u   57   64    3   39.007    4.241   0.497  

当所有远程服务器(不是本地服务器)的jitter值都为4000,并且reach和dalay的值是0时,就表示时间同步有问题。可能原因有2个:

  1)服务器端的防火墙设置,阻断了123端口(可以用 iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT 解决)

2)每次重启ntp服务器之后,大约3-5分钟客户端才能与服务端建立连接,建立连接之后才能进行时间同步,否则客户端同步时间时会显示

若遇到no server suitable for synchronization found的报错信息,稍等片刻再测试即可

4.2、在其他机器测试

修改db01的时间,执行命令ntpdate 192.168.1.61(即自己搭建的时间同步服务器的内网ip)同步时间

  1. [root@db01 ~]# date -s 20170501  
  2. Mon May  1 00:00:00 CST 2017  
  3. [root@db01 ~]# ntpdate 192.168.1.61  
  4. 15 May 17:55:18 ntpdate[2414]: step time server 192.168.1.61 offset 32810061.803564 sec  
  5. [root@db01 ~]# date  
  6. Tue May 15 17:55:21 CST 2018  

 

 

博主原创文章,转载请务必注明出处

利用chrony和ntp搭建时间同步服务器的更多相关文章

  1. CentOS7使用NTP搭建时间同步服务器

    前言 为什么要搭建时间同步服务器呢?场景是这样的. 我们有两台CentOS服务器,其中一台是可以连接外网的,下文中我们称它为A服务器,另一台不能连接外网,但是与A服务器在同一局域网中,下文中我们称它为 ...

  2. CentOS7.x搭建时间同步服务器

    关于chrony Chrony是一个开源的自由软件,像CentOS7或基于RHEL 7操作系统,已经是默认服务,默认配置文件在 /etc/chrony.conf 它能保持系统时间与时间服务器(NTP) ...

  3. 使用ntp从时间同步服务器更新centos系统时间的方法

    CentOS系统时间同步的步骤如下: 复制代码 代码如下: cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimentpdate us.pool.ntp ...

  4. 利用nginx与nginx-rtmp-module搭建流媒体服务器实现直播

    使用环境是centos 7.0+nginx:可以实现简单的流媒体服务. 先下载nginx-rtmp-module拓展: nginx-rtmp-module的官方github地址:https://git ...

  5. 用Nginx搭建CDN服务器方法-开启Nginx缓存与镜像,自建图片服务器

    利用Nginx的proxy_cache搭建缓存服务器一:编译ngx_cache_purge1.Nginx的Proxy_cache是根据Key值md5哈希存储缓存,支持任意的Key,例如你可以根据”域名 ...

  6. centos7搭建ntp时间同步服务器chrony服务

    centos7搭建ntp时间同步服务器chrony服务 前言: 在centos6的时候我们基本使用的是ntp服务用来做时间同步,但是在centos7后推荐是chrony作为时间同步器的服务端使用, ...

  7. 时间同步服务器NTP搭建

    NTP服务器        NTP(Network Time Protocol)[网络时间协议],它是用来同步网络中各个计算机的时间的协议,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒, ...

  8. 利用NTP搭建自己的ntp服务

    利用NTP搭建自己的ntp服务 发表于 2013 年 9 月 22 日 作者 admin 对于校园网/企业用户,如果您网内所有计算机都通过互联网同步时间,在速度和精度上都有一定的折扣,并且对互联网出口 ...

  9. 时间同步服务器NTP

    NTP服务器        NTP(Network Time Protocol)[网络时间协议],它是用来同步网络中各个计算机的时间的协议,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒, ...

随机推荐

  1. BZOJ1196 [HNOI2006]公路修建问题 【二分 + Kruskal】

    题目 OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情况还是很糟糕.所以,OIER Association组织成立了,旨在建立O ...

  2. mongo基本命令

    > show dbs    -- 查看数据库列表 > use admin   --创建admin数据库,如果存在admin数据库则使用admin数据库 > db   ---显示当前使 ...

  3. Topcoder SRM 605 div1 题解

    日常打卡- Easy(250pts): 题目大意:你有n种汉堡包(统统吃掉-),每一种汉堡包有一个type值和一个taste值,你现在要吃掉若干个汉堡包,使得它们taste的总和*(不同的type值的 ...

  4. Linux : 使用 lsof 恢复文件

    用 lsof 命令在某种程度上可以恢复删除的文件, 前提是这个文件被正在运行的进程占用. 比如: 日志文件, 配置文件. lsof 恢复文件 查找需要恢复的文件和占用文件的进程 PID lsof |g ...

  5. .net 网站首页,本次的项目中用到的一个网站首页中统计网页访问量的工具方法,我觉得它应该在pagebase里面,拿来用一下

    需要建立一个根文件夹 ~/xml/couter.txt #region 网站访问量         protected void pageviews() {             int count ...

  6. cocos2d programming guide 翻译 引导页(完结)

    http://bbs.tairan.com/article-25-1.html  Cocos2d官方入门指导 原文地址:http://www.cocos2d-iphone.org/wiki/doku. ...

  7. Windows下VS2013创建与使用动态链接库(.dll)

    一.创建动态链接库文件 ** 1.打开VS2013,选择文件,新建工程  2.选择新建W32控制台应用程序,这里将工程名改为makeDLL  3.在应用程序类型中选择DLL,点击完成  4.完成以上步 ...

  8. Centos 查看硬盘空间

    df -h du -ah --max-depth=1 目录深度为1 -h:以人类可读的方式显示 -a:显示目录占用的磁盘空间大小,还要显示其下目录和文件占用磁盘空间的大小 -s:显示目录占用的磁盘空间 ...

  9. UVA 1604:Cubic Eight-Puzzle(模拟,BFS Grade C)

    题意: 3*3方格,有一个是空的.其他的每个格子里有一个立方体.立方体最初上下白色,前后红色,左右蓝色.移动的方式为滚.给出初态空的位置,终态上面颜色情况,问最少多少步能到达.如果超过30步不能到达, ...

  10. 第二部分:Spring中配置mongodb

    一.需要引用的jar包 1.spring-data-mongodb-1.9.4.RELEASE.jar 2.spring-data-commons-1.12.11.RELEASE.jar 3.mong ...