在LAN内架设简单的时间服务器time server

由于工作需要把公司内网内的机器的时间都统一,而且只有几台服务器可以出外网,条件限制只能自己做一个time server了;服务器OS为Solaris,客户端有solaris,win2k和win2003.
开始在www.sunfreeware.com上下了pkg的ntp402,装上后ntpd不能启动,后来就去www.ntp.org去下了个源码,自己编译(过程略....跟其它的软件一样装就行了),后来发现sunfreeware上的下的装好后有个xntpd 。。。也许用这个可以启动服务吧 。。。因为删了就没试,呵呵,下面是设置

服务端的设置(IP为192.168.195.5)
这个文件默认装好后没有的,在/etc/inet/下有个ntp.server文件,cp一份到/etc/ntp.conf就行了
/etc/ntp.conf
# @(#)ntp.server 1.5 99/09/21 SMI
#
# /etc/inet/ntp.server
#
# An example file that could be copIEd over to /etc/inet/ntp.conf and
# edited; it provides a configuration template for a server that
# listens to an external hardware clock, synchronizes the local clock,
# and announces itself on the NTP multicast net.
#
#
# * All TrueTime receivers are now supported by one driver, type 5.
# Types 15 and 25 will be retained only for a limited time and may
# be reassigned in future.
#
# Either a peer or server. Replace "XType" with a value from the
# table above.
#server 127.127.XType.0 prefer
# //定义了两个可用的服务器 在这里也可以直接用域名来代替IP
#setserver ntp.cuhk.edu.hk //这个是internet上的顶级time server
server 137.189.8.137 prefer
#setserver ntp.fudan.edu.cn //这个是复旦大学的
server 61.129.42.32

#fudge 127.127.XType.0 stratum 0

#broadcast 224.0.1.1 ttl 4

enable auth monitor
driftfile /var/ntp/ntp.drift
statsdir /var/ntp/ntpstats/
filegen peerstats file peerstats type day enable
filegen loopstats file loopstats type day enable
filegen clockstats file clockstats type day enable

#//关于认证的选项,因为在lan中用,不做任合的验证
#keys /etc/inet/ntp.keys
#trustedkey 0
#requestkey 0
#controlkey 0

启动ntpd服务
/usr/local/bin/ntpd -c /etc/ntp.conf -l /var/ntp/ntp.log -p /var/run/ntp.pid



客户端
win2k
让客服机定期来和服务器同步时间
打开一个cmd控制台
net time /setsntp:192.168.195.5
at 00:05 /every:sunday w32tm /once
这样在每周日的00:05分客户机只要开着就会和服务器自动同步时间,为了避免有不开机的情况,
在服务管理器中将“Windows Time”的启动类别设成“自动”可使每次开机时都进行更新

win2003 & winXP
打开“日期和时间”属性面板,在Internet时间页中填入时间的服务器就行了

Unix
如果开了r服务可以直接 rdate 192.168.195.5
还可以用ntp的client程序更新,建议用这个,可以写日志
ntpdate 192.168.195.5
或写入root用户的cron里自动每天执行
crontab -e
#synchronization time from 192.168.195.5
05 0 * * * /usr/sbin/ntpdate 192.168.195.5 >> /var/ntp/ntp_client_err.log 2>&1

注意:当ntpd服务启动以后,client不能更新时间,要等一会才能用(半个小时肯定可以了)还不行就看看日志 。
还有一点就是client上的时间和server相差很小的时候(比如只有1分,半分的)执行了命令也不会和服务器同步的,ntp是逐步一点一点的来同步时间的,如果想立刻和服务器同步就把client时间改前或改后10分钟,再同步就可以了

原文见www.feifan.pub.cn

    推荐阅读