当前位置: 首页 > news >正文

Linux Centos7 服务器局域网集群使用 NTP 同步时间

  1. 服务器环境:Centos7

    IP域名
    192.168.1.101node1
    192.168.1.102node2
    192.168.1.103node3
  2. 下载 ntp 依赖包

    包名驱动网站下载百度云下载
    autogen-liboptsautogen-libopts-5.18-5.el7.x86_64.rpm提取码:1234 autogen-libopts-5.18-5.el7.x86_64.rpm
    ntpdatentpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm提取码:1234 ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
    ntpntp-4.2.6p5-29.el7.centos.2.x86_64.rpm提取码:1234 ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
  3. 安装RPM包
    在101、102、103 每台服务器安装ntp相关依赖包

    rpm -i autogen-libopts-5.18-5.el7.x86_64.rpm
    rpm -i ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
    rpm -i ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
    
  4. 启动ntp服务
    在101、102、103 每台服务器 启动ntp

    # 启动 ntp 服务
    systemctl start  ntpd
    # ntp 开机自启
    systemctl enable  ntpd# ntp 服务状态
    systemctl status ntpd
    
  5. 配置时钟服务器(192.168.1.101)
    编辑 /etc/ntp.conf 文件

    vim /etc/ntp.conf
    

    修改以下内容

    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    # 这里局域网使用回环地址作为时钟源,如果可以连接互联网可以添加外部时钟源
    server 127.127.1.0 # local clock
    # 填入回环地址,设置时间服务器的层级 stratum 0~15  ,0:表示顶级 , 10:通常用于给局域网主机提供时间服务
    fudge 127.127.1.0 stratum 10# 注释以下内容
    #server 0.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    

    重启 ntp 服务

    systemctl restart ntpd
    
  6. 配置时钟客户端(192.168.1.102、192.168.1.103)
    编辑 /etc/ntp.conf 文件

    vim /etc/ntp.conf
    

    修改以下内容

    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# 首选192.168.1.101 作为时钟源
    server 192.168.1.101 prefer 
    # 时钟源地址    
    fudge 192.168.1.101 stratum 10# 注释以下内容
    #server 0.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    

    重启 ntp 服务

    systemctl restart ntpd
    
  7. 查看NTP同步情况

    ntpstat 命令

    [root@localhost ~]# ntpstat
    synchronised to NTP server (192.168.1.101) at stratum 12time correct to within 69 mspolling server every 1024 s
    

    ntpq -p 检查

    [root@localhost ~]# ntpq -p remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    192.168.1.101   LOCAL(0)        11 u   28   64    1    0.147  -72137.   0.000
    

    此处看到与源时钟时间差较大(offset ),建议等待5-10分钟查看

    [root@localhost ~]# ntpq -p remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    192.168.1.101   LOCAL(0)        11 u   54   64  377    0.125   -0.022   0.098
    

    可以看到时间已同步相差无几。

相关文章:

  • 一体式以电折水智能终端:化繁为简,智能八合一
  • c++保存结构体数据为二进制文件与读取
  • 实现的一个网页版的简易表白墙
  • Live800:企业客户服务,如何确保服务质量和响应标准的严格执行
  • 如何选择合适的IP代理,如何为网络爬虫设置代理
  • 前后端交互理解 简易表白墙(servlet)
  • Spring Cloud项目整合Sentinel及简单使用
  • 如何写一个react自定义的hooks?
  • 蓝桥杯 填空 卡片
  • 力扣刷题日记——L238.除自身以外数组的乘积
  • 德人合科技|办公电脑文件资料防泄密软件
  • 后渗透--利用ebpf隐藏后门用户
  • 构建Vue2/Vue3项目的两种方式
  • Flutter第三弹:常用的Widget
  • RUST 每日一省:rust logo收集
  • 《Java编程思想》读书笔记-对象导论
  • Android 控件背景颜色处理
  • ES10 特性的完整指南
  • fetch 从初识到应用
  • Github访问慢解决办法
  • LeetCode算法系列_0891_子序列宽度之和
  • vue.js框架原理浅析
  • 编写符合Python风格的对象
  • 爬虫模拟登陆 SegmentFault
  • 小程序01:wepy框架整合iview webapp UI
  • 学习使用ExpressJS 4.0中的新Router
  • Java数据解析之JSON
  • Java总结 - String - 这篇请使劲喷我
  • 大数据全解:定义、价值及挑战
  • 回归生活:清理微信公众号
  • 移动端高清、多屏适配方案
  • 整理一些计算机基础知识!
  • !!Dom4j 学习笔记
  • $var=htmlencode(“‘);alert(‘2“); 的个人理解
  • (5)STL算法之复制
  • (翻译)Quartz官方教程——第一课:Quartz入门
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (附源码)计算机毕业设计SSM教师教学质量评价系统
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (译)2019年前端性能优化清单 — 下篇
  • .NET C# 使用 SetWindowsHookEx 监听鼠标或键盘消息以及此方法的坑
  • .net 提取注释生成API文档 帮助文档
  • .Net的DataSet直接与SQL2005交互
  • .net分布式压力测试工具(Beetle.DT)
  • .NET设计模式(7):创建型模式专题总结(Creational Pattern)
  • :“Failed to access IIS metabase”解决方法
  • @Autowired和@Resource装配
  • @ResponseBody
  • @serverendpoint注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • @WebService和@WebMethod注解的用法
  • [ 常用工具篇 ] AntSword 蚁剑安装及使用详解
  • [2008][note]腔内级联拉曼发射的,二极管泵浦多频调Q laser——
  • [BUG]vscode插件live server无法自动打开浏览器
  • [C#]OpenCvSharp使用帧差法或者三帧差法检测移动物体