NTP配置時間同步

ora_erin發表於2013-12-20

Oracle RAC兩個節點,配置NTP使得兩個節點時間同步


1)節點1和節點2都啟動NTP服務,節點2(客戶端)向節點1(伺服器端)同步


如果測試用,可修改節點2的時間不同於節點1的時間,date -s "2013-12-20 12:00:00"


節點1(伺服器端)的配置:
[root@node1 ~]# vi /etc/ntp.conf

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.

#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.

restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
restrict 192.168.3.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 key 42         # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 key 42             # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 key 42  # manycast client

# 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
fudge   127.127.1.0 stratum 10

# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8


重啟NTP服務:/etc/init.d/ntpd restart


[root@node1 ~]# ntpstat  --節點1與自己同步成功
synchronised to local net at stratum 11
   time correct to within 10 ms
   polling server every 128 s

[root@node1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 dns2.synet.edu. 202.118.1.46     2 u  196   64  370   27.720  5867038 509323.
 ntp.glnet.edu.c 202.112.10.60    2 u    1   64  335   28.515  5815055 1289295
*LOCAL(0)        .LOCL.          10 l    6   64  377    0.000    0.000   0.001
--LOCAL就表示與本機同步,前面帶*的表示已經同步成功

節點2(客戶端)配置:
[root@node2 log]# vi /etc/ntp.conf

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.

restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 key 42         # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 key 42             # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 key 42  # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  192.168.3.201 prefer    # local clock

# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8


----192.168.3.201是節點1的IP地址


重啟NTP服務:/etc/init.d/ntpd restart


[root@node2 log]# ntpstat  ---提示不能同步
unsynchronised
  time server re-starting
   polling server every 64 s


cd /var/log
[root@node2 log]# tail -n 100 messages
Dec 20 12:03:16 node2 ntpd[25815]: ntpd exiting on signal 15
Dec 20 12:03:16 node2 ntpd[27096]: ntpd 4.2.2p1@1.1570-o Tue Dec  8 20:30:29 UTC 2009 (1)
Dec 20 12:03:16 node2 ntpd[27097]: precision = 9.000 usec
Dec 20 12:03:16 node2 ntpd[27097]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Dec 20 12:03:16 node2 ntpd[27097]: Listening on interface lo, 127.0.0.1#123 Enabled
Dec 20 12:03:16 node2 ntpd[27097]: Listening on interface eth0, 192.168.3.202#123 Enabled
Dec 20 12:03:16 node2 ntpd[27097]: Listening on interface eth1, 10.10.17.202#123 Enabled
Dec 20 12:03:16 node2 ntpd[27097]: kernel time sync status 0040
Dec 20 12:03:16 node2 ntpd[27097]: getaddrinfo: "::1" invalid host address, ignored
Dec 20 12:03:16 node2 ntpd[27097]: frequency initialized 0.000 PPM from /var/lib/ntp/drift
----感覺NTP服務應該沒問題的


[root@node2 log]# ntpq -p    
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 node1           .INIT.          16 u   56   64    0    0.000    0.000   0.000

[root@node2 log]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 node1           LOCAL(0)        11 u   43   64    1    0.135  -509970   0.008
[root@node2 log]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 node1           LOCAL(0)        11 u   14   64    3    0.135  -509970 3146.38
[root@node2 log]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 node1           LOCAL(0)        11 u    2   64    7    0.130  -510033 4976.97
[root@node2 log]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 node1           LOCAL(0)        11 u   58   64   37    0.024  -510094 8518.21


--reach值一直在增加,這應該是正在同步的節奏吧,但是我等了好幾個小時,還沒見他同步完成,
[oracle@node1 ~]$ date; ssh node2 date
Thu Dec 19 22:58:23 CST 2013
Thu Dec 19 22:42:51 CST 2013
節點1和節點2的時間一直沒同步,網上搜了很多,也無解,這個問題先放放,採用第2種方法使兩個節點時間同步


2)節點1啟動NTP服務,節點2關閉NTP服務,節點2(客戶端)使用ntpdate和crond向節點1(伺服器端)同步


節點1的配置同第1種方法


節點2需要關閉NTP服務,否則報錯如下:
ntpdate[3556]: the NTP socket is in use, exiting


[root@node2 ~]# vi /etc/crontab
加這樣一句話:
*/2 * * * * root ntpdate 192.168.3.201
--表示每隔2分鐘在節點2以root身份執行ntpdate 192.168.3.201


重啟crond服務:
[root@node2 ~]# /etc/init.d/crond restart
Stopping crond: [  OK  ]
Starting crond: [  OK  ]


觀察cron的日誌:
[root@node2 log]# pwd
/var/log
[root@node2 log]# tail -f cron
Dec 18 11:40:01 node2 crond[5209]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 18 14:50:42 node2 crond[6762]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 18 15:00:01 node2 crond[7274]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 18 15:01:01 node2 crond[7658]: (root) CMD (run-parts /etc/cron.hourly)
Dec 18 15:10:01 node2 crond[20182]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 19 04:35:10 node2 crond[2637]: (CRON) STARTUP (V5.0)
Dec 19 04:40:01 node2 crond[9143]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 19 04:46:00 node2 crond[2637]: (CRON) STARTUP (V5.0)
Dec 19 04:50:01 node2 crond[7985]: (root) CMD (/usr/lib/sa/sa1 1 1)
Dec 19 04:56:41 node2 crond[18037]: (CRON) STARTUP (V5.0)
Dec 19 04:58:01 node2 crond[27769]: (root) CMD (ntpdate 192.168.3.201)
Dec 19 03:32:51 node2 crond[32458]: (root) CMD (ntpdate 192.168.3.201)
Dec 19 03:34:01 node2 crond[18884]: (root) CMD (ntpdate 192.168.3.201)


兩個節點之間已實現同步


參考資料:http://blog.163.com/william_djj@126/blog/static/35166501201301432546711/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26524307/viewspace-1063924/,如需轉載,請註明出處,否則將追究法律責任。

相關文章