天天看點

每天淩晨2點同步時間linux,linux時間同步的幾種方法

方法1:與一個已知的時間伺服器同步

複制代碼

代碼如下:

ntpdate time.nist.gov

其中 time.nist.gov 是一個時間伺服器.

删除本地時間并設定時區為上海

複制代碼

代碼如下:

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

方法2:linux自動同步時間

vi /etc/crontab

加上一句:

複制代碼

代碼如下:

00 0 1 * * root rdate -s time.nist.gov

配置時間伺服器配置(192.168.10.1)

複制代碼

代碼如下:

1)、# rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm

2)、# vi /etc/ntp.conf

注釋一行:

restrict default ignore

加入一行:

複制代碼

代碼如下:

restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap

3)、# vi /etc/ntp/step-tickers

加入一行:

pool.ntp.org

這樣每次ntpd啟動時,會自動連接配接該國際标準時間伺服器;

4)、# service ntpd start

5)、# netstat -an |grep 123

確定該端口以udp方式開放

時間用戶端配置(192.168.10.2)

1)、# ntpdate 192.168.10.2

應該顯示同步成功

2)、# crond -e

加入

複制代碼

代碼如下:

0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1

每隔10分鐘同步一次時間