Linux下自動調整時間和時區與Internet時間同步

(原文連接)html


調整linux系統時間和時區與Internet時間同步
1、修改時區:
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
修改成中國的東八區
# vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false
2、配置新的時間
日期設定:
# date -s 2008/05/06
時間設定:
# date -s 18:40:00
查看硬件時間(BIOS的):
    hwclock [-rw]
    -r:查看現有BIOS時間,默認爲-r參數
    -w:將如今的linux系統時間寫入BIOS中
    當咱們進行完 Linux 時間的校時後,還須要以 hwclock -w 來更新 BIOS 的時間,由於每次開機的時候,系統會從新由 BIOS 將時間讀出來,因此, BIOS 纔是重要的時間依據。
# hwclock
Tue 06 May 2008 03:49:37 PM CST  -0.039646 seconds
同步BIOS時鐘,強制把系統時間寫入CMOS:
# clock -w
3、實現Internet時間同步(這裏能夠忽略上面兩步)
方法1. 開機的時候自動網絡校時:
    vi /etc/rc.d/rc.local
    /usr/sbin/ntpdate -u 192.168.0.2 192.168.0.3 192.168.0.4;   /sbin/hwclock -w
方法2. 設定計劃任務
crontab格式以下:
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
設定crontab計劃任務也有兩種方式:
一、寫在/etc/crontab裏
代碼:
00 11 * * * root ntpdate 210.72.145.44
天天11點與中國國家授時中心同步時間
天天11點與中國國家授時中心同步時間
固然前提是
apt-get install ntpdate
代碼也但是
00 11 * * * root ntpdate us.pool.ntp.org
二、使用命令crontab -e
crontab -e
    10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w
這樣天天5:10自動進行網絡校時,並同時更新BIOS的時間
################################linux

同步網絡時間:輸入ntpdate time.nist.gov同步網絡時間網絡

[root@localhost ~]# ntpdate time.nist.govui

12 Oct 17:25:01 ntpdate[2784]: step time server 132.163.4.103 offset 1147751.472254 sec.net

##出現以上信息說明同步成功##unix

注:如提示命令不存在,直接輸入:yum install ntp -y  安裝ntp軟件包。server

相關文章
相關標籤/搜索