RHEL7.4 192.168.100.1 作为时间服务器,其它主机到这台来同步时间。

时间服务器安装及配置:
#yum install chrony --RHEL7默认已安装chrony,而没有安装ntpd.

#systemctl status chronyd --查看chronyd服务状态
#systemctl enable chronyd --开机启动

#vi /etc/chrony.conf    --修改配置文件

#server 0.rhel.pool.ntp.org iburst   --注释这4行,由于是内网环境,所以无法跟外部时间服务器进行时间同步。
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
  server 192.168.100.1 iburst    --添加这一行,表示与本机同步时间
 
local stratum 10    --该行取消注释

# Allow NTP client access from local network.
allow 192.168.100.0/24   --允许哪些服务器到这台服务器来同步时间

#systemctl restart chronyd --修改完配置文件后,重启chronyd服务

[root@rhel1 ~]# netstat -antulp | grep chronyd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           705/chronyd        
udp        0      0 127.0.0.1:323           0.0.0.0:*                           705/chronyd        
udp6       0      0 ::1:323                 :::*                                705/chronyd


1.显示系统的当前时间和日期

timedatectl
# timedatectl status
# 两条命令效果等同

[root@rhel1 ~]# timedatectl
       Local time: Sat 2017-10-07 10:55:22 CST
   Universal time: Sat 2017-10-07 02:55:22 UTC
         RTC time: Sat 2017-10-07 02:55:22
        Time zone: Asia/Shanghai (CST, +0800)
      NTP enabled: no
NTP synchronized: yes
  RTC in local TZ: no
       DST active: n/a

注意NTP synchronized值,只有时间服务器自己同步完成时间之后,才能为其它服务器提供时间同步服务。

2.设置日期与时间

timedatectl set-time "YYYY-MM-DD HH:MM:SS"
timedatectl set-time "YYYY-MM-DD"
timedatectl set-time "HH:MM:SS"

3.查看所有可用的时区

timedatectl list-timezones
# 亚洲
timedatectl list-timezones |  grep  -E "Asia/S.*"

4.设置时区

timedatectl set-timezone Asia/Shanghai

5.设置硬件时间

# 硬件时间默认为UTC
timedatectl set-local-rtc 1
# hwclock --systohc --localtime
# 两条命令效果等同

6.启用NTP时间同步
timedatectl set-ntp yes
# yes或no; 1或0也可以

问题:不明白这里启用ntp时间同步有啥意义。难道是说可以在时间服务器上都安装chronyd和ntpd服务来同时提供时间服务吗????如果设置为yes,手动设置时间则报错。看本文结尾。

7、查看时间源信息

