1、安裝ntpdate
yum install ntpdate -y
轉者注:以Ubuntu為例的Debian系統安裝指令如下
apt-get install ntpdate
。
ntpdate簡單用法:
# ntpdate ip
# ntpdate cn.pool.ntp.org
2、date指令
date :檢視目前時間,結果如下:Tue Mar 4 01:36:45 CST 2014
date -s 09:38:40 :設定目前時間,結果如下:Tue Mar 4 09:38:40 CST 2014
3、ntpdate指令
ntpdate -u cn.pool.ntp.org :網絡時間同步指令
注意:若不加上-u參數, 會出現以下提示:no server suitable for synchronization found
-u:從man ntpdate中可以看出-u參數可以越過防火牆與主機同步;
4、ntp常用伺服器
國内:
cn.pool.ntp.org 中國開源免費NTP伺服器
ntp1.aliyun.com 阿裡雲NTP伺服器
ntp2.aliyun.com 阿裡雲NTP伺服器
time1.aliyun.com 阿裡雲NTP伺服器
time2.aliyun.com 阿裡雲NTP伺服器
國外:
time1.apple.com 蘋果NTP伺服器
time2.apple.com 蘋果NTP伺服器
time3.apple.com 蘋果NTP伺服器
time4.apple.com 蘋果NTP伺服器
time5.apple.com 蘋果NTP伺服器
time1.google.com 谷歌NTP伺服器
time2.google.com 谷歌NTP伺服器
time3.google.com 谷歌NTP伺服器
time4.google.com 谷歌NTP伺服器
pool.ntp.org 開源免費NTP伺服器
5、加入crontab
echo "*/20 * * * * /usr/sbin/ntpdate -u ntp1.aliyun.com >/dev/null &" >> /var/spool/cron/root
轉者注:雙引号内指令分别代表
min hour dom mon dow user command
,更多關于crontab可參考【Linux:crontab 定時任務】
版權聲明
本文轉自:https://www.cnblogs.com/luchuangao/p/7795293.html