时间以及时区设置
首先确认使用utc还是local time. UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time) Local time 是你手表上的时间传统的POSIX计算机(Solaris,bsd,unix)使用UTC格式
linux可以处理UTC时间和蹩脚的Windows所使用的local time到底是使用UTC还是local time可以这样来确定:
如果机器上同时安装有Linux和Windows,建议使用local time 如果机器上只安装有Linux,建议使用utc 确定后编辑/etc/sysconfig/clock, UTC=0 是local time; UTC=1 是UTC(GMT)1) 使用cat /etc/sysconfig/clock查看当前时区
linux5:~ # cat /etc/sysconfig/clock## Path: System/Environment/Clock## Description: Information about your timezone and time## Type: string## ServiceRestart: boot.clock## Set to "-u" if your system clock is set to UTC, and to "--localtime"# if your clock runs that way.#HWCLOCK="-u"## Type: string(Europe/Berlin,Europe/London,Europe/Paris)
## ServiceRestart: boot.clock## Timezone (e.g. CET)# (this will set /usr/lib/zoneinfo/localtime)#TIMEZONE="US/Pacific"DEFAULT_TIMEZONE="US/Pacific"linux5:~ #2) 使用tzselect设置时区,最后结果如下
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZto the file '.profile' in your home directory; then log out and log in again.Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:Asia/Shanghailinux5:~ #3) 复制相应的时区文件,替换系统默认时区
linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimelinux5:~ #4) 将当前时间写入BIOS永久生效(避免重启后失效)
linux5:~ # hwclockTue Jan 29 18:22:59 2008 -0.565688 secondslinux5:~ #10. 配置ntp客户端
编辑/etc/ntp.conf,增加一行server 10.30.1.10,其中10.30.1.105就是时钟服务器,如下linux:/var/log # grep -v \# /etc/ntp.confserver 10.30.1.105
查看ntp服务的状态
linux:/var/log # /etc/init.d/xntpd statusChecking for network time protocol daemon (NTPD): unused设置时区以及时间
/usr/sbin/zic -l PRC/bin/date "+%H:%M:%S - %d-%m-%Y"写回硬件时钟
/sbin/hwclock --hctosys --localtime或者写回硬件时钟: hwclock --systohc在/etc/rc.d/rc5.d创建xntp服务的启动脚本
linux:/etc/rc.d/rc5.d # ln -s ../xntpd S14xntpd查看ntp时间调整纪录linux:/var/log # grep ntp messagesAug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 secAug 14 07:19:51 linux ntpd[2884]: ntpd Wed Jun 30 18:37:03 UTC 2004 (1)Aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usecAug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, 0.0.0.0#123Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, ::#123Aug 14 07:19:51 linux ntpd[2884]: Listening on interface lo, 127.0.0.1#123Aug 14 07:19:51 linux ntpd[2884]: Listening on interface eth0, 10.40.157.66#123Aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040mmscbill:~ # date
Wed May 7 15:53:10 CST 2008这里时区设置没有错. PRC是时区的名称,它对应/usr/share/lib/zoneinfo下的PRC时区文件.CST是Chinese Standard Time的缩写,用在date命令的输出中.它是定义在PRC时区文件中.看一下/usr/share/lib/zoneinfo/src下的asia文件就知道是怎么回事了.修改系统时间(bjchenxu,laixi781211,hutuworm)
date -s “2003-04-14 cst”,cst指时区,时间设定用date -s 18:10修改后执行clock -w 写到CMOShwclock --systohcset the hardware clock to the current system time
zdump -v Europe/Moscow 查看时区一些设置参数