配置ntpd提供网络授时服务

在服务器单机运行的时候,时钟准不准并不是太重要。然而,在服务器间有协作越密切,就越来越显示出时钟的重要性了。举几个简单的例子:

Linux进行服务器文件备份的时候,备份服务器通过文件修改时间从主服务器上拉取修改的文件列表。这时,两台服务器时间不同步,就会造成列表内容过多,网络带宽浪费。

在做Oracle RAC集群的时候,如果两台服务器时间不同步则会造成主服务器已失效,备份服务器还没到切换的时间。这种时间的断层使得RAC几乎不起作用。

所以,虽然不重要,但是有必要在局域网中设置一台标准的授时服务器。Linux系统中使用ntpd软件包通过ntp协议实现网络授时。

理论描述

ntpdate命令在客户端运行,想服务器段ntpd提交时间校准请求。ntpd通过ntp协议回应客户端的请求。服务器在udp 123端口监听。

操作步骤

安装ntpd并校准服务器时间

[root@localhost ~]#yum install ntpd ntpdate -y
[root@localhost ~]#ntpdate 210.72.145.44

配置ntpd

配置服务器文件为/etc/ntp.conf。这里只显示有修改的部分。

 [root@localhost ~]#vim /etc/ntpd.conf
driftfile /var/lib/ntp/drift
# 只允许从时间服务器同步时间,不允许trap,modify等请求
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
##本地允许所有操作
restrict 127.0.0.1
restrict -6 ::1
##本地网络中设置较少限制
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
restrict 172.16.0.0 mask 255.15.0.0 nomodify notrap
##上述设置为设置客户端的权限。
# Use public servers from the pool.ntp.org project.
server 210.72.145.44 perfer
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 0.CentOS.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
##设置本地服务器向那些服务器看齐
server  127.127.1.0     # local clock
##在时间服务器没网络连接的话,设置本地时钟。
fudge   127.127.1.0 stratum 10
##设置本地始终的权值


启动ntpd服务

[root@localhost ~]#service ntpd start
[root@localhost ~]#chkconfig ntpd on

配置防火墙

添加如下记录到防火墙配置文件,并重启防火墙

[root@localhost ~]#iptables -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j accept'
[root@localhost ~]#service iptables restart

查看服务器工作状态

ntpstat output detial


ntpstat用来查看ntp状态,ntpq -p用来输出当前服务器从那些主机同步时间。

客户端配置

客户端使用ntpdate命令从服务器端同步时间。

[root@localhost ~]#ntpdate time.honliv.com

可将上述命令添加到crontab中,记得使用ntpdate的绝对路径。

即可。对于Oracle RAC环境,搭建者往往使用其中一台节点作为ntpd服务器。这点作者不敢苟同。从可靠性上讲,万一有故障的是ntpd这台呢。另一方面,RAC提供数据库服务肯定要和其他服务器联通。既然联通,使用全局ntpd服务器不挺好的。当然,全局没有就不说了。

本文出自 “Elephant” 博客,请务必保留此出处http://zlyang.blog.51cto.com/1196234/1725394

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值