How to simulate ntp leap second
Environment
- Red Hat Enterprise Linux 6
- ntpd, version 4.2.6p5 (tested with at least that version)
Issue
- How to simulate ntp leap second
Resolution
Disclaimer
The information mentioned below has been provided by Red Hat, but is outside the scope of our posted Service
Level Agreements (https://www.redhat.com/support/service/sla/) and support procedures. The information is provided
as-is and any configuration settings or installed applications made from the information in this article could make
your Operating System unsupported by Red Hat Support Services. The intent of the information mentioned below is to
provide you with information to accomplish your system needs. Use the information mentioned below at your own risk.
- Sample procedure:
ntpserver
ntpserver uses a local reference clock and a leapfile.
/etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
server 127.127.1.0 burst
leapfile /etc/ntp/leap-file
/etc/ntp/leap-file
2272060800 10 # 1 Jan 1972
2287785600 11 # 1 Jul 1972
2303683200 12 # 1 Jan 1973
2335219200 13 # 1 Jan 1974
2366755200 14 # 1 Jan 1975
2398291200 15 # 1 Jan 1976
2429913600 16 # 1 Jan 1977
2461449600 17 # 1 Jan 1978
2492985600 18 # 1 Jan 1979
2524521600 19 # 1 Jan 1980
2571782400 20 # 1 Jul 1981
2603318400 21 # 1 Jul 1982
2634854400 22 # 1 Jul 1983
2698012800 23 # 1 Jul 1985
2776982400 24 # 1 Jan 1988
2840140800 25 # 1 Jan 1990
2871676800 26 # 1 Jan 1991
2918937600 27 # 1 Jul 1992
2950473600 28 # 1 Jul 1993
2982009600 29 # 1 Jul 1994
3029443200 30 # 1 Jan 1996
3076704000 31 # 1 Jul 1997
3124137600 32 # 1 Jan 1999
3345062400 33 # 1 Jan 2006
3439756800 34 # 1 Jan 2009
3550089600 35 # 1 Jul 2012
3644697600 36 # 1 Jul 2015
3692217600 37 # 1 Jan 2017
You can obtain the above leapfile from:
http://support.ntp.org/bin/view/Support/ConfiguringNTP
6.14. Using the NIST Leap Second File
...skip
As of this writing the name of the current NIST leap seconds file is leap-seconds.3629404800:
ftp://time.nist.gov/pub/leap-seconds.3629404800
ftp://tycho.usno.navy.mil/pub/ntp/leap-seconds.3629404800
...skip
Note: When using this procedure you must set the clock far enough back from the leap second for ntp to stabilize the time before the anticipated leap. Here we're using 15minutes, Your mileage may vary. If you are having problems getting this procedure to work increase this difference.
[root@rhel6 ~]# service ntpd stop
[root@rhel6 ~]# date -s "7/1/2015 08:45:00"
[root@rhel6 ~]# service ntpd start
Note: This sample is for timezone: JST(GMT +9).
ntpclient
ntpclient polls time from ntpserver
/etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
server ntpserver iburst
/etc/sysconfig/ntpd
## Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
## enabling the '-x' option can prevent the time from being stepped in a leap event
# OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g -x"
Then restart ntpd on ntpclient
[root@rhel6 ~]# service ntpd stop
[root@rhel6 ~]# ntpdate ntpserver
[root@rhel6 ~]# service ntpd start
Note: Take care the issue: fsck leaves system unusable after changing the time backwards and rebooting
Diagnostic Steps
[root@ntphost2 /]# date
Wed Jul 1 08:55:42 JST 2015
[root@ntphost2 /]# ntptime | grep status
status 0x2011 (PLL,INS,NANO),
[root@ntphost2 /]#
[root@ntphost2 /]#
[root@ntphost2 /]# date
Wed Jul 1 09:01:30 JST 2015
[root@ntphost2 /]# grep "inserting leap secon" /var/log/messages
Jul 1 08:59:59 ntphost2 kernel: Clock: inserting leap second 23:59:60 UTC
- Time can be monitored using this command:
# while sleep 0.1 ; do date -u -Ins ; done
2015-06-30T23:59:58,018654774+0000
2015-06-30T23:59:58,123359023+0000
2015-06-30T23:59:58,229552900+0000
2015-06-30T23:59:58,334737210+0000
2015-06-30T23:59:58,440948455+0000
2015-06-30T23:59:58,609485640+0000
2015-06-30T23:59:58,716430299+0000
2015-06-30T23:59:58,822196217+0000
2015-06-30T23:59:58,928354352+0000
2015-06-30T23:59:59,033388523+0000
2015-06-30T23:59:59,139528389+0000
2015-06-30T23:59:59,245912308+0000
2015-06-30T23:59:59,354560230+0000
2015-06-30T23:59:59,460970930+0000
2015-06-30T23:59:59,578670612+0000
2015-06-30T23:59:59,681923277+0000
2015-06-30T23:59:59,787195607+0000
2015-06-30T23:59:59,892817166+0000
2015-06-30T23:59:59,999465899+0000
2015-06-30T23:59:59,157591495+0000
2015-06-30T23:59:59,264467758+0000
2015-06-30T23:59:59,370565537+0000
2015-06-30T23:59:59,475371544+0000
2015-06-30T23:59:59,581479763+0000
2015-06-30T23:59:59,686079283+0000
2015-06-30T23:59:59,790239515+0000
2015-06-30T23:59:59,896284479+0000
2015-07-01T00:00:00,002516468+0000
2015-07-01T00:00:00,108540140+0000
2015-07-01T00:00:00,215023678+0000
2015-07-01T00:00:00,321339155+0000
2015-07-01T00:00:00,427251596+0000
2015-07-01T00:00:00,532776107+0000
2015-07-01T00:00:00,641236141+0000
2015-07-01T00:00:00,748231556+0000
2015-07-01T00:00:00,853118309+0000
2015-07-01T00:00:00,959433385+0000
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.