ntp时间同步

转载自: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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值