• CentOS7.9搭建NTP服务器


    一、操作环境

    [root@localhost ~]# screenfetch
    
    • 1

    在这里插入图片描述

    二、详情&rpm包

    1.问题
      最近出差配置zabbix监控时候遇到了时间不同步的问题,环境是A类可以访问互联网和内网,B类只能访问内网,故此写了这篇文章共享给大家希望能给遇到同样问题的道友一些帮助。当然如果有更好的方法欢迎评论留言。
    2.解决方法

    名称ip角色功能
    服务器A192.168.1.9局域网NTP服务器、互联网时间同步
    服务器B192.168.0.172需要时间同步的内网服务器

    关系说明:
    1)A通过ntpdate+crontab实时同步互联网时间,自身做内网B的ntp服务器。
    2)B通过ntpdate实时同步A系统时间。

    3.rpm包
    npt-rpm包【提取码r7q1】

    三、部署

    A服务器操作:

    1.服务器A安装ntp、ntpdate服务

    yum -y install ntp ntpdate
    
    • 1

    2.配置服务器A的ntp.conf配置文件

    [root@localhost ~]# vim /etc/ntp.conf
    driftfile /var/lib/ntp/drift
    restrict default nomodify notrap nopeer noquery
    
    
    restrict 192.168.1.9	#A服务器ip
    restrict ::1
    restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap #需要从A服务器同步时间的客户机网段
    
    
    server 127.127.1.0
    fudge 127.127.1.0 stratum 10
    
    includefile /etc/ntp/crypto/pw
    keys /etc/ntp/keys
    
    logfile /var/log/ntpstats/ntpd.log
    disable monitor
    
    :wq #保存并退出
    
    [root@localhost ~]# systemctl enable --now ntpd  #设置开机自启
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    3.服务器A手动同步一次互联网时间

    [root@localhost ~]# ntpdate -u ntp1.aliyun.com 
    22 Aug 05:39:56 ntpdate[738]: step time server 120.25.115.20 offset 16.260223 sec
    
    • 1
    • 2

    在这里插入图片描述
    4.服务器A写入计划任务每十分钟同步一次互联网时间

    [root@localhost ~]# echo "*/10 * * * * /usr/sbin/ntpdate -u ntp1.aliyun.com > /dev/null 2>&1" >> /var/spool/cron/root
    [root@localhost ~]# crontab -l #查看是否成功
    
    • 1
    • 2

    在这里插入图片描述

    B服务器操作:

    1.服务器B安装ntpdate服务

     yum -y install  ntpdate
    
    • 1

    2.服务器B手动同步一次服务器A的时间

    ntpdate 192.168.1.9
    
    • 1

    在这里插入图片描述
    3.服务器B写入计划任务每十分钟同步一次服务器A的时间

    [root@host-192-168-0-172 ~]# echo "*/10 * * * * /usr/sbin/ntpdate 192.168.1.9 > /dev/null 2>&1" >> /var/spool/cron/root
    [root@host-192-168-0-172 ~]# crontab -l #查看是否成功
    
    • 1
    • 2

    在这里插入图片描述

    四、结束语

      到此ntp时间同步问题就已经解决了,B类服务器不限制数量同理以此可以实现内网间接性同步互联网世界解决zabbix agent与server之间的时间差>60s问题,感谢大家的支持与关注!

  • 相关阅读:
    MyBatis-Plus
    Vue3 readonly 和 shallowReadonly
    一文读懂机智云物联网APP开发
    css-文本单行、多行溢出省略
    动态规划题: 统计每个月兔子的总数
    南大通用数据库-Gbase-8a-学习-21-Oracle到Gbase8a迁移工具orato8a
    博士论文——相似度
    谷粒学院16万字笔记+1600张配图(四)——前端技术
    订单正逆向流程
    rsync远程同步
  • 原文地址:https://blog.csdn.net/qq_43417559/article/details/126431023