Linux配置NTP服务器

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

4、配置ntpd文件

[root@rac2 grid]# vim /etc/sysconfig/ntpd

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

三、启动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

猜你喜欢

转载自blog.csdn.net/weixin_44377973/article/details/105568053