Chinaunix首页 | 论坛 | 博客
  • 博客访问: 321240
  • 博文数量: 36
  • 博客积分: 1641
  • 博客等级: 上尉
  • 技术积分: 575
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-05 09:09
文章分类

全部博文(36)

文章存档

2013年(1)

2012年(4)

2011年(6)

2010年(3)

2009年(11)

2008年(11)

我的朋友

分类: LINUX

2010-12-15 11:37:59

linux系统时间设置

两步

(1)date 042612492005

(2)hwclock –w

第一步的意思是设置时间,设置完了可以用date命令查看对不对...注意是月日时分年

第二步的意思是写入主板的rtc芯片..
=======================================

su -c 'date -s //'

su -c 'date -s ::'

了解Linux的时钟

     由于Linux时钟和Windows时钟从概念的分类、使用到设置都有很大的不同,所以,搞清楚Linux时钟的工作方式与设置操作,不仅对于Linux初学者有着重大意义,而且对于使用Linux服务器的用户来说尤为重要。

Linux时钟的分类

Windows时钟大家可能十分熟悉了,Linux时钟在概念上类似Windows时钟显示当前系统时间,但在时钟分类和设置上却和Windows大相径庭。和Windows不同的是,Linux将时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟两种。系统时间是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的那个主板硬件时钟,这个时钟可以在BIOS“Standard BIOS Feture”项中进行设置。

既然Linux有两个时钟系统,那么大家所使用的Linux默认使用哪种时钟系统呢?会不回出现两种系统时钟冲突的情况呢?这些疑问和担心不无道理。首先,Linux并没有默认哪个时钟系统。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。

Linux启动过程来看,系统时钟和硬件时钟不会发生冲突,但Linux中的所有命令(包括函数)都是采用的系统时钟设置。不仅如此,系统时钟和硬件时钟还可以采用异步方式,见图1所示,即系统时间和硬件时间可以不同。这样做的好处对于普通用户意义不大,但对于Linux网络管理员却有很大的用处。例如,要将一个很大的网络中(跨越若干时区)的服务器同步,假如位于美国纽约的Linux服务器和北京的Linux服务器,其中一台服务器无须改变硬件时钟而只需临时设置一个系统时间,如要将北京服务器上的时间设置为纽约时间,两台服务器完成文件的同步后,再与原来的时钟同步一下即可。这样系统和硬件时钟就提供了更为灵活的操作。

设置Linux的时钟

Linux中,用于时钟查看和设置的命令主要有datehwclockclock。其中,clockhwclock用法相近,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。由于目前绝大多数用户使用x86硬件体系,所以可以视这两个命令为一个命令来学习。

1.   在虚拟终端中使用date命令来查看和设置系统时间

查看系统时钟的操作:

# date

设置系统时钟的操作:

# date 091713272003.30

通用的设置格式:

# date 月日时分年.

2.   使用hwclockclock命令查看和设置硬件时钟

查看硬件时钟的操作:

# hwclock --show

# clock –show

20030917 星期三 132411 -0.482735 seconds

设置硬件时钟的操作:

# hwclock --set --date="09/17/2003 13:26:00"

或者

# clock --set --date="09/17/2003 13:26:00"

通用的设置格式:hwclock/clock --set --date=“// 时:分:秒

3.   同步系统时钟和硬件时钟

Linux系统(笔者使用的是Red Hat 8.0,其它系统没有做过实验)默认重启后,硬件时钟和系统时钟同步。如果不大方便重新启动的话(服务器通常很少重启),使用clockhwclock命令来同步系统时钟和硬件时钟。

硬件时钟与系统时钟同步:

# hwclock –hctosys

或者

# clock –hctosys

上面命令中,--hctosys表示Hardware Clock to SYStem clock

系统时钟和硬件时钟同步:

# hwclock –systohc

或者

# clock –systohc

使用图形化系统设置工具设置时间

对于初学者来,笔者推荐使用图形化的时钟设置工具,如Red Hat 8.0中的日期与时间设置工具,可以在虚拟终端中键“system-config-time”命令,或者选择“K选单/系统设置/日期与时间来启动日期时间设置工具。使用该工具不必考虑系统时间和硬件时间,只需从该对话框中设置日期时间,可同时设置、修改系统时钟和硬件时钟。

Internet同步时钟设置

Windows XP日期与时间设置中有一项与Internet同步的功能,有了这项功能只要上网便可得到十分准确的时间。Red Hat 8.0也提供了这样的功能,在日期与时间设置工具对话框中的下部,有一个启用网络时间协议的选项,将该项选中就可以使用网络时间协议来同步Linux 系统时钟。选中该项后,其下面的服务器下拉列表框就变为可用状态,可从中选择一个时间服务器作为远程时间服务器。然后单击确定按钮,便可连接所设定的时间服务器,并与之同步时间。

Case 1

How to change the clock source in the system?

Article ID: 34407 - Created on: Sep 2, 2009 3:03 AM - Last Modified:  Jun 22, 2010 3:33 AM

Issue

· In some systems, the default clock source  may cause system time delay.

· How to change the clock source in the system?

· How to check which clock source is used on my system.

Environment

· Red Hat Enterprise Linux 4

· Red Hat Enterprise Linux 5

Resolution

The clock source in the system could be changed to make the time more accurate.

Red Hat Enterprise Linux 5

1. Check the available & current clock-source in the system:

# cat /sys/devices/systems/clocksource/clocksource0/available_clocksource

  tsc jiffies pit

