Hadoop集群搭建中时间同步步骤

    一、设置主节点时间服务器的时区

    二、在每一个节点上检查是否安装时间服务ntp

    三、在主节点上配置时间同步的相关文件

    四、在其他从节点上配置与主节点时间同步的脚本

一、设置主节点时间服务器的时区

1、选择时区(就选到beijing就行)

[root@node001 ~]# tzselect

2、把时区,将cp /usr/share/zoneinfo/Asia/Shanghai设置为到/etc/localtime的链接

[root@node001 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 二、在每一个节点上检查是否安装时间服务ntp

[root@node001 ~]# rpm -q ntp
ntp-4.2.6p5-15.el6.centos.x86_64

如果没有显示安装,用yum安装
[root@node001 ~]# yum install -y ntp
设置ntpd 开机开启
[root@node001 ~]# chkconfig ntpd on        
查看打开状态             
[root@node001 ~]# chkconfig --list ntpd
ntpd            0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭     
三、在主节点上配置时间同步的相关文件
[root@node001 ~]# vi /etc/ntp.conf   或者   [root@node001 ~]# vim /etc/ntp.conf
下面加中文的为修改的地方!!!
 
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
restrict 192.168.181.0 mask 255.255.255.0 nomodify notrap        #这里新增内容,更改为自己的网关,我的是181.第一处新增,意思是从IP                                                                                                                                        #地址192.168.181.1-192.168.181.254,默认网关255.255.255.0的服务器                                                                                                                                                                      #都可以使用我们的NTP服务器来同步时间

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst                 #如果集群是在一个封闭的局域网内,可以屏蔽掉默认的server这里注释掉
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 210.72.145.44 perfer          #中国国家受时中心
server 202.112.10.36                 #1.cn.pool.ntp.org
server 59.124.196.83                          #这里可有可无,制定ntp服务器的同步时间范围        
server 192.168.217.130

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
server 127.127.1.0                                    #当服务器与公网失去连接后使用本地时间作为服务的同步时间          
fudge 127.127.1.0 stratum 10
 
重新启动服务
[root@node001 ~]# service ntpd restart
关闭 ntpd:                                                [确定]
正在启动 ntpd:                                            [确定]
 
可设置crontab每天和NTP服务器同步一次
[root@node001 ~]#crontab -e
10 23 * * * root (/usr/sbin/ntpdate cn.pool.ntp.org && /sbin/hwclock -w) &> /var/log/ntpdate.log
四、在其他从节点上配置与主节点时间同步的脚本
在其他节点配置  10 分钟与时间服务器同步一次

[root@node002 ~]# crontab -e

* */1 * * * /usr/sbin/ntpdate node001

检查是否写成

[root@node002 ~]# crontab -l
* */1 * * * /usr/sbin/ntpdate node001

同样的步骤在其他节点重复

更改一个节点的时间

[root@node002 ~]# date -s "2019-4-29 00:00:00"

十分钟后查看时间检查是否同步

[root@node002 ~]# date

如果现在立即要同步,可以手动同步

[root@node002 ~]#ntpdate node001

猜你喜欢

转载自www.cnblogs.com/blog-of-zxf/p/10793440.html