Linux下如何實現與Internet時間同步
一、安裝ntp
[root@server-2 ~]# yum install -y ntpdate
二、同步時間
// 方式一、使用域名連接,要經過DNS解析,速度慢。 [root@server-2 ~]# ntpdate pool.ntp.org
// 方式二、使用IP連接,超級快。 [root@server-2 ~]# ntpdate 120.24.81.91
http://www.pool.ntp.org是NTP的官方網站,在這上面我們可以找到離我們國家的NTP Server cn.pool.ntp.org.它有3個服務器地址:
服務器一: 1.cn.pool.ntp.org
服務器二: 2.asia.pool.ntp.org
服務器三: 3.asia.pool.ntp.org
(直接用域名有時有問題,可以先Ping出他們的IP,然后用IP地址同步)
// 出現以下信息說明成功
Feb 21:23:06 ntpdate[62910]: step time server 182.92.12.11 offset -40.589470 sec
三、將系統時間寫入到系統硬件當中,避免重啟服務器時間覆蓋
// 顯示hardwareclock系統硬件時間
[root@server-2 ~]# hwclock
// 將系統時間寫入到系統硬件當中
[root@server-2 ~]# hwclock -w
四、設定計划任務同步網絡時間
設定crontab計划任務:
crontab -e
10 5 * * * /usr/sbin/ntpdate 120.24.81.91
