Linux集群的NTP服务器时间同步

我们搭建集群环境的时候,时间必须是要统一的,才能保证集群数据的一致性。

一般操作是直接使用NTP,跟默认的时间服务器同步,但是最好还是让所有节点跟集群中的某台作为时间服务器的节点同步。

步骤:(节点有NameNode1,NameNode2,DataNode1,DataNode2,DataNode3)

  1. 选择一台服务器作为时间服务器。(DataNode1做为时间服务器)
  2. 使用root用户,查看服务器是否安装ntp服务 
    rpm -qa|grep ntp

     没有安装的话使用yum install进行安装。

  3.   修改文件 /etc/ntp.conf,一共修改三处内容:
  4.   ①将#去掉。并且将网段修改正确。
    restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
  5.  ②将以下4个server进行#注释掉
    #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
  6. ③最后添加俩句话:

    server 127.127.1.0 #local clock
    fudge  127.127.1.0 stratum 10
  7. 编辑etc/sysconfig/ntpd文件
    # Drop root to id 'ntp:ntp' by default.
    SYNC_HWCLOCK=yes
    OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
  8. 启动ntpd服务,并且设置开机启动

    systemctl start ntpd.service
    systemctl enable ntpd.service

     

  9. 每个需要同步的子节点进行确认有没有ntp。如果没有的话就安装下。
  10. root账户下在每个需要同步的子节点编写crontab任务(crontab -e)。这个任务的意义就是每10分钟和master01同步下服务器时间。
    0-59/10 * * * * /usr/sbin/ntpdate master01.timer.cn

 

附:

1.作为时间服务器的节点的时间校准可以是人工指定(不与其他集群协作的情况下),也可以是跟其他组织的时间服务器同步

这里只说第二种情况。首先要确认当前服务器的时区

将时区设为上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

然后通过定时任务,与阿里云的时间服务器 ntp1.aliyun.com 同步(方法同上面第10步,ntp1~ntp7)

 

2.不同操作系统之间也是可以做时间同步的。linux与windows之间同步是没问题的。


出处:https://www.cnblogs.com/TiestoRay/p/6045778.html#top

猜你喜欢

转载自blog.csdn.net/jackliu16/article/details/80327869