您的位置:首页 > 其它

时间问题

2015-08-20 10:10 309 查看
转载:http://blog.sina.com.cn/s/blog_67b7d7e40101gk5v.html

首先确认使用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 TZ

to 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/Shanghai

linux5:~ #

3) 复制相应的时区文件,替换系统默认时区

linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

linux5:~ #

4) 将当前时间写入BIOS永久生效(避免重启后失效)

linux5:~ # hwclock

Tue Jan 29 18:22:59 2008 -0.565688 seconds

linux5:~ #

10. 配置ntp客户端

编辑/etc/ntp.conf,增加一行server 10.30.1.10,其中10.30.1.105就是时钟服务器,如下

linux:/var/log # grep -v \# /etc/ntp.conf

server 10.30.1.105

查看ntp服务的状态

linux:/var/log # /etc/init.d/xntpd status

Checking 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 messages

Aug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 sec

Aug 14 07:19:51 linux ntpd[2884]: ntpd 4.2.0a@1.1213-r Wed Jun 30 18:37:03 UTC 2004 (1)

Aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usec

Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, 0.0.0.0#123

Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, ::#123

Aug 14 07:19:51 linux ntpd[2884]: Listening on interface lo, 127.0.0.1#123

Aug 14 07:19:51 linux ntpd[2884]: Listening on interface eth0, 10.40.157.66#123

Aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040

mmscbill:~ # 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 写到CMOS

hwclock --systohc

set the hardware clock to the current system time
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: