Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3013227
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: LINUX

2008-03-26 11:18:46

修改配置文件/etc/ntp.conf
添加允许使用该ntpd服务器的服务器
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap


将同步好的时间写到CMOS里
vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes

斜体部分是我添加的部分,设定可以使用时间服务器的两个网段的内网地址及使用的外部的时间服务器。现在我们对配置做一个简要的解释:
 
  第一行restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。
 
  配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务。
 
  端口
 
  ntp使用udp协议,记得开放其123端口,注意,否则出现下面的错误,no server suitable for synchronization found
 
  启动NTPD
 
  启动ntpd守护进程:
 
  service ntpd start

   检查服务器同步状态:ntpq -p
 
 
  客户端的配置
 
  以root身份运行周期性任务:
 
  [root@supersun root]# crontab -e
 
  添加以下内容,每15分钟更新一下时间:
 
  */15 * * * * ntpdate 192.168.7.244
 
  此处的ntpdate命令包含在ntp软件包中,记得确认系统中是否已安装。

    检查服务器同步状态:ntptrace  192.168.server.ip

关于错误  8 Jul 18:20:45 ntpdate[4949]: no server suitable for synchronization found

使用 -d 命令查看错误
ntpdate -d 192.168.7.244
 8 Jul 18:20:45 ntpdate[4949]: ntpdate 4.2.2p1@1.1570-o Thu Jan 17 18:14:10 UTC 2008 (1)
Looking for host 192.168.7.244 and service ntp
host found : rac01
transmit(192.168.7.244)
receive(192.168.7.244)
transmit(192.168.7.244)
receive(192.168.7.244)
transmit(192.168.7.244)
receive(192.168.7.244)
transmit(192.168.7.244)
receive(192.168.7.244)
transmit(192.168.7.244)
192.168.7.244: Server dropped: strata too high
server 192.168.7.244, port 123
stratum 16, precision -20, leap 11, trust 000
refid [192.168.7.244], delay 0.02615, dispersion 0.00050
transmitted 4, in filter 4
reference time:    00000000.00000000  Thu, Feb  7 2036 14:28:16.000
originate timestamp: cc1d6e5e.ef02c0d8  Tue, Jul  8 2008 12:41:02.933
transmit timestamp:  cc1dbdfd.3e598e10  Tue, Jul  8 2008 18:20:45.243
filter delay:  0.02759  0.02615  0.02753  0.02745
         0.00000  0.00000  0.00000  0.00000
filter offset: -20382.3 -20382.3 -20382.3 -20382.3
         0.000000 0.000000 0.000000 0.000000
delay 0.02615, dispersion 0.00050
offset -20382.309995

 8 Jul 18:20:45 ntpdate[4949]: no server suitable for synchronization found

解决:
How about issuing the command "ntpq -p"  on the server that's not 
synchronizing and posting the output? That will tell us which internet
servers it can see, if any. My first guess would be that if it's not
synchronized, it's because it can't establish contact with anything to
synchronize with.

My second guess is that it might fail to synchronize because its own
local clock is too far off. If it's more than five minutes off, set the
local clock to approximately the correct time before starting ntp.

Finally, it might be failing to synchronize because your local clock is
drifting too fast. If the undisciplined local clock gains or loses too
much, it will never synchronize and stay synchronized. The limit is
about 500 parts per million.



 


用ntp同步时间, 出现the NTP socket is in use,exiting

如果使用了计划任务在crontab里只执行,就关闭ntpd服务

*/15 * * * * ntpdate 210.72.145.44

service ntpd stop



Q:
I have a machine which serves as NTP server. This machine has more (3) Network interfaces (+ loopback). By default NTP "binds" itself to all available interfaces, i.e. it listens on port 123 on all interfaces:

netstat -an|grep 123
udp 0 0 127.0.0.1.123 *.*
udp 0 0 1.2.3.4.123 *.*
udp 0 0 *.123 *.*
udp 0 0 1.2.5.4.123 *.*
udp 0 0 1.2.6.4.123 *.*

I would like to "bind" NTP to only one interface, say the 1.2.3.4. Is it possible? I do not find any hint on the net.

P:
As far as I know, no version of (x)ntpd can do this.

As an alternative, you could use the "restrict" directive in /etc/ntp.conf file to make the NTP server ignore any communication that comes from the unauthorized interfaces. For example, to allow 1.2.3.4 and loopback only, you might add this to /etc/ntp.conf:

# no restrictions for loopback...
restrict 127.0.0.1 mask 255.0.0.0
# no restrictions for 1.2.3.0/24
restrict 1.2.3.4 mask 255.255.255.0
# everything else is ignored
restrict default ignore

P:
ou might be able to exploit the fact that it only binds to the interfaces at start-up time .
Not very pretty but you could stop the other interfaces comming up then start ntp then start the rest , or during rc2 ifconfig the ones you don't want down before ntp start then start ntp and then the other interfaces.




以下转自:

数据库服务器的时间与真实时间一旦出现差异,就要对数据库服务器进行时间同步。很多地方都把ntpdate放到cron中,5分钟自动同步一次。然而,这么做,常常会引会数据库ORA-01555,甚至db crash。

找到一种方法据说可以解决这个问题。即使用ntpd -x来同步时间 instead of ntpdate。
实际上ntpd,不只是一种时间服务器的server端,同时也可以做client端,相当于ntpdate。当它做client时,与ntpdate的差别是,ntpdate已近淘汰,ntpd则可看作是它升级版。
 
下面的方法是讲如何在linux的环境中设置ntpd:

1. 修改/etc/ntp.conf

2. 加入time server。每个数据库中心都应用会有一组时间服务器,可以找sa要, 比如国际站,加入:

server ntp1.alibaba.com
server ntp2.alibaba.com
server ntp3.alibaba.com

ntp.conf有很多参数,都忽略就行。

3. 修改/etc/sysconfig/ntpd, 加入-x参数,变成:

OPTIONS=”-U ntp -x -p /var/run/ntpd.pid”

这据说是为db同步所要求的。

4. 首先同步一次时间:
ntpdate time.nist.gov; hwclock –systohc

如果数据库还要在运行,建议不要这么做。待例行维护时再处理。

5. 然后启动ntpd:
/etc/init.d/ntpd start

6. 最后加入到自动启动列表:
chkconfig –level 2345 ntpd on

阅读(3444) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~