时间同步的方式:找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,比如,每隔十分钟,同步一次时间。
配置时间同步实操如下:
- 时间服务器配置(必须root用户)
(1)检查ntp是否安装
[root@hadoop001 桌面]# 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
(2)修改ntp配置文件
[root@hadoop001 桌面]# vi /etc/ntp.conf
修改内容如下
(3)修改/etc/sysconfig/ntpd 文件a)修改1(设置本地网络上的主机不受限制。)
#restrict 192.168.1.0 mask 255.255.255.0 nomodifynotrap为
restrict 192.168.1.0 mask 255.255.255.0 nomodifynotrap
b)修改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为
#server0.centos.pool.ntp.org iburst
#server1.centos.pool.ntp.org iburst
#server2.centos.pool.ntp.org iburst
#server3.centos.pool.ntp.org iburst
c)添加3(添加默认的一个内部时钟数据,使用它为局域网用户提供服务。)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
[root@hadoop001 桌面]#vim /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes(4)重新启动ntpd
[root@hadoop001 桌面]#service ntpd status
ntpd 已停
[root@hadoop001 桌面]#service ntpd start
正在启动 ntpd: [确定]
(5)执行:
[root@hadoop001桌面]# chkconfig ntpd on 其他机器配置(必须root用户)
(1)在其他机器配置10分钟与时间服务器同步一次
[root@hadoop002 hadoop-2.7.2]# crontab -e
编写脚本
*/10 * * * * /usr/sbin/ntpdate hadoop102
(2)修改任意机器时间
[root@hadoop002 hadoop]# date -s "2011-11-11 11:11:11"
(3)十分钟后查看机器是否与时间服务器同步
[root@hadoop002 hadoop]# date