Chinaunix首页 | 论坛 | 博客
  • 博客访问: 144027
  • 博文数量: 31
  • 博客积分: 2075
  • 博客等级: 大尉
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-29 10:06
文章分类

全部博文(31)

文章存档

2017年(3)

2014年(1)

2013年(1)

2011年(9)

2010年(14)

2009年(3)

我的朋友

分类: LINUX

2010-12-21 17:54:57

(1)date 042612492005 

            '月 日 时 分 年’

(2)hwclock –w

     写入主板的rtc芯片

su -c 'date -s //'

su -c 'date -s ::'

 

       Linux时钟的分类

分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟2种,系统时间是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的那个主板硬件时钟,这个时钟可以在BIOS“Standard BIOS Feture”项中进行设置。

       Linux并没有默认哪个时钟系统。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。

       Linux中的所有命令(包括函数)都是采用的系统时钟设置。不仅如此,系统时钟和硬件时钟还可以采用异步方式,即系统时间和硬件时间可以不同。

这样做的好处对于普通用户意义不大,但对于Linux网络管理员却有很大的用处。例如,要将一个很大的网络中(跨越若干时区)的服务器同步,假如位于美国纽约的Linux服务器和北京的Linux服务器,其中一台服务器无须改变硬件时钟而只需临时设置一个系统时间,如要将北京服务器上的时间设置为纽约时间,两台服务器完成文件的同步后,再与原来的时钟同步一下即可。这样系统和硬件时钟就提供了更为灵活的操作。

    设置Linux的时钟

Linux中,用于时钟查看和设置的命令主要有datehwclockclock。其中,clockhwclock用法相近,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。

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系统默认重启后,硬件时钟和系统时钟同步。如果不方便重启,使用clockhwclock命令来同步系统时钟和硬件时钟。

[A、] 硬件时钟与系统时钟同步:

# hwclock –hctosys

或者

# clock –hctosys

--hctosys表示Hardware Clock to SYStem clock

[B、] 系统时钟和硬件时钟同步:

# hwclock –systohc

或者

# clock –systohc

# hwclock –systohc

或者

# clock –systohc

 
【Related Cases】

How to change the clock source in the system?

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

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:

阅读(1433) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~