Centos7部署时间同步服务chrony

Chrony是一个开源的自由软件,像CentOS7或基于RHEL 7操作系统,已经是默认服务,默认配置文件在 /etc/chrony.conf 它能保持系统时间与时间服务器(NTP)同步,让时间始终保持同步。相对于NTP时间同步软件,占据很大优势。其用法也很简单。

Chrony有两个核心组件,分别是:chronyd:是守护进程,主要用于调整内核中运行的系统时间和时间服务器同步。它确定计算机增减时间的比率,并对此进行调整补偿。chronyc:提供一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作。

 

安装chrony

所有机器关闭防火墙和selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config & setenforce 0&& systemctl disable firewalld.service && systemctl stop firewalld.service

所有机器都安装chrony,centos7最小化安装时默认已经装了此服务,所以次步骤可省略

rpm -qa |grep chrony

# systemctl status chronyd

# yum install chrony -y

开启并自启动

# systemctl restart chronyd

# systemctl enable chronyd

 

修改配置文件

服务器端

# vim /etc/chrony.conf

# 使用pool.ntp.org项目中的公共服务器。以server开,理论上你想添加多少时间服务器都可以。

# 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都注释掉 并且开启local stratum 10设置

如果需要同步其他机器的时间则配置 server 并且注释掉 local stratum 10设置

 

# Serve time even if not synchronized to a time source.

这个功能开启后,本机不去同步别人的时间到本机

#local stratum 10

local stratum 10

 

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。

# Record the rate at which the system clock gains/losses time.

driftfile /var/lib/chrony/drift

 

# chronyd根据需求减慢或加速时间调整,

# 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。

# 该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟。

# 只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。

# Allow the system clock to be stepped in the first three updates

# if its offset is larger than 1 second.

makestep 1.0 3

 

# 将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。

# Enable kernel synchronization of the real-time clock (RTC).

rtcsync

 

# 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器

# Allow NTP client access from local network.

#allow 192.168.0.0/16

allow 10.0.0.0/16

allow 192.168.1.0/24

 

# 指定日志文件的目录。

# Specify directory for log files.

logdir /var/log/chrony

 

客户端

注释掉其他server,并在客户端添加以下即可:

server 10.0.0.100 iburst

其他配置默认就好

local stratum 10 设置一定要关掉

 

重启服务端和客户端

# systemctl restart chronyd

常用命令

查看时间同步源:

# chronyc sources -v

手动同步时间

chronyc makestep

查看时间同步源状态:

# chronyc sourcestats -v^

* 或者^-是正常状态 ^?是有问题的,可能是防火墙或者服务配置有问题

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值