注意事项
双机时钟必须同步,时间误差应控制在1分钟之内。
前提条件
用作时钟源的服务器即时间服务器与各主机间的网络连接正常。
为方便描述,例如时间服务器hostntp的IP地址为:10.10.11.19。
背景信息
所有需要与时间服务器同步时间的主机都是NTP客户端,需要配置NTP服务。
操作步骤
步骤 1 以root用户登录主机。
步骤 2 确认NTP服务已停止。
1. 确认NTP服务是否已启动。
# ps-ef | grep xntpd | grep -v grep
系统显示如下类似信息,则表明NTP服务已启动。
root20532 1 0 15:32:01 ? 0:00 /usr/sbin/xntpd
2. 若NTP服务已启动,执行下列命令停止NTP服务。
# /sbin/init.d/xntpdstop
步骤 3 配置“/etc/hosts”。
将时间服务器的地址10.10.11.19 加入“/etc/hosts”。
# echo"10.10.11.19 hostntp" >> /etc/hosts
步骤 4 配置NTP服务。
1. 配置“/etc/ntp.conf”。
# vi/etc/ntp.conf
serverhostntp
driftfile/etc/ntp.drift
2. 设置文件的权限和属性。
# chownroot:root /etc/ntp.conf
# chmod600 /etc/ntp.conf
# touch/etc/ntp.drift
# chmod755 /etc/ntp.drift
3. 配置“/etc/rc.config.d/netdaemons”。
# vi/etc/rc.config.d/netdaemons
exportNTPDATE_SERVER=hostntp
exportXNTPD=1
exportXNTPD_ARGS=
步骤 5 手工同步时间。
# ntpdatehostntp
手工同步时间是为了减小主机与时间服务器间的时间差,避免NTP Daemon自动退出。
步骤 6 启动NTP服务。
# /sbin/init.d/xntpdstart
步骤 7 添加定时任务。
# crontab-e
在文件中添加如下信息,表示30分钟执行一次。
0,30 ** * * /sbin/init.d/xntpd start > /dev/null 2>&1
步骤 8 核对定时任务添加结果。
# crontab-l | grep ntp
0,30 ** * * /sbin/init.d/xntpd start > /dev/null 2>&1
----结束