CentOS6.8搭建NTP服務(wù)器完整教程
準(zhǔn)備工作
確保系統(tǒng)已連接網(wǎng)絡(luò)并具備root權(quán)限,使用yum update
更新系統(tǒng)軟件包。
安裝NTP服務(wù)
yum install ntp -y
安裝完成后驗證版本:ntpd --version
配置NTP服務(wù)器
編輯配置文件:vi /etc/ntp.conf
# 添加國內(nèi)公共NTP服務(wù)器 server ntp.ntsc.ac.cn iburst server cn.ntp.org.cn iburst # 允許內(nèi)網(wǎng)客戶端訪問 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 啟用本地時鐘 server 127.127.1.0 fudge 127.127.1.0 stratum 10
防火墻設(shè)置
iptables -I INPUT -p udp --dport 123 -j ACCEPT
service iptables save
service iptables restart
啟動NTP服務(wù)
service ntpd start
chkconfig ntpd on
ntpstat
客戶端配置
Linux客戶端執(zhí)行:ntpdate 服務(wù)器IP
設(shè)置定時任務(wù):crontab -e
添加:
*/30 * * * * /usr/sbin/ntpdate 服務(wù)器IP >/dev/null 2>&1
驗證同步狀態(tài)
ntpq -p
ntpstat
顯示synchronised to NTP server
表示同步成功。
常見問題排查
- 服務(wù)啟動失?。簷z查
/var/log/messages
日志 - 時間不同步:確認(rèn)防火墻是否開放UDP 123端口
- 同步延遲大:嘗試更換NTP服務(wù)器源