時鐘伺服器在運維工作中,它為了保證所有的伺服器時間正确并且都一緻,起到了至關重要的作用;在伺服器所在的區域網路内部有很多伺服器是與外網隔絕的。通常是通過區域網路内一台電腦作為中轉,通常中轉電腦上面架設時鐘伺服器,保障内網不能上外網的伺服器時鐘同步;
安裝過程也很簡單;下面就是步驟:本篇文章純粹是抛磚引玉,僅供參考;
①确認已經ntp程式包:
# yum install ntp
#讓本伺服器時間與time.nist.gov時間同步,使伺服器為标準時間
[root@ntp ~]# ntpdate time.windows.com
#自動同步伺服器時鐘
[root@ntp ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate time.windows.com
[root@ntp ~]# service crond restart
②配置時間源
# vi /etc/ntp.conf
server time.windows.com
server time.lib.tsinghua.edu.cn
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
③配置是否為其他PC提供時間服務
restrict 192.168.9.0 mask 255.255.255.0 nomodify notrap
④配置開機時自動運作時間服務
# chkconfig ntpd on
# 系統時間與bios事件的偏差記錄
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
# 日志
logfile /var/log/ntp.log
broadcastdelay 0.008
⑤啟動或停止時間服務
# service ntpd start
# service ntpd stop
# service ntpd restart
⑥驗證ntp服務已經運作
# pgrep ntpd
⑦初始同步
# ntpdate -u time.lib.tsinghua.edu.cn
⑧确認同步成功
# ntpq -p
當然,如果要提供時間服務,還必須相應的設定iptable防火牆的配置。CentOS的時間服務使用udp 123端口。
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiInBnauczN1UjM4ETMx8CXxEDMxAjMvwFduVWboNWY0RXYvwVbvNmLvR3YxUjL0M3Lc9CX6MHc0RHaiojIsJye.jpg)
⑨Windows 的PC用戶端同步時間成功;