Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

CentOS 6.5 部署 NTP 時間同步服務

部署注意事項:時區要在安裝系統時設定好,否則無法同步。

安裝與配置 NTP 服務

yum -y install ntp
vi /etc/ntp.conf

編輯設定檔:

# line 19: 添加允許接收請求的網絡範圍
restrict 192.168.30.0 mask 255.255.255.0 nomodify notrap
# 客戶端需要同步的 ip,有多少個客戶端就添加多少個
restrict 192.168.30.5
# 同步的上層服務器(中國最活躍的時間服務器:https://www.pool.ntp.org/zone/cn)
server 210.72.145.44 prefer # 中國國家授時中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
# 允許上層時間服務器主動修改本機時間
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# 外部時間服務器不可用時,以本地時間作為時間服務
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

在底部加入:

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

防火牆設定

對外開放 123 埠:iptables -I INPUT -p udp -m udp --sport 123 -j ACCEPT。最好的辦法是關閉所有 Linux 系統防火牆:

chkconfig --level 2345 ip6tables off
chkconfig --level 2345 iptables off
service ip6tables stop
service iptables stop

查看防火牆是否關閉成功:chkconfig --list | grep ip。

允許 BIOS 與系統時間同步,簡單命令 hwclock -w 也可,或修改設定檔 vi /etc/sysconfig/ntpd 並設 SYNC_HWCLOCK=yes。

查看服務連接與監聽:netstat -tlunp | grep ntp;查看本機與上層 NTP 服務器通信情況:ntpq -p;查看 123 埠:lsof -i:123。

啟動與自啟動

/etc/rc.d/init.d/ntpd start 或 service ntpd start
chkconfig ntpd on
chkconfig --level 35 ntpd on

NTP-Client(Linux)部署

在 CentOS Client 上同步時間:ntpdate 192.168.30.3。若提示 no server suitable for synchronization found,加入 -u 參數可越過防火牆同步,例如 ntpdate -u 192.168.30.3。

設定定時同步:編輯 vi /root/ntpupdate.sh,內容為 /usr/sbin/ntpdate 192.168.30.3,再用 crontab -e 加入 */1 * * * * /root/ntpupdate.sh 每分鐘執行一次。

NTP-Client(Windows)部署:設定時間服務器地址即可。

CentOS 6.5 部署 NTP 時間同步服務

Copyright © Linux教程網 All Rights Reserved