集群时间同步

     同步方式

  • 机器可以访问网络,这种定时同步网络时间
  • 从节点同步主节点的时间,其他机器不连接网络,只从主节点同步

     检查时区

date -R

     如果不是+8,需要先设置机器的时区

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

     查看ntp服务是否安装

rpm -qa|grep ntp

    安装ntp服务命令

yum –y install ntp

     主节点修改

vi /etc/ntp.conf

      

#授权 192.168.184.2-192.168.184.255 网段上的所有机器可以从这台机器上查询和同步时间
 
restrict 192.168.184.2 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

     所有节点修改

vi /etc/sysconfig/ntpd
#让硬件时间与系统时间一起同步
SYNC_HWCLOCK=yes

     或者使用命令同步

hwclock -w

     修改后重启ntp服务

service ntpd stop
service ntpd start

     从节点设置定时任务定时同步主节点

service ntpd stop

  设置定时任务定时从主节点同步时间

crontab -e

      每隔一小时同步一次主节点

0 0 */1 * * ? /usr/sbin/ntpdate hadoop1  #hadoop1是主机名

      

 

    

posted on 2024-12-11 21:47  溪水静幽  阅读(24)  评论(0)    收藏  举报