使用chrony配置NTP服务器
  

尕强 30506人觉得有帮助

{{ttag.title}}
使用chrony配置NTP服务器

此方式只适用于centos/redhat 7-8
1,先停用ntpd,如果有的话
systemctl stop ntpdsystemctl disable ntpd
2,安装chrony程序
yum install -y chrony
3,启动chrony程序
systemctl start chronydsystemctl enable chronyd
4,放开NTP服务端口
firewall-cmd --permanent --add-service=ntpfirewall-cmd --reload
关闭防火墙
systemctl stop firewalld
systemctl enable firewalld
5,编辑下面的脚本
# vi ntp.sh
保存下面内容,并执行
#/bin/bash# Write NTP configuration# Backup chrony.confcurrentTimestamp=`date +%y-%m-%d-%H:%M:%S`chrony_conf="/etc/chrony.conf"chrony_conf_backup=$chrony_conf.chronyconfig.$currentTimestampif [ -f "$chrony_conf" ]; then echo backup $chrony_conf to $chrony_conf_backup cp $chrony_conf $chrony_conf_backupfi# Write chrony.confecho "# Welcome to the chrony configuration file. See chrony.conf(5) for more# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).server ntp1.aliyun.com iburstserver ntp2.aliyun.com iburstserver ntp3.aliyun.com iburstserver ntp4.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/16allow# Serve time even if not synchronized to a time source.local stratum 10# Specify file containing keys for NTP authentication.keyfile /etc/chrony.keys# Get TAI-UTC offset and leap seconds from the system tz database.leapsectz right/UTC# Specify directory for log files.logdir /var/log/chrony# Select which information is logged.log measurements statistics tracking" > $chrony_confecho "Restart chronyd deamon."systemctl restart chronydtimedatectl set-ntp yes
执行
# sh ntp.sh

测试:(客户端链接时间服务器)

一、Windows10客户端:
打开控制面板-日期与时间-Internet时间-更改时间,输入时间服务器地址-立即更新
Windows11:
打开控制面板-时间和语言-日期和时间-附加时钟--Internet时间-更改时间,输入时间服务器地址-立即更新
更改时间服务器时间:
先断网
禁用时间服务器同步时间
timedatectl set-ntp false  或    timedatectl set-ntp no
然后修改时间:
timedatectl set-time 9:46:30
重启chronyd
systemctl restart chronyd
启用时间服务器同步时间
timedatectl set-ntp true  或    timedatectl set-ntp yes
查看时间
timedatectl    或    date

在Windows上更新时间,发现时间与时间服务器时间同步
查看多少个客户端连接了时间服务器:
# chronyc
# clients
# exit 退出

二、Linux客户端配置
安装本地yum
1,先停用ntpd,如果有的话
systemctl stop ntpdsystemctl disable ntpd
2,安装chrony程序
yum install -y chrony
3,启动chrony程序
systemctl start chronydsystemctl enable chronyd
4、chrony.conf 修改两处
# 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 192.168.2.188 iburst# Allow NTP client access from local network.allow 192.168.2.188

5、开启同步systemctl restart chronyd# 查看时间同步状态timedatectl status# 开启网络时间同步timedatectl set-ntp true

6、查看多少个客户端连接了时间服务器:
# chronyc
# clients
# exit 退出


7、卸载chrony
# yum remove chrony*

打赏鼓励作者,期待更多好文!

打赏
28人已打赏

尕强 发表于 2024-4-7 08:46
  
1111111111111
dhf 发表于 2023-9-7 10:32
  
每日打卡学习,感谢分享,学习了!!!
dhf 发表于 2023-9-6 10:34
  
每日打卡学习,感谢分享,学习了!!!
伊利丹·怒风 发表于 2023-7-11 16:11
  
systemctl restart chronyd
启用时间服务器同步时间
思贤 发表于 2023-7-10 10:25
  
每天学习一点点,每天进步一点点。
S_李军 发表于 2023-7-10 10:19
  
逐句地看完这个帖子以后,我的心久久不能平静,震撼啊!为什么会有如此好的帖子!我纵横社区多年,自以为再也不会有任何帖子能打动我,没想到今天看到了如此精妙绝伦的这样一篇帖子。
秦冰 发表于 2023-7-10 10:19
  
逐句地看完这个帖子以后,我的心久久不能平静,震撼啊!为什么会有如此好的帖子!我纵横社区多年,自以为再也不会有任何帖子能打动我,没想到今天看到了如此精妙绝伦的这样一篇帖子。
sangfor_双 发表于 2023-7-10 10:19
  
逐句地看完这个帖子以后,我的心久久不能平静,震撼啊!为什么会有如此好的帖子!我纵横社区多年,自以为再也不会有任何帖子能打动我,没想到今天看到了如此精妙绝伦的这样一篇帖子。
sangfor_s 发表于 2023-7-10 10:19
  
逐句地看完这个帖子以后,我的心久久不能平静,震撼啊!为什么会有如此好的帖子!我纵横社区多年,自以为再也不会有任何帖子能打动我,没想到今天看到了如此精妙绝伦的这样一篇帖子。
发表新帖
热门标签
全部标签>
每日一问
每周精选
技术笔记
技术盲盒
2024年技术争霸赛
产品连连看
2023技术争霸赛专题
干货满满
技术咨询
标准化排查
新版本体验
通用技术
技术晨报
功能体验
秒懂零信任
自助服务平台操作指引
文档捉虫活动
信服课堂视频
GIF动图学习
答题自测
每日一记
运维工具
SDP百科
技术圆桌
排障笔记本
专家问答
在线直播
安装部署配置
测试报告
解决方案
项目案例
存储
技术争霸赛
卧龙计划
畅聊IT
MVP
网络基础知识
升级
安全攻防
上网策略
日志审计
问题分析处理
流量管理
云计算知识
用户认证
原创分享
sangfor周刊
VPN 对接
SANGFOR资讯
专家分享
技术顾问
信服故事
功能咨询
终端接入
授权
设备维护
资源访问
地址转换
虚拟机
迁移
加速技术
产品预警公告
玩转零信任
信服圈儿
S豆商城资讯
「智能机器人」
追光者计划
深信服技术支持平台
社区帮助指南
答题榜单公布
纪元平台
华北区拉练
天逸直播
以战代练
山东区技术晨报
齐鲁TV
华北区交付直播
北京区每日一练

本版版主

12
185
6

发帖

粉丝

关注

本版达人

LoveTec...

本周分享达人

新手24116...

本周提问达人