zoukankan      html  css  js  c++  java
  • chrony实现局域网时间同步

    chrony基于cs架构实现,配置一台服务主机与其他客户主机即可

    服务端

    timedatectl set-timezone Asia/Shanghai   --时区修改为shanghai
    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    --添加这一行,表示与本机同步时间

      #server cn.pool.ntp.org iburst  --国内也常用这俩时间同步服务器
      #server tw.pool.ntp.org iburst

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

    客户端

    #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    ---添加该行,表示到这台服务器去同步时间。

    重启chrony服务,并开机自启

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

    常用命令

    cat /etc/chrony.conf | grep -v ^# | grep -v ^$ 查看配置文件(去掉注释行和空行)
    

      

    查看时间同步源:
    $ chronyc sources -v
    查看时间同步源状态:
    $ chronyc sourcestats -v
    校准时间服务器:
    $ chronyc tracking
    

      

     

    其他

    查看时间同步

    [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

    手动修改时间时,必须把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
  • 相关阅读:
    Logistic Regression
    如何把日期格式化为指定格式?
    JavaScript的自调用函数
    elementui 在原生方法参数里,添加参数
    原生js实现随着滚动条滚动,导航会自动切换的效果
    微信小程序-canvas绘制文字实现自动换行
    visual studio 和 sql server 的激活密钥序列号
    跨多个服务器访问不同数据库的表的方法
    数据库面试中常问的几个问题
    聚集索引和非聚集索引的区别
  • 原文地址:https://www.cnblogs.com/soymilk2019/p/10821284.html
Copyright © 2011-2022 走看看