1、master中执行以下操作
# 安装ntp
yum -y install ntp
# 配置ntp
# vi /etc/ntp.conf
# 注释或者删除以下4行
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
fudge 127.127.1.0 stratum 10
# 启动并加入开机自启服务
systemctl start ntpd
systemctl enable ntpd
2、修改/etc/sysconfig/ntpd 文件
vi /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
3、重新启动ntpd服务
service ntpd status
service ntpd start
4、设置ntpd服务开机启动
chkconfig ntpd on
5、其他机器配置(必须是root用户)
(1)在其他机器配置10分钟与时间服务器同步一次
crontab -e
编写定时任务如下:
*/10 * * * * /usr/sbin/ntpdate 时间同步服务器主机名
(2)修改任意机器时间
date -s "2017-9-11 11:11:11"
(3)十分钟后查看机器是否与时间服务器同步
date
说明:测试的时候可以将10分钟调整为1分钟,以节省时间。
6、所有slave从节点中执行以下操作
# 安装
yum -y install ntpdate
# 设置开机启动
systemctl enable ntpdate
# 时间同步
ntpdate master.hadoop