1、安裝ntp
#yum install ntp
2、執(zhí)行命令:
#ntpdate us.pool.ntp.org 。
rhas5的時(shí)區(qū)是以文件形式存在的,當(dāng)前的時(shí)區(qū)文件是在/etc/localtime
其他時(shí)區(qū)的文件存放在/usr/share/zoneinfo下
3、我們使用的是東八區(qū)(+0800),北京,上海的時(shí)間
所以將#cp -f /usr/share/zoneinfo/Asia/Shanghai拷貝到/etc/localtime
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime/p>
p>#reboot
重啟之后,date查看時(shí)間、查看當(dāng)前時(shí)區(qū) date -R、查看/修改Linux時(shí)區(qū)和時(shí)間
一、時(shí)區(qū)
1. 查看當(dāng)前時(shí)區(qū)
date -R
2. 修改設(shè)置時(shí)區(qū)
方法(1)
tzselect
方法(2) 僅限于RedHat Linux 和 CentOS系統(tǒng)
timeconfig
方法(3) 適用于Debian
dpkg-reconfigure tzdata
3. 復(fù)制相應(yīng)的時(shí)區(qū)文件,替換CentOS系統(tǒng)時(shí)區(qū)文件;或者創(chuàng)建鏈接文件
cp /usr/share/zoneinfo/$主時(shí)區(qū)/$次時(shí)區(qū) /etc/localtime
在中國可以使用:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、時(shí)間
1、查看時(shí)間和日期
date
2、設(shè)置時(shí)間和日期
將CentOS系統(tǒng)日期設(shè)定成2011年11月30日的命令
date -s 11/30/11
將CentOS系統(tǒng)時(shí)間設(shè)定成下午09點(diǎn)13分0秒的命令
date -s 09:13:00
3. 將當(dāng)前時(shí)間和日期寫入BIOS,避免重啟后失效
hwclock -w
三、定時(shí)同步時(shí)間
讓系統(tǒng)時(shí)間與硬件時(shí)鐘同步,用:
wclock –hctosys
#或
clock –hctosys
相反地,讓硬件時(shí)鐘與系統(tǒng)時(shí)間同步:
hwclock –systohc
#或
clock –systohc
讓系統(tǒng)時(shí)間每隔十分鐘去同步一下硬件時(shí)間。
[hqw@localhost root]$ vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/10 * * * * root hwclock --hctosys #加入此行,每隔10分鐘執(zhí)行一次hwclock --hctosys