sdfshfh 2017-04-22
集群时间同步配置
1.配置时间服务器
1.1检查NTP是否安装
[tpsky@master hadoop-2.5.2]$ sudo rpm -qa|grep ntp
ntp-4.2.6p5-10.el6.centos.2.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-10.el6.centos.2.x86_64
1.2编辑/etc/ntp.conf配置文件
[tpsky@master hadoop-2.5.2]$ sudo vim /etc/ntp.conf
第一步:文件中添加如下内容
restrict 10.31.131.0 mask 255.255.255.0 nomodify notrap
第二步:注释以下内容
#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 # local clock
fudge 127.127.1.0 stratum 10
1.3配置BIOS时间与系统时间同步
1.3.1查看/etc/sysconfig/ntpd内容
[tpsky@master hadoop-2.5.2]$ cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
1.3.2编辑/etc/sysconfig/ntpd,在【OPTIONS】前添加如下内容
[tpsky@master hadoop-2.5.2]$ sudo vim /etc/sysconfig/ntpd
内容:
SYNC_HWCLOCK=yes
1.4查看NTP服务启动状态并设置成机器启动
1.4.1查看NTP服务启动状态
[tpsky@master hadoop-2.5.2]$ sudo service ntpd status
ntpd is stopped
1.4.2启动NTP服务
[tpsky@master hadoop-2.5.2]$ sudo service ntpd start
Starting ntpd: [ OK ]
1.4.3查看NTP服务机器启动状态
[tpsky@master hadoop-2.5.2]$ sudo chkconfig --list|grep ntp
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
1.4.4设置NTP服务机器启动
[tpsky@master hadoop-2.5.2]$ sudo chkconfig ntpd on
1.4.5查看NTP服务机器启动状态
[tpsky@master hadoop-2.5.2]$ sudo chkconfig --list|grep ntp
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
1.5测试NTP服务
[tpsky@master hadoop-2.5.2]$ ntpstat
synchronised to local net at stratum 11
time correct to within 3948 ms
polling server every 64 s
2.配置集群中的其他机器
2.1进行时间同步(NTP服务器配置好5分钟后再操作,不然会出错)
[tpsky@yarn hadoop-2.5.2]$ sudo ntpdate master.tpsoft.com
22 Apr 16:23:59 ntpdate[14366]: adjust time server 10.31.131.101 offset 0.000083 sec
2.2设置集群机器与NTP时间服务器,每10分钟同步一次时间(用root用户操作,我试过sudo操作也行)
[tpsky@yarn hadoop-2.5.2]$ sudo crontab -e
输入内容:
0-59/10 * * * * /usr/sbin/ntpdate master.tpsoft.com
2.3查看任务运行日志
[tpsky@secondary hadoop-2.5.2]$ ls /var/log/cron*
/var/log/cron
[tpsky@secondary hadoop-2.5.2]$ sudo more /var/log/cron
Apr 22 17:01:01 secondary run-parts(/etc/cron.hourly)[13695]: finished 0anacron
Apr 22 17:10:01 secondary CROND[13958]: (root) CMD (/usr/sbin/ntpdate master.tpsoft.com)
Apr 22 17:10:01 secondary CROND[13957]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Apr 22 17:20:01 secondary CROND[14254]: (root) CMD (/usr/sbin/ntpdate master.tpsoft.com)