linux下時(shí)間同步的兩種方法分享
發(fā)布日期:2022-03-27 13:29 | 文章來源:源碼之家
方法1:
與一個(gè)已知的時(shí)間服務(wù)器同步
復(fù)制代碼
代碼如下:ntpdate time.nist.gov
其中 time.nist.gov 是一個(gè)時(shí)間服務(wù)器.
刪除本地時(shí)間并設(shè)置時(shí)區(qū)為上海
復(fù)制代碼
代碼如下:rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
方法2:
linux自動(dòng)同步時(shí)間
vi /etc/crontab
加上一句:
復(fù)制代碼
代碼如下:00 0 1 * * root rdate -s time.nist.gov
配置時(shí)間服務(wù)器配置(192.168.10.1)
復(fù)制代碼
代碼如下:1)、# rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm
2)、# vi /etc/ntp.conf
注釋一行:
restrict default ignore
加入一行:
復(fù)制代碼
代碼如下:restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap
3)、# vi /etc/ntp/step-tickers
加入一行:
pool.ntp.org
這樣每次ntpd啟動(dòng)時(shí),會自動(dòng)連接該國際標(biāo)準(zhǔn)時(shí)間服務(wù)器;
4)、# service ntpd start
5)、# netstat -an |grep 123
確保該端口以udp方式開放
時(shí)間客戶端配置(192.168.10.2)
1)、# ntpdate 192.168.10.2
應(yīng)該顯示同步成功
2)、# crond -e
加入
復(fù)制代碼
代碼如下:0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1
每隔10分鐘同步一次時(shí)間
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章