第十章:集羣時間同步
時間同步的方式:找一個機器,作爲時間服務器,所有的機器與這臺集羣時間進行定時的同步,比如,每隔十分鐘,同步一次時間。
配置時間同步具體實操:
- 時間服務器配置(必須root用戶)
(1)檢查ntp是否安裝
[root@hadoop104 ~]# 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@hadoop104 ~]# vi /etc/ntp.conf
修改內容如下
a)修改1(授權192.168.1.0-192.168.1.255網段上的所有機器可以從這臺機器上查詢和同步時間)
#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
(3)修改/etc/sysconfig/ntpd 文件
[root@hadoop104 ~]# vim /etc/sysconfig/ntpd
增加內容如下(讓硬件時間與系統時間一起同步)
SYNC_HWCLOCK=yes
(4)重新啓動ntpd服務
[root@hadoop104 ~]# service ntpd status
ntpd 已停
[root@hadoop104 ~]# service ntpd start
正在啓動 ntpd: [確定]
(5)設置ntpd服務開機啓動
[root@hadoop102 ~]# chkconfig ntpd on
- 其他機器配置(必須root用戶)
(1)在其他機器配置10分鐘與時間服務器同步一次
[root@hadoop105 ~]# crontab -e
編寫定時任務如下:
*/10 * * * * /usr/sbin/ntpdate hadoop102
(2)修改任意機器時間
[root@hadoop105 ~]# date -s "2017-9-11 11:11:11"
(3)十分鐘後查看機器是否與時間服務器同步
[root@hadoop105 ~]# date