Hadoop 集群时间同步
文章目录
- 时间服务器配置
- 检查 ntp 是否安装
- 修改 ntp 配置文件
- 修改/etc/sysconfig/ntpd 文件
- 重新启动 ntpd
- 其他机器配置
- 测试
- 同步网络时间
时间同步的方式:
找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时 的同步,比如,每隔十分钟,同步一次时间。
时间服务器配置
必须 root 用户!!!
检查 ntp 是否安装
[root@hadoop102 hadoop]# 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
修改 ntp 配置文件
[root@hadoop102 hadoop]# vim /etc/ntp.conf
# Hosts on local network are less restricted.
# 允许192.168.0.0/254子网内主机时间同步
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
# 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 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 # 指定阶层编号为10,降低其优先度
修改/etc/sysconfig/ntpd 文件
[root@hadoop102 hadoop]# vim /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
# 增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
重新启动 ntpd
# 查看ntpd状态
[root@hadoop102 hadoop]# service ntpd status
ntpd 已死,但 pid 文件仍存
[root@hadoop102 hadoop]# service ntpd start
正在启动 ntpd: [确定]
[root@hadoop102 hadoop]# service ntpd status
ntpd (pid 3506) 正在运行...
# 设置开机启动
[root@hadoop102 hadoop]# chkconfig ntpd on
其他机器配置
必须 root 用户!!!
[root@hadoop103 hadoop]# crontab -e
* * * * * /usr/sbin/ntpdate hadoop102
#hadoop104同上
测试
[root@hadoop103 hadoop]# date
2019年 03月 31日 星期日 00:50:23 CST
[root@hadoop103 hadoop]# date -s "2017-9-11 11:11:11"
2017年 09月 11日 星期一 11:11:11 CST
[root@hadoop103 hadoop]# date
2017年 09月 11日 星期一 11:11:12 CST
[root@hadoop103 hadoop]# date
2017年 09月 11日 星期一 11:11:42 CST
[root@hadoop103 hadoop]# date
2019年 03月 31日 星期日 00:51:18 CST
[root@hadoop103 hadoop]#
同步网络时间
[root@hadoop102 hadoop]# service ntpd stop
关闭 ntpd: [确定]
[root@hadoop102 hadoop]# /usr/sbin/ntpdate 0.cn.pool.ntp.org && /sbin/hwclock -w
31 Mar 12:59:23 ntpdate[3566]: step time server 78.46.102.180 offset 43393.687845 sec
[root@hadoop102 hadoop]# date
2019年 03月 31日 星期日 12:59:26 CST
[root@hadoop102 hadoop]# service ntpd start
正在启动 ntpd: [确定]
[root@hadoop102 hadoop]# chkconfig ntpd on
[root@hadoop102 hadoop]# date
2019年 03月 31日 星期日 13:00:09 CST
[root@hadoop102 hadoop]#
还没有评论,来说两句吧...