Linux配置NTP服務器
NTP(Network Time Protocol)服務器用於局域網內服務器時間同步,可以保證局域網所有的服務器與時間服務器的時間保持一致,應用於對時間實時性要求高的、必須統一時間的事件。
一、安裝NTP服務
1、查看是否安裝NTP
[root@wgx network-scripts]# rpm -qa | grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
2、安裝NTP
[root@oracle etc]# yum install ntp ntpdate -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
.......
Installed:
ntp.x86_64 0:4.2.6p5-15.el6.centos ntpdate.x86_64 0:4.2.6p5-15.el6.centos
Complete!
二、配置NTP服務
1、所有節點都需要進行的配置
配置當前節點IP地址、集羣所在網段的網關、子網掩碼,結果如下:
[root@oracle etc]# vim ntp.conf
# 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 192.168.1.202 nomodify notrap nopeer noquery #當前節點IP地址
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
restrict 192.168.1.1 mask 255.255.255.0 nomodify notrap #集羣所在網段的網關,子網掩碼
2、主節點的配置
在server部分添加以下內容:
[root@wgx etc]# vim ntp.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
server 127.127.1.0 # local clock
# 當服務器無法連接到公用的時間服務器時,以局域網的時間服務器爲客戶端提供時間同步服務
Fudge 127.127.1.0 stratum 10
3、其他節點的配置
在server部分添加如下語句,將server指向主節點:
[root@oracle etc]# vim ntp.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
server 192.168.1.201
Fudge 192.168.1.201 stratum 10
三、啓動NTP服務
配置完成後,啓動NTP服務,查看NTP狀態。命令如下:
[root@wgx etc]# service ntpd start
正在啓動 ntpd: [確定]
[root@wgx etc]# ntpstat
synchronised to local net at stratum 6
time correct to within 7948 ms
polling server every 64 s
四、設置開機啓動NTP服務
chkconfig ntpd on
五、查看NTP服務狀態
[root@rac1 ~]# ntpstat
synchronised to local net at stratum 6
time correct to within 948 ms
polling server every 64 s
[root@rac2 etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*rac1.example.co LOCAL(0) 6 u - 64 37 0.386 -0.023 0.018