加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

CentOS下如何部署NTP服务器

发布时间:2016-08-16 18:40:17 所属栏目:Linux 来源:站长网
导读:安装NTP wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p3.tar.gz tar ntp-4.2.6p3.tar.gz cd ntp-4.2.6p3 ./configure --prefix=/usr

安装NTP

wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p3.tar.gz

tar ntp-4.2.6p3.tar.gz

cd  ntp-4.2.6p3

./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks

make

make install

cp /usr/local/ntp/bin/* /usr/bin/

修改ntp.conf配置文件

首先先了解一下ntp.conf里面涉及到参数说明

关于权限设定部分; 权限的设定主要以 restrict 这个参数来设定

格式如下:

restrict IP地址 mask 子网掩码 参数; 其中 IP 可以是IP地址,也可以是 default ,default

就是指所有的IP参数有以下几个:

ignore :关闭所有的 NTP 联机服务

nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时

notrust:客户端除非通过认证,否则该客户端来源将被视为不信任子网

noquery :不提供客户端的时间查询

注意:如果参数没有设定,那就表示该 IP (或子网)没有任何限制

用server这个参数设定上级时间服务器

格式如下: server IP地址或域名 [prefer]

IP地址或域名就是我们指定的上级时间服务器,如果 Server 参数最后加上 prefer,表示我们的 NTP

服务器主要以该部主机时间进行校准

driftfile格式如下:driftfile 文件名

在与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内 注意: driftfile

后面接的文件需要使用完整的路径文件名,不能是链接文件,并且文件的权限需要设定成 ntpd守护进程可以写入。

vi /etc/ntp.conf

1.允许任何IP的客户机都可以进行时间同步

将“restrict default kod nomodify notrap nopeer noquery”这行修改成:

restrict default nomodify

2.只允许192.168.0.0网段的客户机进行时间同步

restrict 192.168.0.0 mask 255.255.0.0 nomodify

URL:http://www.bianceng.cn/OS/Linux/201410/45692.htm

源文件安装是没有ntp.conf (闲麻烦的话,大家可以选择yum -y install ntp) 手动添加,touch /etc/ntp.conf,复制以下

======================================================================

restrict default nomodify notrap noquery

restrict 127.0.0.1

restrict 192.168.0.0 mask 255.255.0.0 nomodify

server 0.pool.ntp.org

server 1.pool.ntp.org

server 2.pool.ntp.org

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10 #调整为8,表示将使用local时间作为ntp服务提供给ntp客户端

driftfile /var/lib/ntp/drift

broadcastdelay  0.008

keys            /etc/ntp/keys

=====================================================================

让本服务器时间与time.nist.gov时间同步,使服务器为标准时间

使用ntpd同步时间(注意:使用ntpd时,本机与上源的时间相差不能太大,否则不运行,所以应

该先用ntpdate取得时间初值后在启动ntpd)

[root@localhost ~]# ntpdate time.nist.gov

以守护进程启动ntpd

[root@localhost ~]#/usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid

如果是yum安装ntp  使用 chkconfig --level 35 ntpd on

[root@localhost ~]#netstat -nul |grep 123

udp        0      0 192.168.50.91:123           0.0.0.0:*                              

udp        0      0 127.0.0.1:123               0.0.0.0:*                              

udp        0      0 0.0.0.0:123                 0.0.0.0:*

[root@localhost ~]# ntpq -p

remote           refid                     st t when   poll  reach   delay     offset         jitter

==============================================================================

114.80.81.1     204.152.184.72     2 u    5      64    1       13.142  -287655   0.001

218.75.4.130    216.218.192.202  2 u    4      64    1       15.109  -287655   0.001

*LOCAL(0)        .LOCL.               10 l    3      64    1       0.000    0.000       0.001

 

remote:响应这个请求的NTP服务器的名称。

refid:NTP服务器使用的上一级ntp服务器。

st :remote远程服务器的级别.由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端.所以服              务器从高到低级别可以设定为1-16.为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器

when: 上一次成功请求之后到现在的秒数。

poll : 本地机和远程服务器多少时间进行一次同步(单位为秒).在一开始运行NTP的时候这个poll值会比较小,那                  样和服务器同步的频率也就增加了,可以尽快调整到正确的时间范围,之后poll值会逐渐增大,同步的频率               也就会相应减小

reach:这是一个八进制值,用来测试能否和服务器连接.每成功连接一次它的值就会增加

delay:从本地机发送同步要求到ntp服务器的round trip time

offset:主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒(ms)。offset越接近于0,主机和                     ntp服务器的时间越接近

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读