多余的话都写在教程的后面,直接进入下面的操作命令。下面所有的操作都必须使用root账户来操作。切记。
- #1. 查看当前时间
- date
-
- #2. 添加wlnmp源
- rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
-
- #3. 安装ntp服务
- yum install wntp
-
- #4. 时间同步
- ntpdate ntp1.aliyun.com
-
- #5. 打开防火墙NTP服务端口,如果没有打开防火墙,就不用操作这一步
- #添加NTP服务端口
- firewall-cmd --add-service=ntp --permanent
- #重新加载NTP服务配置
- firewall-cmd --reload
-
- #6. 下载安装chrony
- yum install -y chrony
-
- #7. 启动chrony服务
- systemctl restart chronyd
-
- #8. 查看chronyd服务状态
- systemctl status chronyd
-
- #9.在查看一下同步时间后的时间
- date
------------------------------------------------华丽的分割线-------------------------------------------
经过上面的操作,相信大家的时间一定都设置好了吧。开始唠嗑……
Chrony是网络时间协议 (NTP) 的通用实现。它可以将系统时钟与 NTP 服务器、参考时钟(例如 GPS 接收器)同步,以及使用手表和键盘手动输入。它还可以作为 NTPv4 (RFC 5905) 服务器和对等点运行,为网络中的其他计算机提供时间服务。
它旨在在各种条件下都表现良好,包括间歇性网络连接、严重拥塞的网络、不断变化的温度(普通计算机时钟对温度敏感)以及不能连续运行或在虚拟机上运行的系统。
通过 Internet 同步的两台机器之间的典型精度在几毫秒内;在 LAN 上,精度通常以几十微秒为单位。使用硬件时间戳或硬件参考时钟,亚微秒精度可能是可能的。
中包含两个程序chrony,chronyd一个是可以在引导时启动的守护程序,另一个chronyc是一个命令行界面程序,可用于监控chronyd的性能并在运行时更改各种操作参数。
上面的翻译来自GOOGLE。原文如下
- chrony is a versatile implementation of the Network Time Protocol (NTP).
- It can synchronise the system clock with NTP servers, reference clocks (e.g. GPS receiver),
- and manual input using wristwatch and keyboard.
- It can also operate as an NTPv4 (RFC 5905) server and peer to provide a time service to other computers in the network.
-
- It is designed to perform well in a wide range of conditions,
- including intermittent network connections,
- heavily congested networks,
- changing temperatures (ordinary computer clocks are sensitive to temperature),
- and systems that do not run continuosly,
- or run on a virtual machine.
-
- Typical accuracy between two machines synchronised over the Internet is within a few milliseconds;
- on a LAN,
- accuracy is typically in tens of microseconds.
- With hardware timestamping, or a hardware reference clock,
- sub-microsecond accuracy may be possible.
-
- Two programs are included in chrony,
- chronyd is a daemon that can be started at boot time and chronyc is a command-line interface program which can be used to monitor chronyd’s performance and to change various operating parameters whilst it is running.
chrony的优势是更快的同步,从而最大程度减少了时间和频率误差,对于并非全天 24 小时运行的虚拟计算机而言非常有用,能够更好地响应时钟频率的快速变化,对于具备不稳定时钟的虚拟机或导致时钟频率发生变化的节能技术而言非常有用。
在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响
在应对临时非对称延迟时(例如,在大规模下载造成链接饱和时)提供了更好的稳定性
无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟。
chrony官网
https://chrony.tuxfamily.orgchrony官方文档
https://chrony.tuxfamily.org/documentation.html
开放 323/udp,123/udp端口,或直接关闭防火墙。
- #把866/tcp换成自己的323/udp
- firewall-cmd --zone=public --add-port=866/tcp --permanent
-
- #把866/tcp换成自己的123/udp
- firewall-cmd --zone=public --add-port=866/tcp --permanent
-
- # 重新加载
- firewall-cmd --reload
-
-
-
- #删除866端口,如果不需要删除该端口就不需要操作
- firewall-cmd --zone=public --remove-port=866/tcp --permanent
输入chronyc回车就进入交互式模式,进入交互式模式可以使用help命令查看帮助列表。常用指令说明如下:
| accheck | 检查NTP访问是否对特定主机可用 |
| activity | 该命令会显示有多少NTP源在线/离线 |
| add server | 手动添加一台新的NTP服务器。 |
| clients | 在客户端报告已访问到服务器 |
| delete | 手动移除NTP服务器或对等服务器 |
| settime | 手动设置守护进程时间 |
| tracking | 显示系统时间信息 |
| 说明:chronyd和chronyc的详细使用方法可以使用命令# man chronyd和# man chronyc查看 | |
| systemctl start chronyd.service | 启动 |
| systemctl status chronyd.service | 查看当前状态 |
| systemctl restart chronyd.service | 重启 |
| systemctl stop chronyd.service | 停止 |
| systemctl enable chronyd.service | 设置开机启动 |