Focus On Oracle

Installing, Backup & Recovery, Performance Tuning,
Troubleshooting, Upgrading, Patching

Oracle Engineered System


当前位置: 首页 » 技术文章 » Oracle

How to config NTP on Linux

The Network Time Protocol (NTP) is used to synchronize the time of a computer client or server to another server or reference time source.

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。在一个IDC机房里面,当有很多服务器的时候,配置NTP是非常有必要的,n台服务器可能有n个时间,如果时间不一致会带来很多问题,比如RAC中的节点被驱逐。下面告诉你如何简单配置NTP客户端。


A.在Linux上配置NTP客户端

Prerequisites

please make sure firewall is disabled or allow access to the port 123

1.Check and make sure ntp packages are installed
[root@db1 ~]# rpm -qa|grep ^ntp
ntpdate-4.2.6p5-1.el6.x86_64
ntp-4.2.6p5-1.el6.x86_64
2.Create/edit NTP configuration file (/etc/ntp.conf) and add NTP server(s)
[root@db1 ~]# vi /etc/ntp.conf
server 10.0.0.100 prefer
3.Create/edit configuration file (/etc/sysconfig/ntpd) for NTP daemon (/usr/sbin/ntpd)
-x option must be used for Oracle RAC
[root@db1 ~]#  vi /etc/sysconfig/ntpd
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"

 -p pidfile
               Specify the name and path of the file used to record the ntpd process ID. This is the same operation as the pid-
               file pidfile command.

 -u user[:group]
               Specify a user, and optionally a group, to switch to. This option is only available if the OS  supports  running
               the  server  without  full  root  privileges.  Currently,  this option is supported under NetBSD (configure with
               --enable-clockctl) and Linux (configure with --enable-linuxcaps).
 -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  win-
               dow  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.     
4.Create/edit configuration file (/etc/ntp/step-tickers)
[root@db1 ~]# vi /etc/ntp/step-tickers
# List of servers used for initial synchronization.
server 10.0.0.100 prefer
5.Start NTP
[root@db1 ~]# /sbin/service ntpd start
[root@db1 ~]# /sbin/service ntpd status
6.Check and verify date
date
ntpq -p
watch ntpq -p
ntpstat
启动ntpd服务后,可用通过ntpq -p观察,过几分钟后,时间会跟ntp服务器时间同步
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   19   64    1    3.250  -129036   0.000
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   24   64    1    3.250  -129036   0.000
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   27   64    1    3.250  -129036   0.000
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   30   64    1    3.250  -129036   0.000
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   32   64    1    3.250  -129036   0.000
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   47   64    1    3.250  -129036   0.000
[root@db1 ~]#
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   LOCAL(0)        11 u   51   64    7    0.261  -129034  14.951
[root@db1 ~]# watch ntpq -p
[root@db1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.0.0.100   .STEP.          16 u   61   64    0    0.000    0.000   0.000
[root@db1 ~]#
[root@db1 ~]# ntpstat
unsynchronised
   polling server every 16 s
[root@db1 ~]#

7.如果想在windows上想同步Linux ntp服务器,也可以通过hosts去实现

C:\Windows\System32\drivers\etc\hosts

10.0.0.100 time.windows.com

B.在Windows上配置NTP 客户端以实现网络时钟同步

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vsphere.upgrade.doc%2FGUID-B77341E3-9D7D-48B6-A221-B782C21AF98E.html

在 Windows 服务器上使用注册表编辑器进行配置更改。步骤
1.启用 NTP 模式。
  a 转至注册表设置 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters
  b 将“类型”值设置为 NTP。
2.启用 NTP 客户端。
  a 转至注册表设置 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
  b 将“AnnounceFlags”值设置为 5。
3.输入要与之同步的上游 NTP 服务器。
  a 转至注册表设置 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders。
  b 将 NtpServer 值设置为至少包含三台 NTP 服务器的列表。
 例如,您可以将值设置为 0x1 1.pool.ntp.org、0x1 2.pool.ntp.org、0x1 3.pool.ntp.org。
4.指定 150 分钟的更新时间间隔。
  a 转至注册表设置 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient,
  b 将“SpecialPollInterval”值设置为 900。
5.重新启动 W32time 服务,使更改生效。

C.ORACLE集群时间服务

集群由多台计算机组成,每台计算机都有自身的守时机制。时钟可能在某个服务器上运行地更快或更慢。这种时间差异可能会导致各种问题
1.分析日志定位问题时,由于时间不一致,可能需要花费更多的时间
2.集群节点逐出问题

为避免此问题,大部分系统都配置了时间同步服务(NTP网络时间协议)。如果未配置 NTP,可能会存在以上潜在问题。11gR2 Oracle ClusterWare安装了一种时间同步机制(CTSS集群时间同步服务),引入了CTSS时钟同步模式。CTSS和NTP不能同时运行。假定现在运行在CTSS模式下,如果启用了NTP,CTSS会转化为Observer mode

CTSS: Cluster Time Synchronization Service

# crsctl check CTSS
   CRS-4700: The Cluster Time Synchronization Service is in Observer mode.
   
# crsctl check CTSS    
   CRS-4701: The Cluster Time Synchronization Service is in Active mode.

CRS-4702: Offset from the reference node (in msec): 100  


Leap Seconds

http://nwtime.org/leap-second-resources/


修改时区

# Linux 6

# ll /etc/localtime
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# Linux 7
# ll /etc/localtime
# timedatectl list-timezones |grep Shanghai
# timedatectl set-timezone Asia/Shanghai
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Reference

http://www.ntp.org

http://www.ntp.org.cn

https://www.eecis.udel.edu/~mills/ntp/

http://support.ntp.org/bin/view/Main/ExternalTimeRelatedLinks

http://www.akadia.com/services/ntp_synchronize.html

NTP homepage
ntpd
Network time protocol (version 3) specification
Public NTP Time Servers


关键词:ntp 

相关文章

How to config NTP on Linux
Top