NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致。
服务端配置:
在服务上安装NTP服务: yum install ntp ntpdate -y
修改配置文件:vi /etc/ntp.conf
配置文件内容:
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server x.x.x.x
fudge x.x.x.x stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
重启服务:/etc/init.d/ntpd restart
配置防火墙:vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p udp --dport 123 -j ACCEPT
查看状态:ntpq -p
官方时间服务器:ntpdate pool.ntp.org
客户端配置:
将客户端指向服务器:ntpdate x.x.x.x
同步出现以下提示:the NTP socket is in use, exiting
将ntpd服务停止,在执行同步命令,执行完成在启动ntpd服务
/etc/init.d/ntpd stop
ntpdate pool.ntp.org
/etc/init.d/ntpd start
配置同步计划任务
crontab -e
分 时 日 月 星期 /usr/sbin/ntpdate ntp-server x.x.x.x >>/usr/local/logs/crontab/ntpdate.log