美文网首页每日一篇大数据
配置集群时间同步

配置集群时间同步

作者: sixleaves | 来源:发表于2018-10-29 10:26 被阅读16次

    配置集群时间同步:

    1.时间服务器配置(必须root用户)

    • 检查ntp是否安装
    [root@hadoop102 桌面]# rpm -qa|grep ntp
    ntp-4.2.6p5-10.el6.centos.x86_64
    fontpackages-filesystem-1.41-1.1.el6.noarch
    ntpdate-4.2.6p5-10.el6.centos.x86_64
    

    2.修改ntp配置文件

    [root@hadoop102 桌面]# vim /etc/ntp.conf
    修改内容如下

    • 授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间
    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为
    restrict 192.168.176.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 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
    

    3.修改/etc/sysconfig/ntpd 文件

    • 编辑/etc/sysconfig/ntpd
      [root@hadoop102 桌面]# vim /etc/sysconfig/ntpd
    • 增加内容如下(让硬件时间与系统时间一起同步)
      SYNC_HWCLOCK=yes
    • 重新启动ntpd服务
      [root@hadoop102 桌面]# service ntpd status
      ntpd 已停
      [root@hadoop102 桌面]# service ntpd start
      正在启动 ntpd:[确定]
    • 设置ntpd服务开机启动
      [root@hadoop102 桌面]# chkconfig ntpd on

    4.其他机器配置(必须root用户)

    • 在其他机器配置10分钟与时间服务器同步一次
      [root@hadoop103桌面]# crontab -e
      编写定时任务如下:
      */10 * * * * /usr/sbin/ntpdate hadoop102
    • 修改任意机器时间
      [root@hadoop103桌面]# date -s "2018-10-28 14:53:11"
    • 十分钟后查看机器是否与时间服务器同步
      [root@hadoop103桌面]# date
      说明:测试的时候可以将10分钟调整为1分钟,节省时间

    相关文章

      网友评论

        本文标题:配置集群时间同步

        本文链接:https://www.haomeiwen.com/subject/aoavtqtx.html