• 集群时间同步


    三、集群时间同步
    集群时间不同步,会有一系列的bug发生,为了避免这种情况的发生,就需要配置集群时间同步。

    时间同步方式如下:

    以vagrant1作为时间服务器,vagrant2和vagrant3与vagrant1的时间进行定时同步,设置一个时间进行同步,比如,每隔2分钟,同步一次。

    以下操作都要在root用户下面操作

    1.时间服务器配置(vagrant1)
    (1)在所有节点(vagrant1,vagrant2,vagrant3)查看是否安装ntp

    rpm -qa | grep ntp
    (2)如果没有安装,在所有节点(vagrant1,vagrant2,vagrant3)安装ntp

    yum install -y ntp
    (3)在所有节点(vagrant1,vagrant2,vagrant3)关闭ntp服务和自启动

    sudo systemctl stop ntpd
    sudo systemctl disable ntpd
    注意:下面的操作都是vagrant1这一台服务器上

    (4)修改ntp配置文件

    vim /etc/ntp.conf
    修改添加内容如下:

    修改1:授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间

    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    修改为(也就是去掉这一行前面的注释)
    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    修改2:集群在局域网中,不使用其他互联网上的时间

    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
    添加3:当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步

    server 127.127.1.0
    fudge 127.127.1.0 stratum 10
    (5)修改/etc/sysconfig/ntpd 文件

    vim /etc/sysconfig/ntpd
    添加内容如下:(为了让硬件时间与系统时间一起同步)

    SYNC_HWCLOCK=yes
    (6)重新启动ntpd服务

    systemctl start ntpd
    (7)设置ntpd服务开机启动

    systemctl enable ntpd
    2.其他机器配置(vagrant2,vagrant3)
    (1)在其他机器上配置2分钟与时间服务器同步一次

    crontab -e
    编写定时任务如下:

    */2 * * * * /usr/sbin/ntpdate vagrant1
    (2)修改任意机器时间

    date -s "2018-1-15 12:11:10"
    (3)2分钟后查看机器是否与时间服务器同步

    date
    ————————————————
    版权声明:本文为CSDN博主「肉松学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/weixin_52678046/article/details/112257790

  • 相关阅读:
    hadoop:WordCount问题总结
    .mata. _root_ (转)
    Hbase笔记:批量导入
    Hbase笔记4 java操作Hbase
    wget
    中国大陆开源镜像站汇总
    全键盘操作Windows
    linux下实用命令
    /dev/null和/dev/zero的区别
    Windows xp下安装sql server2005所碰到的一些问题及解决方法
  • 原文地址:https://www.cnblogs.com/tutuwowo/p/16061558.html
Copyright © 2020-2023  润新知