zoukankan      html  css  js  c++  java
  • 【NTP服务】时间同步服务NTP

    NTP服务介绍

      网络传输中,数据包和日志都需要准确的时间戳。在Linux系统中 Network Time Protocol,NTP协议有用户在空间中的守护进程实现,即ntp和chrony。(要能访问互联网)

    同步系统时间

    • 修改配置文件制定ntp服务器同步
    # 查看是否安装
    [root@rhel8 tanbaobao]# yum list | grep chrony
    chrony.x86_64                                        3.5-1.el8
    
    # 查看chrony的配置文件
    [root@rhel8 tanbaobao]# rpm -qc  chrony
    /etc/chrony.conf
    /etc/chrony.keys
    /etc/logrotate.d/chrony
    /etc/sysconfig/chronyd
    
    # 添加时间池(http://www.ntp.org.cn/pool.php)
    [root@rhel8 tanbaobao]# vi /etc/chrony.conf 
    将原来的时间池注释,添加时间池
    # pool 2.rhel.pool.ntp.org iburst
    pool cn.ntp.org.cn iburst
    
    # 重启服务
    [root@rhel8 tanbaobao]# systemctl restart chronyd.service
    # 指定时间服务器(配置文件中加入如下)
    [root@rhel8 tanbaobao]# vi /etc/chrony.conf 
    server 203.107.6.88 iburst
    • 临时制定ntp服务器同步
    # 需先停掉chronyd服务
    [root@rhel8 tanbaobao]# systemctl stop chronyd
    
    # 临时修改
    [root@rhel8 tanbaobao]# chronyd -q "server cn.ntp.org.cn iburst"
    2020-06-05T11:34:07Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCD
    NS +SECHASH +IPV6 +DEBUG)2020-06-05T11:34:07Z Initial frequency 4.723 ppm
    2020-06-05T11:34:11Z System clock wrong by 0.000601 seconds (step)
    2020-06-05T11:34:11Z chronyd exiting

    搭建时间同步服务RHEL8

    • 关闭防火墙和selinux
    • 配置软件仓库
    • 软件三部曲:
      •   安装软件
      •   确认软件是否安装成功
      •   查看软件的文件列表(配置文件,程序本身,慢手册)
    • 连接配置文件(man 5 xxx.conf)
    • 根据需求修改配置文件完成服务搭建
    • 启动服务,设置开机自启
    • 测试验证

    时间同步服务器端

      这里我是用的自己腾讯云服务器作为服务端。

    # 关防火墙,selinux,安装chrony
    # 设置允许别人访问该服务端
    [root@tanbaobao ~]# vi /etc/chrony.conf 
    在26行下面添加访问ip
    allow 192.168.187.0/24    # 这里是客户端的ip
    
    # 重启服务
    [root@tanbaobao ~]# systemctl restart chronyd.service 
    [root@tanbaobao ~]# systemctl status chronyd.service 
    
    # 查看NTP端口123
    [root@tanbaobao ~]# netstat -nlup | grep :123
    udp        0      0 0.0.0.0:123             0.0.0.0:*                           26521/chronyd 
        

    客户端

    #关防火墙 ,selinux,安装软件
    # 配置从哪里同步时间,这里从服务端ip处获取
    [root@rhel8 tanbaobao]# 
    [root@rhel8 tanbaobao]# vim /etc/chrony.conf 
    server 服务端ip地址 iburst
    
    # 重启服务
    [root@rhel8 tanbaobao]# systemctl restart chronyd.service
    [root@rhel8 tanbaobao]# systemctl status chronyd.service
    
    # 手动同步
    [root@rhel8 tanbaobao]# chronyc sources
    [root@rhel8 tanbaobao]# chronyc makestep
    200 OK
  • 相关阅读:
    代码品质
    窖藏好题
    最后一次模拟
    几个有意思的题目
    【数组练习】
    【复习】图论
    【复习】后缀数组
    The Usage Of Difference Table
    【复习】NTT注意事项
    CF999E Reachability from the Capital
  • 原文地址:https://www.cnblogs.com/HeiDi-BoKe/p/13051688.html
Copyright © 2011-2022 走看看