ntp时间同步工具chrony

Chrony 应用本身已经有几年了,是 络时间协议的 (NTP) 的另一种实现。一直以来众多发行版里标配的都是ntpd对时服务,自rhel7/centos7 起,Chrony做为了发行版里的标配服务,不过老的ntpd服务依旧在rhel7/centos7里可以找到 。Chrony可以同时做为ntp服务的客户端和服务端。默认安装完后有两个程序chronyd和chronyc 。chronyd是一个在系统后台运行的守护进程,chronyc是用来监控chronyd性能和配置其参数程序。

chrony时间同步软件,目前centos7系统默认自带。若没安装使用yum -y install chrony进行下载。

配置

ntp服务-客户端配置

1.修改配置文件/etc/chrony.conf

配置服务器ip地址(server servier_ip iburst #选择要同步的服务器)

局域 或者公 北京时间提供的服务器为:ntpip1,ntpip2

tce环境开出的虚机,默认已经设置好ntp。

# 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 ntpip1 iburst

# Ignore stratum in source selection.

stratumweight 0

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

driftfile /var/lib/chrony/drift

# Enable kernel RTC synchronization.

rtcsync

# In first three updates step the system clock instead of slew

# if the adjustment is larger than 10 seconds.

makestep 10 3

# Allow NTP client access from local network.

#allow 192.168/16

# Listen for commands only on localhost.

bindcmdaddress 127.0.0.1

bindcmdaddress ::1

# Serve time even if not synchronized to any NTP server.

#local stratum 10

keyfile /etc/chrony.keys

# Specify the key used as password for chronyc.

commandkey 1

# Generate command key if missing.

generatecommandkey

# Disable logging of client accesses.

noclientlog

# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.

logchange 0.5

logdir /var/log/chrony

#log measurements statistics tracking

2.重启服务 systemctl restart chronyd

3.client查看同步结果

chronyc sources -v #-V 亦可 ,结果为^*则同步完成

ntp服务-服务端搭建配置

不建议使用虚机作为ntp服务器

建议ntp服务器使用物理机或者使用专用ntp服务器

  1. server修改主配置文件, vim /etc/chrony.conf,修改allow配置

# 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

# 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 127.0.0.1 #允许谁去同步我的时间

# 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

2.systemctl restart chronyd #重启服务

systemctl stop firewalld #防火墙没关的话需要关闭

三、NTP 服务器列表

Windows系统上自带的两个:time.windows.com 和 time.nist.gov
MacOS上自带的两个:time.apple.com 和 time.asia.apple.com
NTP授时快速域名服务:cn.ntp.org.cn

1、阿里云授时服务器

#NTP服务器 ntp.aliyun.com

2、国外授时服务器

#NTP服务器

time.google.com

time.apple.com

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年4月9日
下一篇 2021年4月9日

相关推荐