Linux configuration NTP server

Linux configuration NTP server

The NTP (Network Time Protocol) server is used to synchronize the time of the servers in the local area network, which can ensure that the time of all servers in the local area network is consistent with the time server. It is applied to events that require high real-time time and must be unified.

One, install NTP service

1. Check if NTP is installed

[root@wgx network-scripts]# rpm -qa | grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch

2. Install 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!

Two, configure NTP service

1. Configuration required for all nodes

Configure the current node IP address, the gateway of the network segment where the cluster is located, and the subnet mask. The results are as follows:

[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. Configuration of the master node

Add the following in the server section:

[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. Configuration of other nodes

Add the following statement in the server section to point the server to the master node:

[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. Configure ntpd file

[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"

Three, start the NTP service

After the configuration is complete, start the NTP service and check the NTP status. The command is as follows:

[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

Fourth, set the boot to start the NTP service

chkconfig ntpd on

Guess you like

Origin blog.csdn.net/weixin_44377973/article/details/105568053