ntp windows linux端口,Linux 系统安装配置ntp 4.2.8p5时间服务器/客户机

配置时间同步服务器

系统环境:CentOS release 6.5源码:ntp-4.2.8p5.tar.gz

http://www.ntp.org/downloads.html

[zhaojq@virtual-machine]#tar -xzvfntp-4.2.8p5.tar.gz[zhaojq@virtual-machine]#mkdir /usr/ntp/usr/ntp为ntpd的安装后文件路径

[zhaojq@virtual-machine]# cd ntp-4.2.8p5[zhaojq@virtual-machine]#./configure --prefix=/usr/ntp --enable-all-clocks --enable-parse-clocks[zhaojq@virtual-machine]#make && make install

安装成功

修改ntp.conf配置文件

vi /etc/ntp.conf

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

将语句restrict default kod nomodify notrap nopeer noquery

修改为restrict default nomodify

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

在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:

restrict 192.168.1.0 mask 255.255.255.0 nomodify

3、修改时间服务器池

ntp.org现在提供NTP POOL PROJECT,即ntp 服务器池项目。在中国区域,配置如下即可:

server 0.cn.pool.ntp.org

server 3.asia.pool.ntp.org

server 2.asia.pool.ntp.org

其中0.cn 是中国服务器池,*.asia是亚洲的服务器池。

最新列表见:http://www.pool.ntp.org/zone/cn

0818b9ca8b590ca3270a3433284dd417.png

以守护进程启动ntpd

/usr/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid

ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。

配置时间同步客户机

客户端机器使用ntpdate 程序来执行同步。 格式如下:

ntpdate ntp服务器IP

注:如果客户机没有ntpdate,可以将ntp-4.2.8p5中的ntpdate复制到客户机的/usr/sbin/目录

配置客户机定时进行时间同步vi/etc/crontab

增加一行,在每天的5点10分、9点10分、14点10分、19点10分与时间同步服务器进行同步

10 5,9,14,19 * * * /usr/sbin/ntpdate ntp服务器IP

客户机用 ntpdate -dntp服务器IP命令 进行同步测试,查看返回信息:

导致 no server suitable for synchronization found 的错误的信息:Server dropped: no data

客户机用ntpdate -dntp服务器IP命令,有错误信息如下:

[zhaojq@virtual-machine]#/home/ntp/ntpdate -d 61.147.198.101

20 Jan 14:30:52 ntpdate[3436]: ntpdate 4.2.6p4@1.2324 Thu Aug  6 12:00:35 UTC 2015 (1)

Looking for host 61.147.198.101 and service ntp

host found : 61.147.198.101

transmit(61.147.198.101)

transmit(61.147.198.101)

transmit(61.147.198.101)

transmit(61.147.198.101)

transmit(61.147.198.101)

61.147.198.101:Server dropped: no data

server 61.147.198.101, port 123

stratum 0, precision 0, leap 00, trust 000

refid [61.147.198.101], delay 0.00000, dispersion 64.00000

transmitted 4, in filter 4

reference time:    00000000.00000000  Thu, Feb  7 2036 14:28:16.000

originate timestamp: 00000000.00000000  Thu, Feb  7 2036 14:28:16.000

transmit timestamp:  da49a82c.aff08e8c  Wed, Jan 20 2016 14:31:08.687

filter delay:  0.00000  0.00000  0.00000  0.00000

0.00000  0.00000  0.00000  0.00000

filter offset: 0.000000 0.000000 0.000000 0.000000

0.000000 0.000000 0.000000 0.000000

delay 0.00000, dispersion 64.00000

offset 0.000000

20 Jan 14:31:10 ntpdate[3436]: no server suitable for synchronization found

出现这个问题的原因可能有2:

1.检查ntp的版本.如果你使用的是ntp4.2(包括4.2)之后的版本,在restrict的定义中使用了notrust的话,会导致以上错误。

使用以下命令检查ntp的版本:

# ntpq -c version

下面是来自ntp官方网站的说明:

The behavior of notrust changed between versions 4.1 and 4.2.

In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".

In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd

解决:把notrust去掉。

2.检查ntp server的防火墙.可能是server的防火墙屏蔽了udp 123端口。

可以用命令

[zhaojq@virtual-machine]#service iptables stop

来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。

[zhaojq@virtual-machine]#iptables -I INPUT -p udp --dport 123 -j ACCEPT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值