- 在搭建hadoop集群的時候,往往由於集群中機器的時間不一致造成一些錯誤,比如System times on machines may be out of sync. Check system time and time zones.
- 我們需要解決的就是配置一個ntp來同步時間
- 時間同步的方式:找一個機器,作為時間服務器,所有的機器與這台集群時間進行定時的同步,比如每隔十分鍾同步一次等等
- 時間服務器配置(必須root用戶):
- 檢查ntp服務是否安裝
[root@hadoop102 桌面]# 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 桌面]# vi /etc/ntp.conf 修改內容如下 a) 修改 1 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 為 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 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 為 #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 c) 添加 3 server 127.127.1.0 fudge 127.127.1.0 stratum 10
- 修改/etc/sysconfig/ntpd 文件
[root@hadoop102 桌面]# vim /etc/sysconfig/ntpd 增加內容如下 SYNC_HWCLOCK=yes
- 重啟ntpd服務
[root@hadoop102 桌面]# service ntpd status ntpd 已停 [root@hadoop102 桌面]# service ntpd start 正在啟動 ntpd: [確定] 執行: [root@hadoop102 桌面]# chkconfig ntpd on
- 其他機器配置(必須 root 用戶) :
- 在其他機器配置 10 分鍾與時間服務器同步一次
[root@hadoop103 hadoop-2.7.2]# crontab -e 編寫腳本 */10 * * * * /usr/sbin/ntpdate hadoop102
- 修改任意機器時間
[root@hadoop103 hadoop]# date -s "2017-9-11 11:11:11"
- 十分鍾后查看機器是否與時間服務器同步
[root@hadoop103 hadoop]# date
- 在其他機器配置 10 分鍾與時間服務器同步一次
- 檢查ntp服務是否安裝