Chrony服务器实验练习

1.通过自定义时间服务器向指定的客户端主机同步时间,自定义时间服务器主机的时间通过ntp.aliyun.com主机同步时间

实验环境

实验使用两台Linux虚拟机,一台当作服务器主机(192.168.159.132),一台当作客户端主机(192.168.159.134)

服务器主机配置

复制代码
1.设置主机名为server
[root@localhost ~]# hostnamectl set-hostname server #设置新主机名
[root@localhost ~]# reboot   #重启系统

2.保证能接收到客户端的请求
[root@server ~]# systemctl stop firewalld    #关闭防火墙
[root@server ~]# setenforce 0                #关闭selinux


3.确认chrony是否安装及启动(默认安装启动)
[root@server ~]# rpm -qa | grep chrony

[root@server ~]# ps -aux | grep chronyd
复制代码
4.更改配置文件
[root@server ~]# vim /etc/chrony.conf

5.修改参数
#添加阿里的时间同步服务地址
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
pool ntp.aliyun.com  iburst

#设置192.168.159.134/24 可以访问本机进行同步
# Allow NTP client access from local network.
allow 192.168.159.134/24

#设置当前服务器层级
# Serve time even if not synchronized to a time source.
local stratum 10


6.重启服务等待客户端连接
[root@server ~]# systemctl restart chronyd

客户端主机配置

复制代码
1.设置主机名为server
[root@localhost ~]# hostnamectl set-hostname client #设置新主机名
[root@localhost ~]# reboot   #重启系统


2.修改配置文件
[root@client ~]# vim /etc/chrony.conf
#设置要连接的时间服务主机192.168.159.132
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
pool 192.168.159.132  iburst

3.重启加载配置连接服务器
[root@client ~]# systemctl restart chronyd

测试

复制代码
1.客户端主机设置错误时间
[root@client ~]# date 101010102025
Fri Oct 10 10:10:00 AM CST 2025

2.重启加载配置
[root@client ~]# systemctl restart chronyd

3.等待一段时间后查看时间,恢复正确时间
[root@client ~]# date
Tue Oct 21 03:01:50 PM CST 2025
相关推荐
碳基沙盒1 小时前
OpenClaw 多 Agent 配置实战指南
运维
Sinclair2 天前
简单几步,安卓手机秒变服务器,安装 CMS 程序
android·服务器
Rockbean3 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
蝎子莱莱爱打怪3 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
茶杯梦轩3 天前
CompletableFuture 在 项目实战 中 创建异步任务 的核心优势及使用场景
服务器·后端·面试
海天鹰4 天前
【免费】PHP主机=域名+解析+主机
服务器
DianSan_ERP4 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅4 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒4 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
芝士雪豹只抽瑞克五4 天前
Nginx 高性能Web服务器笔记
服务器·nginx