往往在比较正规的公司里,hadoop集群是不对外的。而比如kudu等组件中,对时间同步要求比较严格。本文旨在在内网中以一台服务器为ntp server,其他节点与之同步的步骤。
本文使用ntp 提供对时服务。
# 查看对时同步状态
ntpstat
# 安装 ntp,不过一般默认都安装了。
yum install ntp
# 开机启动
chkconfig ntpd on
node1 192.168.1.100 node2 192.168.1.101 假设 node1 为 node2 提供对时服务。
node1 编辑 /etc/ntp.conf 文件
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
# 允许内网其他机器同步时间
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
server asia.pool.ntp.org perfer
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
restrict asia.pool.ntp.org nomodify notrap noquery
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
编辑完之后,启动ntp服务
service ntpd start
node2 编辑 /etc/ntp.conf 文件
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
# 配置时间服务器为本地的时间服务器
server 192.168.1.100
restrict 192.168.1.100 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
# 先同步一下,以便平滑同步到一直所需时间尽量短。
ntpdate -u 192.168.1.100
# 启动对时服务
service ntpd start
# 开机启动
chkconfig ntpd on
# 查看对时状态
ntpstat
# 在node1 192.168.1.100 上定时同步:
crontab -e
*/5 * * * * /usr/sbin/ntpdate 210.72.145.44 >/dev/null 2>&1