服務器 : 192.168.137.3
客戶機: 192.168.137.6
1、 服務器端
centos7下首先確認服務器的防火牆、selinux關閉狀態
# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
第一步 為服務器和客戶機安裝ntp ntpdate --默認已安裝
# yum install ntp ntpdate -y
第二步 查找時間同步服務器
http://www.pool.ntp.org/zone/asia
第三步 編輯 /etc/ntp.conf
server time.windows.com
server s2m.time.edu.cn
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
server 127.127.1.0 iburst local clock 當外部時間不可用時,使用本地時間。
restrict 192.168.137.1 mask 255.255.255.0 nomodify 允許更新的IP地址段
第四步 啟動ntp服務
systemctl start ntpd
systemctl enable ntpd.service 設置開機啟動服務
第五步 驗證服務
# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
211.138.200.209 .INIT. 16 u - 64 0 0.000 0.000 0.000
ns.pku.edu.cn .INIT. 16 u - 64 0 0.000 0.000 0.000
211.138.200.208 .INIT. 16 u - 64 0 0.000 0.000 0.000
nipper.paina.jp .INIT. 16 u - 64 0 0.000 0.000 0.000
send.mx.cdnetwo .INIT. 16 u - 64 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 5 l 52 64 1 0.000 0.000 0.000
# date -R
Fri, 15 Jul 2016 15:28:34 +0800
2.客戶端
第六步 遠程客戶端時間同步測試
# date
Fri Jul 15 15:31:22 CST 2016
# ntpdate 192.168.137.3
15 Jul 15:33:04 ntpdate[63912]: step time server 192.168.137.3 offset -4.492463 sec
第七步 客戶端設置計划任務,每天晚上1點同步時間
crontab -e
00 01 * * * root /usr/sbin/ntpdate 192.168.137.3; /sbin/hwclock -w
格式 00 01 * * * 五個字符表示 分 時 日 月 年