惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
H
Help Net Security
V
Visual Studio Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
The Cloudflare Blog
Martin Fowler
Martin Fowler
D
Docker
腾讯CDC
F
Fortinet All Blogs
雷峰网
雷峰网
GbyAI
GbyAI
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - 叶小钗

博客园 - XiaoK

centOS端口映射命令 java gc日志的基本知识 定时清除linux内存buff/cache缓存 将libstdc++.so.6升级到libstdc++.so.6.0.29 修改rabbitMQ3.8默认端口号 一个项目用的linunx后台服务配置 nginx负载均衡的配置 linux配置nginx开机启动 vi编辑器常用命令 解决setroubleshootd进程占用内存、cpu高 centOS linux常用操作命令 Internet Explorer 安全区域注册表项说明 获取WPF控件句柄的方法 当远程访问mysql时,mysql会解析域名,会导致访问速度很慢 创建鼠标指针图标 [转]c#消息处理 c#实现渐变色 OpenFileDialog组件会更改应用程序默认目录问题 winForm中将控件背景设为透明色
在centOS linux上使用chrony搭建NTP时间同步服务器
XiaoK · 2023-03-09 · via 博客园 - XiaoK
  • centOS6.0以后,系统就自带chrony服务,只用修改配置,然后启动服务就可以了
  • chrony可以同时作为服务器和客户端。在配置文件中注释allow  0.0.0.0/0配置,就只能作为客户端,打开这个配置即可作为服务器也可以作为客户端
  • 打开/etc/chrony.conf文件,输入以下配置
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# NTP服务器地址。server可以配置多个,这里配了阿里云、腾讯云、一个私人ntp和中科院的ntp服务器,实际测试中中科院的ntp服务器最慢 server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst server time1.cloud.tencent.com iburst
server time3.cloud.tencent.com iburst
server cn.ntp.org.cn iburst server ntp.ntsc.ac.cn 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.
# 允许连接到此服务器同步时间的网段;0.0.0.0/0表示允许所有网段;注释该配置此服务就只能作为NTP客户端,不能作为服务器 allow
0.0.0.0/0 # Serve time even if not synchronized to a time source.
# 当配置的server不可用时,是否使用本地时间同步到客户端 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

#和服务器相差多少秒内才执行同步。本地时间和服务器时间相差的秒数超过这个时间就不会同步。默认是3秒
maxdistance 94608000.0

  • 保存配置文件。注意配置文件中的红色文字
  • 依次执行以下命令
timedatectl set-timezone 'Asia/Shanghai'   #将时区改为亚洲上海
timedatectl set-ntp true # 启动ntp服务

systemctl restart chronyd  #启动chronyd  服务
systemctl enable chronyd  #将chronyd  设置为开机启动

chronyc -a makestep  #手动同步一次时间
  • 如果开启了防火墙,需要执行以下命令。因NTP使用123/UDP端口协议,所以允许NTP服务即可
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
  • chrony常用命令
chronyc sources -v   #查看时间同步状态 ntp_servers

chronyc sourcestats -v  #查看 ntp_servers 状态

chronyc tracking -v  #查看 ntp 详细信息

chronyc -a makestep #强制同步下系统时钟

posted @ 2023-03-09 17:20  XiaoK  阅读(777)  评论()    收藏  举报