# cat /sys/devices/systems/clocksource/clocksource0/current_clocksource

  tsc

Clocksource availability depends on the hardware of the system.

2. Change a value of the clocksource:

# echo "jiffies" > /sys/devices/systems/clocksource/clocksource0/current_clocksource

In order to use a specified clock source after reboot, please append the kernel 'clocksource=' parameter in /boot/grub/grub.conf. The following is an example from x86 system:

 title Red Hat Enterprise Linux (2.6.18-128.el5)

        root (hd0,0)

        kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ clocksource=jiffies

        initrd /initrd-2.6.18-128.el5.img

Case 2

VMWare guest time runs fast and jumps ahead on RHEL4 or RHEL5

Article ID: 35501 - Created on: Dec 29, 2009 4:41 PM - Last Modified:  Aug 16, 2010 10:15 PM

Issue

· Rapid kernel timekeeping issue.

· /usr/bin/top redisplays all of the processes in a continuous fashion, instead of observing the set three second refresh delay.

· select() and sleep() system calls complete faster than they should.

· Time skipping with VMWare.

Environment

· Red Hat Enterprise Linux 4

· Red Hat Enterprise Linux 5

· VMWare guest

Resolution

· Kernel parameters will need to be added to the current kernel in /boot/grub/grub.conf. This parameter is different for different versions of Red Hat Enterprise Linux:

Kernel parameters for 32-bit kernels

Version(s)

Parameter(s)

*Red Hat Enterprise Linux 5.4 (kernel 2.6.18-164)

No additional kernel parameters required.

Refer to vmware kbase about the optional use of divider=10.

Red Hat Enterprise Linux 5.1 to 5.3 (kernel 2.6.18-53 - 2.6.18-128)

clocksource=acpi_pm divider=10

Red Hat Enterprise Linux 5.0 (kernel 2.6.18-8)

clocksource=acpi_pm

Red Hat Enterprise Linux 4.7 to 4.8 (kernel 2.6.9-78 - 2.6.9-89)

clock=pmtmr divider=10

Red Hat Enterprise Linux 4.0 to 4.6 (kernel 2.6.9-5 - 2.6.9-67)

clock=pmtmr

Kernel parameters for 64-bit kernels

Version(s)

Parameter(s)

*Red Hat Enterprise Linux 5.4 (kernel 2.6.18-164)

No additional kernel parameters required.

Refer to vmware kbase about the optional use of divider=10.

Red Hat Enterprise Linux 5.2 to 5.3 (kernel 2.6.18-53 - 2.6.18-128)

notsc divider=10

Red Hat Enterprise Linux 5.1 with  (kernel 2.6.18-8)

notsc divider=10

Red Hat Enterprise Linux 5.1 without  (kernel 2.6.18-8)

notsc

Red Hat Enterprise Linux 5.0 (kernel 2.6.18-8)

no additional kernel parameters required

Red Hat Enterprise Linux 4.7 to 4.8 (kernel 2.6.9-78 - 2.6.9-89)

notsc divider=10

Red Hat Enterprise Linux 4.2 to 4.6 (kernel 2.6.9-5 - 2.6.9-67)

notsc

Note: None of these cases have reported that using divider has solved this problem on Red Hat Enterprise Linux 5.4.

VMware has released the patch for a similar problem on ESX 4.0 Update 2. Check your VMWare support to verify your problem can be applicable for this patch:

An issue in the timer emulation causes timer interrupts to be delivered to the guest operating system at an excessive rate

This issue has been observed after a vMotion migration when a virtual machine has been up for a relatively long time, such as for one hundred days.

This issue is resolved in this release.

Examples for kernel parameters setup

1 Edit /etc/grub.conf file.

o Before:

title Red Hat Enterprise Linux Server-base (2.6.18-92.el5)

        root (hd0,0)

        kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

        initrd /initrd-2.6.18-92.el5.img

o After:

title Red Hat Enterprise Linux Server-base (2.6.18-92.el5)

        root (hd0,0)

        kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet clocksource=acpi_pm divider=10

        initrd /initrd-2.6.18-92.el5.img

2 Reboot the system:

# reboot

NTP parameters

· The /etc/ntp.conf should also be modified to   allow it to accept extremely large offset changes: add or edit the line tinker panic 0.

Examples for NTP parameters setup

Edit /etc/ntp.conf file:
tinker panic 0

restrict 127.0.0.1

restrict default kod nomodify notrap

server 0.vmware.pool.ntp.org

server 1.vmware.pool.ntp.org

server 2.vmware.pool.ntp.org

driftfile /var/lib/ntp/drift

3 Restart the ntpd service:

# service ntpd restart

Comments

For more information refer to:

Root cause

· The clock tick speed in a virtual machine can run at a different frequency to what the kernel expects hardware to be running at. The system expects more ticks than are provided by the hypervisor, and runs roughly ten seconds worth of ticks in one second.

Diagnostic steps

4 Apply the timekeeping best practices documented in

5 Check for timer interrupt delivery falling behind: ntpq -p

6 Check that NTP is running properly in the guest and on the host: ntpq -p

7 Collect time in the guest versus time reported by a reference source: /usr/sbin/ntpdate -q

8 Open a ticket with vmware support:

阅读(6883) | 评论(1) | 转发(0) |
0

上一篇:WHOIS

下一篇:IBM DS3300的配置

给主人留下些什么吧!~~

chinaunix网友2010-12-16 14:35:57

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com