服务器每隔好几个月,总会差那么几分钟。应对措施,就是每隔段时间,进行网络对时。

以下摘自《鸟哥的私房菜》,可解读为什么会有偏差的问题。

1
2
3
4
5
6
7
事實上,在我們的身邊就有很多的原子鐘,例如石英表,還有電腦主機上面的 BIOS 內部就含有一個原子鐘在
紀錄與計算時間的進行吶!不過由於原子鐘主要是利用計算晶片 (crystal) 的原子震盪週期去計時的,
這是因為每種晶片都有自己的獨特的震盪週期之故。 然而因為這種晶片的震盪週期在不同的晶片之間多多少少都會有點差異性,
甚至同一批晶片也可能會或多或少有些許的差異(就連溫度也可能造成這樣的誤差呢!),
因此也就造成了BIOS的時間會三不五時的給他快了幾秒或者慢了幾秒。
或許您會認為,BIOS 計時器每天快個五秒也沒有什麼了不起的,不過如果您再仔細的算一算,會發現,一天快五秒, 那麼一個月快2.5分鐘,
一年就快了 75 分鐘了!所以說,呵呵!時間差是真的會存在的! (依据该原理,只要关机或者重启次数越多,时间就会差得越离谱)

1.挑选最快最稳定的ntp上层服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C:\Documents and Settings\linqp>ping ntp.api.bz -n 100
Approximate round trip times in milli-seconds:
Minimum = 67ms, Maximum = 89ms, Average = 80ms

C:\Documents and Settings\linqp>ping t3.hshh.org -n 50
Approximate round trip times in milli-seconds:
Minimum = 18ms, Maximum = 22ms, Average = 19ms

C:\Documents and Settings\linqp>ping t1.hshh.org -n 50
Approximate round trip times in milli-seconds:
Minimum = 22ms, Maximum = 27ms, Average = 24ms

C:\Documents and Settings\linqp>ping 1.cn.pool.ntp.org -n 50
Ping statistics for 122.226.192.4:
Packets: Sent = 50, Received = 50, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 18ms, Maximum = 24ms, Average = 21ms

2.使用ntpdate同步系统时间

1
root@krc:~# /usr/sbin/ntpdate t3.hshh.org

修改前

1
2
3
4
root@krc:~# date
Tue Jul 13 16:22:42 CST 2010
root@krc:~# hwclock -r
Tue 13 Jul 2010 04:21:23 PM CST -0.001126 seconds

修改后

1
2
3
4
root@krc:~# date
Tue Jul 13 16:26:33 CST 2010
root@krc:~# hwclock -r
Tue 13 Jul 2010 04:26:45 PM CST -0.001124 seconds

3.建立计划任务

1
2
3
4
5
6
7
8
9
10
root@krc:~#crontab -e
# m h dom mon dow command
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
28 23 * * * /etc/webmin/cron/tempdelete.pl
1 0 * * 1 find /data1/backup_zone/data_www/* -mtime +28 |xargs rm -f
10 00 * * 1 cat /dev/null > /data1/backup_zone/data_www/snapfile
11 00 * * * bash /root/script-bak/bak_www.sh
1 1 * * * bash /root/script-bak/bak_conf.sh
11 1 * * 1 find /data1/backup_zone/data_conf/* -mtime +28 |xargs rm -f
*/10 * * * * /usr/sbin/ntpdate t3.hshh.org && /sbin/hwclock -w

4.参考资料

1
2
3
鸟哥的教程 http://linux.vbird.org/linux_server/0440ntp.php
Public NTP Server http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers
Asia Public NTP Server http://www.pool.ntp.org/zone/asia
Trackback

no comment untill now

Add your comment now