centos集群中各节点如何实现时间同步?

选择集群中一台节点为ntp时间服务器,其他节点以此机器的时间为基准来进行同步。

 

本节以两台服务器为例

192.168.1.1

192.168.1.2

本节以192.168.1.1作为ntp服务器,192.168.1.2作为客户端来同步服务器的时间, 在多节点的集群中道理是一样的。

 

1 集群中所有节点安装ntp时间同步工具

yum -y install ntp ntpdate #安装ntpdate时间同步工具

 

2  192.168.1.1时间同步服务器设置

修改/etc/ntp.conf文件,添加server设置127.127.1.0为其自身

vim /etc/ntp.conf

在public servers节下添加

server     127.127.1.0   #设置自己作为时间同步服务器

在access节下新增加一个restrict段为可以接受服务的网段,本例为192.168.1.0

restrict 192.168.1.0

如下标黄加粗部分所示:

# 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 ::1
restrict 192.168.1.0 #设置可接受服务的网段

# 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 127.127.1.0  #设置自己作为时间同步服务器
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst

 

启动时间同步服务器

systemctl start ntpd     #启动时间同步程序
systemctl enable ntpd  #允许时间同步程序开机启动

在其它节点上运行如下命令同步时间

ntpdate -u 192.168.1.1
posted @ 2020-05-13 11:02  <Snooker>  阅读(1029)  评论(0编辑  收藏  举报