linux下時間同步的兩種方法分享

方法1:

與一個已知的時間服務器同步linux


代碼以下:服務器

ntpdate time.nist.govide

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

刪除本地時間並設置時區爲上海
 

rest

代碼以下:orm

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
crontab

方法2:
linux自動同步時間vi /etc/crontab加上一句:同步


代碼以下:it

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

配置時間服務器配置(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分鐘同步一次時間

相關文章
相關標籤/搜索