suse linux 10系统时间跑偏问题解析

来源:互联网 发布:海思麒麟 知乎 编辑:程序博客网 时间:2024/05/17 09:28

在suse linux 10上部署WAS应用和搭建ORACLE RAC集群时,经常会碰到因系统时间不准而导致WAS不正常和RAC节点宕机问题,解决系统时间跑偏的问题,大家会很自然的想到NTP和CRONTAB。下面针对这个问题来具体说说suse linux 10系统时间跑偏问题。

一、现象
        经过观察,你会发现在安装系统后第一次设置正确系统时间后,没设置定时校准的情况下,它的系统时间一小时会偏差有4-6分钟左右,一天下来通常会偏差50分钟左右。这在生产环境下肯定会出问题。

二、NTP设置
        如果你能直接连接到外部时间源或一个内部的时间源服务器,你可以在其中的一台suse linux 10上设置NTP服务器,让其他suse linux 10定时同步这台NTP服务器就行。
#vi  /etc/ntp.conf

## Radio and modem clocks by convention have addresses in the 
## form 127.127.t.u, where t is the clock type and u is a unit 
## number in the range 0-3. 
##
## Most of these clocks require support in the form of a 
## serial port or special bus peripheral. The particular  
## device is normally specified by adding a soft link 
## /dev/device-u to the particular hardware device involved, 
## where u correspond to the unit number above. 
## 
## Generic DCF77 clock on serial port (Conrad DCF77)
## Address:     127.127.8.u
## Serial Port: /dev/refclock-u
##  
## (create soft link /dev/refclock-0 to the particular ttyS?)
##
# server 127.127.8.0 mode 5 prefer

##
## Undisciplined Local Clock. This is a fake driver intended for backup
## and when no outside source of synchronized time is available.
##
server 127.127.1.0              # local clock (LCL)
fudge  127.127.1.0 stratum 10   # LCL is unsynchronized
##
## Outside source of synchronized time
##
## server xx.xx.xx.xx           # IP address of server

server  10.7.0.81     #手工设置时间源服务器

##
## Miscellaneous stuff
##

driftfile /var/lib/ntp/drift/ntp.drift # path for drift file

logfile   /var/log/ntp          # alternate log file
# logconfig =syncstatus + sysevents
# logconfig =all

# statsdir /tmp/                # directory for statistics files
# filegen peerstats  file peerstats  type day enable
# filegen loopstats  file loopstats  type day enable
# filegen clockstats file clockstats type day enable

#
# Authentication stuff
#
# keys /etc/ntp.keys            # path for keys file
# trustedkey 1 2 3 4 5 6 14 15  # define trusted keys
# requestkey 15                 # key (7) for accessing server variables
# controlkey 15                 # key (6) for accessing server variables

然后你可以使用:

#hwclock  -r                #查看硬件时间

#hwclock --systohc     #把硬件时间赋给系统时间

在其他suse linux 10上设置CRONTAB定时校准
#crontab -e   加上下面一句
*/15 * * * *  /usr/sbin/ntpdate 10.7.0.81;/sbin/hwclock -w
意思是每15分钟同步一次并将时间写入硬件时钟

三、直接设置CRONTAB

     如果有时间源服务器且suse linux 10服务器都能正常PING通时间源服务器,你可以在所有的suse linux 10服务器上直接设置CRONTAB来定时同步时间源服务器。
具体方法同上
#crontab -e   加上下面一句
*/15 * * * *  /usr/sbin/ntpdate 10.7.0.81;/sbin/hwclock -w
意思是每15分钟同步一次并将时间写入硬件时钟
如果你想看到每天具体的输出结果,可以加一个输出日志ntprizhi.txt来分析
*/15 * * * *  /usr/sbin/ntpdate 10.7.0.81>>/tmp/ntprizhi.txt;/sbin/hwclock -w
当然也可以查看系统下的日志,如果你是root用户,直接查看
/var/mail/root就可以了,形式如下
Subject: Cron <root@tyzssq> /usr/sbin/ntpdate 10.7.0.81;/sbin/hwclock -w
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20121126103001.076FF2090E@tyzssq.site>
Date: Tue, 26 Nov 2012 18:30:01 +0800 (CST)

26 Nov 18:29:59 ntpdate[6917]: step time server 10.7.0.81 offset -1.361968 sec

四、系统内核参数修改
        即便设置了每15分钟同步,有时你发现仍然会出现时间跑偏的问题。这时你可以缩短同步的时间,比如设置成每5分钟甚至每1分钟同步一次,但如果需要同步的suse linux 10服务器
比较多的情况下对时间源就会造成压力。这时你需要考虑让suse linux 10服务器自己把时间跑准,那么方法是修改系统内核参数。
我们先看一下修改前的系统内核参数
# cat /boot/grub/menu.lst
# Modified by YaST2. Last modification on Thu Nov  3 08:00:47 UTC 2011
default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE Linux Enterprise Server 10 SP2
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.16.60-0.21-smp root=/dev/hda2    resume=/dev/hda1 splash=silent showopts hda=noprobe hdb=noprobe 
    initrd /boot/initrd-2.6.16.60-0.21-smp

###Don't change this comment - YaST2 identifier: Original name: floppy###
title Floppy
    rootnoverify (hd0)
    chainloader (fd0)+1

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- SUSE Linux Enterprise Server 10 SP2
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.16.60-0.21-smp root=/dev/hda2 showopts ide=nodma apm=off acpi=off noresume edd=off 3 hda=noprobe hdb=noprobe 
    initrd /boot/initrd-2.6.16.60-0.21-smp
You have new mail in /var/mail/root

修改后的文件,注意红色语句部分

# cat /boot/grub/menu.lst
# Modified by YaST2. Last modification on Thu Nov  3 08:00:47 UTC 2011
default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE Linux Enterprise Server 10 SP2
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.16.60-0.21-smp root=/dev/hda2    resume=/dev/hda1 splash=silent showopts hda=noprobe hdb=noprobe clock=pmtmr
    initrd /boot/initrd-2.6.16.60-0.21-smp

###Don't change this comment - YaST2 identifier: Original name: floppy###
title Floppy
    rootnoverify (hd0)
    chainloader (fd0)+1

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- SUSE Linux Enterprise Server 10 SP2
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.16.60-0.21-smp root=/dev/hda2 showopts ide=nodma apm=off acpi=off noresume edd=off 3 hda=noprobe hdb=noprobe clock=pmtmr
    initrd /boot/initrd-2.6.16.60-0.21-smp
You have new mail in /var/mail/root
 

注意红色的语句其后面加上了蓝色部分clock=pmtmr

当该参数设置后,可以在合适时间重启服务器让参数生效,经过测试和观察,系统时间不再跑偏.
 

时间加快的原理探究:
相对于SLES9的2.4内核,SLES10中的2.6内核改变了时钟嘀嗒的中断数量,从100个/每秒到1000个/每秒。在双处理器的2.6内核,甚至可以达到每秒3000个。由于LINUX内核产生中断的能力差别,一些时间嘀嗒可能会被忽略。这会导致许多额外的嘀嗒来校正被忽略的嘀嗒,从而带来时间加快的副作用。当然LINUX本身会有算法来校正和解决系统中的这个问题。

原创粉丝点击