一些大数据框架需要集群的时间是同步的,例如hbase ,我们可以使用ntp进行时钟同步,大体流程,设置一套机器的时间为时钟源,其余的linux机器执行定时任务去同步时钟源的时间到本机 配置步骤如下:
1、看下ntp是否安装,没有的话需要安装ntp
rpm -qa|grep ntp
2、切换root账号
su -
3、修改ntp配置文件
vi /etc/ntp.conf
修改里面的配置,修改内容如下
(1)修改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
(2)修改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
(3)添加3(添加默认的一个内部时钟数据,使用它为局域网用户提供服务。)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
4、修改/etc/sysconfig/ntpd 文件
vim /etc/sysconfig/ntpd
在ntpd中增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
5、重新启动ntpd
service ntpd status 先看状态
service ntpd start 如果是stop的状态 接下来启动ntp
6、开启ntpd服务,至此,时钟源时间配置完毕
chkconfig ntpd on
7、切换到其他机器,切换到root用户,在其他机器配置5分钟与时间服务器同步一次
crontab -e
在里面编写脚本,注意这个hadoop102为时钟源的hostname,如不知道时钟源hostname是什么,切换到时钟源,在命令行输入hostname查看
*/5 * * * * /usr/sbin/ntpdate hadoop102
8、测试 ,修改设置了脚本的非时钟源机器时间,等待5分钟 命令行输入date查看时间是否和时钟源同步。
date -s "2018-8-21 11:11:11"