[root@rhel1 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample              
===============================================================================
^* rhel1.rusky.com              10   7   377   22m  -3603ns[  -19us] +/-   32us
[root@rhel1 ~]# chronyc sources -v
210 Number of sources = 1

.-- Source mode  '^' = server, '=' = peer, '#' = local clock.
  / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample              
===============================================================================
^* rhel1.rusky.com              10   7   377   22m  -3603ns[  -19us] +/-   32us
[root@rhel1 ~]#


客户端时间同步配置:

1.yum install chrony –y

2.修改配置文件

[root@rhel2 ~]# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org iburst  --注释这4行
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst    ---添加该行,表示到这台服务器去同步时间。

3.重启chronyd并设置开机启动

[root@rhel2 ~]# systemctl restart chronyd.service
[root@rhel2 ~]# systemctl enable chronyd.service

4. 查看时间同步状态

[root@rhel2 ~]# timedatectl
       Local time: Sat 2017-10-07 11:15:43 CST
   Universal time: Sat 2017-10-07 03:15:43 UTC
         RTC time: Sat 2017-10-07 03:02:26
        Time zone: Asia/Shanghai (CST, +0800)
      NTP enabled: no
NTP synchronized: yes   --为yes表示已同步
  RTC in local TZ: no
       DST active: n/a

重启chronyd服务后,需要过几分钟才会自动完成同步。

如果需要手动,可使用下面的命令:

#ntpdate 192.168.100.1   如果同步失败,则可能 是服务端的时间未同步。即服务端NTP synchronized 为no。

============================

手动修改时间时,必须把NTP enabled 设置为no.

[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017
[root@rhel1 ~]# timedatectl
       Local time: Sat 2017-10-07 11:31:45 CST
   Universal time: Sat 2017-10-07 03:31:45 UTC
         RTC time: Sun 2017-10-08 03:01:57
        Time zone: Asia/Shanghai (CST, +0800)
      NTP enabled: no
NTP synchronized: no
  RTC in local TZ: no
       DST active: n/a

如果把NTP enabled 修改为yes时,表示开启自动同步时间,此时,是不能手动修改时间的。

如果为No时,表示关闭自动同步时间。

[root@rhel1 ~]# timedatectl set-ntp yes
[root@rhel1 ~]# timedatectl set-time "2017-10-08 11:00:50"
Failed to set time: Automatic time synchronization is enabled
[root@rhel1 ~]# timedatectl set-ntp no
[root@rhel1 ~]# timedatectl set-time "2017-10-08 11:00:50"
[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017

chrony 时间同步的更多相关文章

  1. chrony时间同步 服务端 客户端 安装配置

    chrony时间同步 服务端 客户端 安装配置 原创内容http://www.cnblogs.com/elvi/p/7658021.html #!/bin/sh #运行环境 centos7 #chro ...

  2. CentOS7.4 chrony时间同步服务器部署(替代NTPD)

    Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确. 它由两个程序组成:chronyd和chronyc. chronyd是一个后台运行的守护进程,用于调整内核 ...

  3. Linux基础学习-chrony时间同步服务

    Chrony时间同步 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.它的用于是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可 ...

  4. Linux 时间同步 05 chrony时间同步

    Linux 时间同步 05 chrony时间同步 目录 Linux 时间同步 05 chrony时间同步 chrony 的优势: chrony包介绍 安装chrony 配置与外部时间服务器进行时间同步 ...

  5. linux服务之NTP及chrony时间同步

    博客园 首页 联系 管理   linux服务之NTP及chrony时间同步   一.NTP时间同步 NTP(Network Time Protocol,网络时间协议)是由RFC 1305定义的时间同步 ...

  6. Chrony时间同步服务

    概:  网络时间协议(Network Time Protocol,NTP)是用于网络时间同步的协议.提供NTP时间同步服务的软件有很多,这里采用Chrony软件来实现时间同步 chrony 的优势:  ...

  7. chrony 时间同步服务器

    这篇文章也不错: https://www.zfl9.com/chrony.html 简介 chrony是网络时间协议(NTP)的多用途实现.它可以使系统时钟与NTP服务器.参考时钟(例如GPS接收器) ...

  8. centos 8.x系统配置chrony时间同步服务

    redhat/centos 7.x默认使用的时间同步服务为ntp服务,但是从redhat/centos 8开始在官方的仓库中移除了ntp软件,换成默认的chrony进行时间同步的服务,虽然也可以通过添 ...

  9. Chrony时间同步

    chrony 服务器 yum -y install chrony cp /etc/chrony.conf{,.bak} #备份默认配置 cat > /etc/chrony.conf <&l ...

随机推荐

  1. [转]thinkphp在iis下的rewrite伪静态的配置方法

    From : http://code-tech.diandian.com/post/2012-11-12/40042151797 首先你要安装IIS下的rewrite组建,下载地址:Rewrite.z ...

  2. Unicode和UTF-8之间的关系

    作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才算初步 ...

  3. maven清理.lastUpdated文件maven清理下载失败的jar,方便重新下载

    因网络或其他的原因,maven下载jar等文件失败后,会在目录中存在  *.jar.lastUpdated ,如:xmlpull-1.1.3.1.jar.lastUpdated,此时,代码编译时会一直 ...

  4. 【BZOJ】【3931】【CQOI2015】网络吞吐量

    最短路+最大流 思维难度并不高,其实题面几乎已经把算法讲完了…… 练习模板的好题= = 哦对了,求最短路和最大流的时候都得开long long……QwQ /********************** ...

  5. Maven 默认插件以及功能

    Maven 默认插件 已知 Maven 使用 plugin 来执行实际操作的,在默认情况下,Maven 会绑定以下几个插件来完成基本操作. plugin function life cycle pha ...

  6. postgresql共享内存的三个结构体

    本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/16105797 postgresql的共享内存维护主要 ...

  7. 分布式高并发物联网(车联网-JT808协议)平台架构方案

    技术支持QQ:78772895 1.车载终端网关采用mina/netty+spring架构,独立于其他应用,主要负责维护接入终端的tcp链接.上行以及下行消息的解码.编码.流量控制,黑白名单等安全控制 ...

  8. 命令行修改mysql密码和远程访问

    http://jingyan.baidu.com/article/a3a3f8118cea488da2eb8a0a.html

  9. GIT 如何从另一分支合并特定的文件

    是否遇到过这种情景: 您在一个分支上工作,发现该分支上的某些文件实现的功能已经在其他分支上实现了 但因为这两个分支实现不同的功能,因此不能进行简单的合并工作,但您又不想重复其他已经完成的工作 以下操作 ...

  10. Python防止sql注入

    看了网上文章,说的都挺好的,给cursor.execute传递格式串和参数,就能防止注入,但是我写了代码,却死活跑不通,怀疑自己用了一个假的python 最后,发现原因可能是不同的数据库,对于字符串的 ...