1. 首页
  2. IT资讯

[20191230]注意设置SYNC_HWCLOCK=yes.txt

[20191230]注意设置SYNC_HWCLOCK=yes.txt

–//前一段时间的测试,链接:http://blog.itpub.net/267265/viewspace-2670625/=>[20191226]dmesg与时间戳.txt
–//实际上当时机器出现异常,重启后硬件时钟与system时钟不一致造成的情况:
–//主要几个原因造成这个问题,这个问题主要出现在Oracle Linux Server release 5.9,我检查6.X以上版本SYNC_HWCLOCK=yes:

1.环境:
# cat /etc/issue
Oracle Linux Server release 5.9

# cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -x"

# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=no

# Additional options for ntpdate
NTPDATE_OPTIONS=""

–//缺省安装后加入-x参数的同时,必须修改SYNC_HWCLOCK=yes.不然启动ntpd服务不会修改硬件时间.

2.几点说明:
-x 参数:

-x  Normally, the time is slewed if the offset is less than the step threshold, which is 128 ms by default, and stepped
    if above the threshold. This option sets the threshold to 600 s, which is well within the accuracy window to set the
    clock  manually. Note: Since the slew rate of typical Unix kernels is limited to 0.5 ms/s, each second of adjustment
    requires an amortization interval of 2000 s. Thus, an adjustment as much as 600 s will take almost 14 days to
    complete. This option can be used with the -g and -q options. See the tinker command for other options. Note: The
    kernel time discipline is disabled with this option.

通常情况下,如果偏移量小于步长阈值(默认情况下为128ms),则旋转时间并步进。如果超过阈值。此选项将阈值设置为600s,该阈值在
精确度窗口内,以设置手动计时。注:由于典型Unix内核的旋转速率仅限于0.5ms/s,因此每秒调整一次因此,多达600秒的调整需要将近
14天的时间才能完成。完成。此选项可与-g和-q选项一起使用。有关其他选项,请参见修补程序命令。注:用此选项禁用内核时间。

–//首先必须设置-x参数,不然即使设置SYNC_HWCLOCK=yes,也不会调用hwclock同步硬件时间.

# vi /etc/init.d/ntpd

readconf() {
    dostep=''
    dropstr=''
    OPTIND=1
    while getopts ":46aAbc:dD:f:gi:k:l:LnN:p:P:qr:s:t:u:v:V:x" args $OPTIONS;
    do
      case "$args" in
        x) dostep=yes;;
        ~~~~~~~~~~~~~~~
        c) ntpconf="$OPTARG";;
        u) dropstr="-U $(echo $OPTARG | sed 's/:.*//')";;
      esac
    done

    [ -x /sbin/ntpd -a -f $ntpconf ] || exit 0

    tickers=''
    if [ -s "$ntpstep" ]; then
        tickers=$(sed 's/#.*//' $ntpstep)
        echo "$tickers" | grep -qi '[a-z0-9]' && dostep=yes || tickers=''
    fi
    if [ -n "$dostep" -a -z "$tickers" ]; then
        # -x option is used, but step-tickers doesn't exist or contain
        # anything useful, use servers from ntp.conf instead
        tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf |
            fgrep -v 127.127.1.0)
    fi
}

–//注意看下划线,仅仅设置-x参数,dostep=yes.

start() {
    # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 1

    readconf;
#   set -x
#   echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    if [ -n "$dostep" ]; then
   ~~~~~~~~~~~~~~~~~~~~~~~~~~        
        echo -n $"$prog: Synchronizing with time server: "
        /sbin/ntpdate $dropstr -s -b $NTPDATE_OPTIONS $tickers &>/dev/null
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        if [ $RETVAL -eq 0 ]; then
            [ "$SYNC_HWCLOCK" = "yes" ] && sync_hwclock
        else
            OPTIONS="$OPTIONS -g"
        fi
    else
        # -g can replace the grep for time servers
        # as it permits ntpd to violate its 1000s limit once.
        OPTIONS="$OPTIONS -g"
    fi
        # Start daemons.
        echo -n $"Starting $prog: "
        daemon ntpd $OPTIONS
    RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
    return $RETVAL
}

–//注意看下划线,-n 表示the length of STRING is nonzero,如果$dostep有值才会调用里面的命令.才会执行ntpdate以及同步硬件时
–//间.

–//另外注意一个问题有一些系统有防火墙,必须修改/etc/ntp.conf,必须加入本地时间服务器.一般这个时间服务器与上游的时间服务器
–//同步,不然也不会同步硬件时间.这样启动看到的情况是这样:

# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
ntpd: Synchronising with time server:                      [  OK  ]
Syncing hardware clock to system time                      [  OK  ]
Starting ntpd:                                             [  OK  ]

–//为什么要这样设置,实际上即使你启动ntpd同步硬件时间,随着运行时间增加,硬件时钟与系统时钟会差距越来越远:
#  hwclock -r ;date
Mon 30 Dec 2019 04:23:38 PM CST  -0.897579 seconds
Mon Dec 30 15:57:24 CST 2019

–//也许养成隔段时间重启ntpd服务很有必要.
–//两者相差30分钟.而且硬件时钟超前系统时钟.设想如果系统异常重启,不会同步系统时钟到硬件时钟(参考/etc/init.d/halt脚本).
–//这样如果你没有设置SYNC_HWCLOCK=yes,这样时间差距太大,ntpd会无法启动.oracle rac系统时间也不正确.注意看前面-x参数说明.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2671283/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:深沉的少年,转转请注明出处:http://www.cxybcw.com/182816.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code