在公司內網,搭建服務器集群時,為了到達一致性,需要對服務器時間進行同步。內網一般不能訪問互聯網,此時急需一台內部的時間服務器,用於內網機器的時間同步。
安裝ntp
yum install -y ntp ntpdate
修改配置文件 /etc/ntp.conf
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# 允許設置的可信任地址段對NTPD各服務的訪問,但不允許此地址段內客戶端修改NTPD服務器時間(nomodify)
restrict 192.168.113.0 mask 255.255.255.0 nomodify notrap
# 外部時間服務器
server ntp.aliyun.com
# 外部時間服務器不可用時,以本地時間作為時間服務
server 127.127.1.0
fudge 127.127.1.0 stratum 5
啟動服務
systemctl start ntpd
systemctl enable ntpd
測試
ntpdate -u 127.0.0.1