19
2021
06
16:35:38

CentOS 7利用chrony搭建NTP时钟服务器(替代ntp)



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

CentOS 7利用chrony搭建NTP时钟服务器(替代ntp)


chrony介绍:

在Windows或Linux服务器的运行时,在内网系统中时间需要相对的精确才能保证服务不出差错,例如AD、DNS、LVS、HA等,都需要后台的服务器之间保持时间的同步。CentOS7中默认安装的是chrony,而CentOS6中使用的是NTP。本篇文章介绍的是在CentOS7环境下搭建chrony时钟同步服务器。

chrony相较于ntp服务,chrony服务有如下几点优势:

1、更快的同步只需要数分钟而非数小时时间,从而最大程度的减少时间和频率误差,这对于并非全天运行的台式计算机或系统而言非常有用;
2、能够更好的响应时间频率的快速变化,这对于具备不稳定时钟的虚拟机或导致时钟频率反生变化的节能技术而言非常有用;
3、在初始同步后,它并不会停止时钟,以防对需要系统时间保持单调的程序造成影响;
4、在应对临时非对称延迟时,(例如,大规模下载造成链接饱和时)提供了更好的稳定性;
5、无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟。

安装过程:

1、关闭系统防火墙和开机启动防火墙:

systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

2、关闭系统SELinux服务:
手动关闭:
编辑 vi /etc/selinux/config 将SELINUX修改为disabled,如下图:

命令关闭:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

以上2种方法均为永久关闭SELinux方法,都需要重启后生效。
重启系统:reboot
查看SELinux状态:sestatus

3、进行安装chrony服务:(系统默认安装,如若未安装,请执行以下命令安装chrony)

yum install chrony -y

4、启动chrony并设置开机自动启动:

systemctl enable chronyd.service
systemctl restart chronyd.service
systemctl status chronyd.service

5、设置时区:

timedatectl set-timezone Asia/Shanghai

6、编辑chrony配置文件,设置上游时钟服务器地址:
vi /etc/chrony.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 iburstserver  ntp.aliyun.com iburst #此处为修改的阿里的授时服务器。# Record the rate at which the system clock gains/losses time.driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates# if its offset is larger than 1 second.makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).rtcsync# Enable hardware timestamping on all interfaces that support it.#hwtimestamp *# Increase the minimum number of selectable sources required to adjust# the system clock.#minsources 2# Allow NTP client access from local network.#allow 192.168.0.0/16 #指定一台主机、子网,或者网络允许或拒绝连接到时钟服务器的机器。# Serve time even if not synchronized to a time source.#local stratum 10# Specify file containing keys for NTP authentication.#keyfile /etc/chrony.keys# Specify directory for log files.logdir /var/log/chrony# Select which information is logged.#log measurements statistics tracking

配置完成后重启服务:

systemctl restart chronyd.service

查看时间同步源:

chronyc sources -v

查看时间同步源状态:

chronyc sourcestats -v

校准时间服务器:

chronyc tracking

至此,我们需求的一台内网时间服务器已经配置完毕。


本文链接:https://hqyman.cn/post/1753.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: