下面内容根据实际情况修改
time.windows.com 时间服务器地址
服务器A 192.168.7.9 时间同步服务器(能通外网)
服务器B 192.168.7.8 内网服务器
服务器A
安装依赖
yum -y install ntp ntpdate
systemctl daemon-reload && systemctl start ntpd && systemctl enable ntpd
- 修改配置文件(参考一下内容):
vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 192.168.7.9
restrict ::1
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
- 设置开机自启
systemctl daemon-reload && systemctl restart ntpd && systemctl enable ntpdate
- 同步时间服务器时间
ntpdate time.windows.com
- 定时任务(每10分钟执行一次)
echo "*/10 * * * * /usr/sbin/ntpdate -u time.windows.com > /dev/null 2>&1" >> /var/spool/cron/root
crontab -l
- 开启防火墙端口
firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --list-ports --permanent
服务器B
安装依赖
yum -y install ntpdate
- 手动同步服务器A
ntpdate 192.168.7.8
- 定时任务(每10分钟执行一次)
echo "*/10 * * * * /usr/sbin/ntpdate 192.168.7.8 > /dev/null 2>&1" >> /var/spool/cron/root
crontab -l
- 端口转发(可以不执行)
iptables -t nat -I OUTPUT -p udp -d 173.0.255.52 --dport 123 -j DNAT --to 173.0.255.52:12345
ntpdate 173.0.255.52