各個節(jié)點實現(xiàn)時間同步
有三臺虛擬機, tt-hadoop1為主, tt-hadoop2 和 tt-hadoop3 為從
要實現(xiàn)從節(jié)點的date永遠和主節(jié)點的date保持一致
1> 在tt-hadoop1檢查ntp包是否安裝
命令:?rpm -qa|grep ntpd
如圖所示,說明有ntp包
2> 修改配置文件
在 /etc/目錄下找到ntp.conf
a.? 在ntp.conf中添加以下內(nèi)容
restrict 192.168.11.0 mask 255.255.255.0 nomodify notrap
b.? 注釋以下四行內(nèi)容
#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.? 去掉以下注釋(如果沒有,直接手動添加)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
3> 啟動ntp
命令: service ntpd start
查看ntp狀態(tài)
命令(三個都可): service ntpd status
? ? ? ? ? ? ? ? ? ? ? ? ? ?ntpstat
? ? ? ? ? ? ? ? ? ? ? ? ? ?ntpq -p
設置ntp為開機自啟
命令:?chkconfig ntpd on
4> 查看ntp的啟動路徑? 命令:which ntpdate
在從機上執(zhí)行?ntpdate tt-hadoop1,就實現(xiàn)了時間的同步,但為了方便,而不是每次開啟虛擬機都執(zhí)行這個語句才能同步,所以寫一個腳本
命令: crontab -e? ?(-e為編輯,-l為查看)
寫入以下內(nèi)容,如圖所示
0-59/1 * * * * /usr/sbin/ntpdate tt-hadoop1
也可以設置BIOS與系統(tǒng)時間同步
a> 查看
b>?編輯 在[OPTIONS]前添加以下內(nèi)容
vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
c> 測試
ntpstat
sudo ntpq -p