配置ntpd提供网络授时服务

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

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

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

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

理论描述

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

操做步骤

安装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

配置防火墙

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

[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用来输出当前服务器从那些主机同步时间。spa

客户端配置

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

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

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

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

相关文章
相关标签/搜索