zoukankan      html  css  js  c++  java
  • linux(CentOS7) 之 ntp时间同步配置步骤

    下 载

    百度搜索 ntp rpm 下载(或直接进入官网https://pkgs.org/download/ntp)

     

    搜多ntp,选择centos7 64位下载,ntpdata 是依赖包也要下载

     

     

    基 础 环 境

    三台centos7最小化安装

    ip                       hostname

    192.168.100.10 bigdata01

    192.168.100.11 bigdata02

    192.168.100.12 bigdata03

    以192.168.100.10 bigdata01 为时间服务器,另外两台同步此时间。

     

    安 装 ntp

    sudo rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm

    报错,依赖包未安装

    libopts.so.25()(64bit)

    ntpdate-4.2.6p5-29.el7.centos.2

     

    安装依赖包(ntp 客户端)

    sudo rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm

     

    sudo rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpm

     

    再安装ntp(ntp服务器)

    sudo rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm

     

    配置ntp(只配置时间服务器,其他只需安装,不用配置)

    启用restrice,修改网段

    vi /etc/ntp.cnf
    # 启用restrice限制,网段改为集群的网段(本例是100)
    
    restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
    
    #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
    
    server 127.127.1.0 #本机作为时间服务器
    fudge 127.127.1.0 stratum 10

    修改配置文件ntpd

    sudo vi /etc/sysconfig/ntpd

    添加SYNC_CLOCK=yes

    启动时间服务器的ntp服务(客户机不要启动ntp服务,只需启动服务器ntp服务!

    sudo systemctl start ntpd

     查看ntp服务状态

    sudo systemctl status ntpd

    设置开机启动ntp服务

    sudo systemctl enable ntpd

    配置其他机器的同步

    切换到root用户进行配置,通过contab进行定时同步,每10分同步一次。

    192.168.100.11 上执行

    crontab -e

    */10 * * * * /usr/sbin/ntpdate 192.168.100.10

     

    192.168.100.12 上执行

    crontab -e

    */10 * * * * /usr/sbin/ntpdate 192.168.100.10

     

    测 试

    查看目前三台机器的时间

     

    192.168.100.10

    date "+%Y-%m-%d %H:%M:%S"

    2021-04-04 23:19:38

     

    192.168.100.11

    date "+%Y-%m-%d %H:%M:%S"

    2021-04-04 23:19:38

     

    192.168.100.12

    date "+%Y-%m-%d %H:%M:%S"

    2021-04-04 23:19:38

     

    修改192.168.100.11上的时间

     

    将时间改为一个以前的时间:

    sudo date -s '2021-01-01 23:19:38'

    2021年 01月 01日 星期五 23:19:38 CST

     

    date "+%Y-%m-%d %H:%M:%S"

    2021-01-01 23:19:45

     

    10分钟后,看是否实现了自动同步,将192.168.100.11上的时间修改为和192.168.100.10上的一致。

     

    查看是否自动同步时间

    date "+%Y-%m-%d %H:%M:%S"

    2021-04-04 23:32:38

     

    同步成功。

    世风之狡诈多端,到底忠厚人颠扑不破; 末俗以繁华相尚,终觉冷淡处趣味弥长。
  • 相关阅读:
    [ios] 分辨率
    [bat] 图片裁剪工具ImageMagick
    [ASP.NET] 调用32位ORACLE错误
    [Linux] 开启ESX的SSH
    [Linux] 关机和重启命令
    [.net] 关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files… ‘Access is denied.’ 的解决办法
    [linux] XEN里面的虚拟机centos无法使用date s设置时间
    字符串替换,string的强大
    C语言学习笔记(1)
    C语言学习笔记(8)
  • 原文地址:https://www.cnblogs.com/simple-li/p/14617652.html
Copyright © 2011-2022 走看看