一、NTP服务器(IP:192.168.1.101)
-
安装:yum install -y ntp
-
防火墙允许:iptables -A INPUT -i $EXTIF -p udp -s 192.168.1.0/24 --dport 123 -j ACCEPT
-
配置:vim /etc/ntp.conf
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server前#去掉
-
启动:/etc/init.d/ntpd start
chkconfig ntpd on
-
观察:ntpq -p或ntpstat
二、NTP客户端
-
安装:yum install -y ntpdate
-
先手动同步:ntpdate 192.168.1.101(排错:ntpdate -d 192.168.1.101)
-
配置:vim /etc/ntp.conf
server 192.168.1.101
-
启动:/etc/init.d/ntpd start
chkconfig ntpd on
-
写入crontab -e
增加一行,在每天的 6 点 10 分与时间同步服务器进行同步
10 06 * * * /usr/sbin/ntpdate ntp-server 的 ip >>/usr/local/logs/crontab/ntpdate.log
注意:
-
自建NTP time与外部server time不能差太多
-
防火墙要允许UDP port 123
-
需要等几分钟生效
-
server与client间时间误差不能大于1000s