Chinaunix首页 | 论坛 | 博客
  • 博客访问: 120126
  • 博文数量: 43
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 400
  • 用 户 组: 普通用户
  • 注册时间: 2016-10-14 10:31
文章分类

分类: 信息化

2017-05-10 08:43:56

192.168.56.11   ntp服务器

192.168.56.200  ntp服务器上层同步ip

192.168.56.12   客户端

1:查看客户端和服务器端ntp rpm包是否安装

[root@11g ~]# rpm -qa | grep ntp

fontpackages-filesystem-1.41-1.1.el6.noarch

ntp-4.2.4p8-3.el6.x86_64

ntpdate-4.2.4p8-3.el6.x86_64

如果没有后面两个,需要安装,注意是客户端和服务器端都要查看

2:在需要做ntp服务器的主机 编辑 /etc/ntp.conf

[root@11g ~]# cp /etc/ntp.conf /etc/ntp.conf.bak  先拷贝一份做备份

[root@11g ~]# rm -rf /etc/ntp.conf                显出原始ntp配置文件

[root@11g ~]# vi /etc/ntp.conf                    重新编辑一份ntp配置文件

driftfile /var/lib/ntp/drift

restrict 192.168.56.12                    

restrict 127.0.0.1 

restrict -6 ::1

server 192.168.56.200

fudge 192.168.56.200 stratum 8

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

注释:

restrict 192.168.56.12      <---------客户端需要同步的ip,有多少个客户端,添加多      

restrict 127.0.0.1          <---------允许本地同步,便于本地监控、配置

restrict -6 ::1

server 192.168.56.200       <---------需要同步的上层服务器

fudge 192.168.56.200 stratum 8    <-------同步上层服务器的stratum 大小不能超过或等于16

还有一种方案是:

[root@11g ~]# vi /etc/ntp.conf                    

driftfile /var/lib/ntp/drift

restrict default  nomodify notrap      <-----      允许所有ip,省去设置麻烦           

restrict 127.0.0.1 

restrict -6 ::1

server 192.168.56.200

fudge 192.168.56.200 stratum 8

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

3:启动ntp服务器

[root@11g ~]# /etc/init.d/ntpd start       启动

Starting ntpd:                                             [  OK  ]

[root@11g ~]# chkconfig ntpd on            设置开机自启动ntpd服务

[root@11g ~]# lsof -i:123                   查看123端口

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

ntpd    2862  ntp   16u  IPv4  22529      0t0  UDP *:ntp 

ntpd    2862  ntp   17u  IPv6  22530      0t0  UDP *:ntp 

ntpd    2862  ntp   18u  IPv6  22534      0t0  UDP localhost6.localdomain6:ntp 

ntpd    2862  ntp   19u  IPv6  22535      0t0  UDP [fe80::a00:27ff:fe8a:b4f0]:ntp 

ntpd    2862  ntp   20u  IPv6  22536      0t0  UDP [fe80::a00:27ff:feb9:c941]:ntp 

ntpd    2862  ntp   21u  IPv4  22537      0t0  UDP localhost.localdomain:ntp 

ntpd    2862  ntp   22u  IPv4  22538      0t0  UDP 11g:ntp 

ntpd    2862  ntp   23u  IPv4  22539      0t0  UDP 192.168.110.12:ntp   <-----可以看出,设置成功

[root@11g ~]# ntpq -p        如果出现这样的情况,ntp服务器最后设置才算成功

     remote           refid      st t when poll reach   delay   offset  jitter

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

*192.168.56.200  LOCAL(0)        11 u    9   64  377    1.362    2.822   0.449

以下是失败的设置:

[root@11g ~]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

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

 192.168.56.200  .INIT.          16 u   41   64    0    0.000    0.000   0.000

4:防火墙设置

iptables -I INPUT -p udp -m udp --sport 123 -j ACCEPT    对外开放123端口

最好的办法是将所有linux系统的防火墙都关闭:

chkconfig --level 2345 ip6tables off      

chkconfig --level 2345 iptables off         

service ip6tables stop

service iptables stop                       

查看是否关闭成功:

[root@mysql ~]# chkconfig --list | grep ip

ip6tables      0:off1:off2:off3:off4:off5:off6:off

iptables      0:off1:off2:off3:off4:off5:off6:off

3:客户端设置

[root@mysql ~]# ntpdate 192.168.56.11  设置同步

22 Jul 06:53:14 ntpdate[5611]: no server suitable for synchronization found

[root@mysql ~]# ntpdate -d 192.168.56.11  查看原因

22 Jul 02:55:01 ntpdate[2096]: ntpdate 4.2.4p8@1.1612-o Thu Jan 10 15:17:41 UTC 2013 (1)

Looking for host 192.168.56.11 and service ntp

host found : 11g

transmit(192.168.56.11)

receive(192.168.56.11)

transmit(192.168.56.11)

receive(192.168.56.11)

transmit(192.168.56.11)

receive(192.168.56.11)

transmit(192.168.56.11)

receive(192.168.56.11)

transmit(192.168.56.11)

192.168.56.11: Server dropped: strata too high    <------失败原因stratum 设置的太高,这里设置成16了,前面已经提到过要注意

server 192.168.56.11, port 123

stratum 16, precision -24, leap 11, trust 000

refid [192.168.56.11], delay 0.02599, dispersion 0.00005

transmitted 4, in filter 4

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

originate timestamp: d777e086.0c12c80f  Tue, Jul 22 2014  2:55:02.047

transmit timestamp:  d777e086.0bf476b0  Tue, Jul 22 2014  2:55:02.046

filter delay:  0.02658  0.02638  0.02602  0.02599 

         0.00000  0.00000  0.00000  0.00000 

filter offset: 0.000135 -0.00003 0.000137 0.000145

         0.000000 0.000000 0.000000 0.000000

delay 0.02599, dispersion 0.00005

offset 0.000145

22 Jul 02:55:02 ntpdate[2096]: no server suitable for synchronization found

如果stratum 设置没有问题的话,第一次执行

[root@mysql ~]# ntpdate 192.168.56.11 

22 Jul 06:53:14 ntpdate[5611]: no server suitable for synchronization found

需要再等上3-5分钟再次执行

[root@mysql ~]# ntpdate 192.168.56.11

22 Jul 06:54:45 ntpdate[5627]: adjust time server 192.168.56.11 offset -0.119003 sec    <-----同步成功

4:客户端设置定时同步时间

[root@mysql ~]# vi /root/ntpupdate.sh    编辑定时脚本

/usr/sbin/ntpdate 192.168.56.11

[root@mysql ~]# cat /root/ntpupdate.sh   编辑完之后查看

/usr/sbin/ntpdate 192.168.56.11

[root@mysql ~]# crontab -e               编辑定时任务,每分钟执行一次

*/1 * * * * /root/ntpupdate.sh

[root@mysql ~]# crontab -l

*/1 * * * * /root/ntpupdate.sh            编辑后查看

注意:

1:本身主机设置成ntp服务器:

[root@oracle11g ~]# cat /etc/ntp.conf

idriftfile /var/lib/ntp/drift

restrict default  nomodify notrap  

restrict 127.0.0.1 

restrict -6 ::1

server 127.127.1.0

fudge 127.127.1.0 stratum 8

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

2:客户端手工设置ntpdate时,需要stop 客户端的ntpd服务 
阅读(1229) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~