Chrony is a flexible implementation of the Network Time Protocol (NTP). It is used to synchronize the system clock from different NTP servers, reference clocks or via manual input.
It can also be used NTPv4 server to provide time service to other servers in the same network. It is meant to operate flawlessly under different conditions such as intermittent network connection, heavily loaded networks, changing temperatures which may affect the clock of ordinary computers.
Chrony comes with two programs:
chronyc – command line interface for chrony
chronyd – daemon that can be started at boot time
Install Chrony:
# yum -y install chrony
Check the status of chronyd:
# systemctl status chronyd [On SystemD]
# /etc/init.d/chronyd status [On Init]
Enable chrony daemon upon boot:
# systemctl enable chrony [On SystemD]
# chkconfig –add chronyd [On Init]
Configure Firewalld:
$ firewall-cmd –add-service=ntp –permanent
$ firewall-cmd –reload
Check Chrony Synchronization:
# chronyc tracking
If you want to step the system clock immediately and ignoring any adjustments currently being in progress, you can use the following command:
# chronyc makestep
Configure Chrony:
The configuration file of chrony is located at /etc/chrony.conf or /etc/chrony/chrony.conf.
附录:
1.手工设置时间
timedatectl set-time “YYYY-MM-DD HH:MM:SS”
2.手工设置时区
timedatectl set-timezone Asia/Shanghai
3.以系统时间为基准,修改硬件时间
hwclock –systohc
hwclock -w
以硬件时间为基准,修改系统时间
hwclock –hctosys
hwclock -s
设置硬件时间(硬件时间默认为UTC,将硬件时钟调整为与本地时钟一致)
timedatectl set-local-rtc 1
hwclock –systohc –localtime //与上面命令效果一致
启用NTP时间同步
timedatectl set-ntp yes
4.内网时间服务器配置示例(假设内网时间服务器IP为10.28.204.66):
内网时间服务器配置文件注释以下内容:
#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 10.28.204.66 iburst
这样一台内网时间服务器已经配置完毕。
同样在客户端配置文件中注释掉其他server,并在客户端配置文件中添加以下内容:
server 10.28.204.66 iburst
至此已经完成时间同步的配置。如有多台机器,操作类似。
需要注意的是,配置完/etc/chrony.conf后,需重启chrony服务。
5.chronyc常用命令
查看 ntp_servers 状态:chronyc sources -v
查看 ntp_sync 状态:chronyc sourcestats -v
查看 ntp_servers 是否在线:chronyc activity -v
查看 ntp 详细信息:chronyc tracking -v