内网对时服务 ntp 平滑更改

往往在比较正规的公司里,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

参考

转载于:https://my.oschina.net/corleone/blog/855900

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值