服务器安装(linux)
要安装ntp 的rpm 包
1、将ntp.conf覆盖/etc/ntp.conf
ntp.conf如下:
# A very simple client-only ntp configuration.
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 8
driftfile /etc/ntp/drift
broadcast 172.16.4.255
restrict default ignore
restrict default nomodify notrap
restrict 172.16.4.0 mask 255.255.255.0
authenticate no
2、为了使NTP服务可以在系统引导的时候自动启动,执行:
# chkconfig ntpd on
3、启动/关闭/重启NTP的命令是:
# /etc/init.d/ntpd start
# /etc/init.d/ntpd stop
# /etc/init.d/ntpd restart
4、使用下面的命令检查时间服务器同步的状态
# ntpq -p
5、使用下面的命令来检查NTP服务是否启动
# netstat -an |grep 123
ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。
客服端安装(每隔一个小时更新一次时间)
1、将ntpdatecron上传到/etc/cron.hourly
chmod +x /etc/cron.hourly/ntpdatecron
ntpdatecron如下:
#!/bin/sh
/usr/sbin/ntpdate 172.16.6.45
/usr/sbin/ntpdate 172.16.6.45
2、要启动 cron务,使用以下命令。
/sbin/service crond start
要停止该服务,使用以下命令。
/sbin/service crond stop