一. 使用ntpdate 命令
1.1 服务器可链接外网时
# crontab -e
加入一行:
*/1 * * * * ntpdate 210.72.145.44
210.72.145.44 为中国国家授时中心服务器地址,这样该机每隔1分重就可以与国家授时中心进行同步了。
注意: 在使用ntpdate 命令时, ntpd 服务必须是关闭的, 否则会报the NTP socket is in use, exiting 错误。
关闭 ntpd 服务命令如下:
[root@node2 init.d]# /etc/init.d/ntpd stop
Shutting down ntpd: [ OK ]
1.2. 架设本地时间服务器
需要修改 /etc/ntp.conf文件里的几个配置就可以了,比如本地时间服务器IP 为 10.85.10.119, 配置如下:
server 210.72.145.44 prefer (中国国家授时中心服务器地址 prefer表示优先 注意把默认的server更改成这样)
server 127.127.1.0 (本地时间)
restrict 10.85.10.0 mask 255.255.255.0 nomodify (允许10..85.10.* 的IP 使用该时间服务器)
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap noquery notrust (屏蔽其他IP过来更新时间)
其他的保持默认不动。