美国vps服务器的Linux公共服务组件之时间同步chrony
云服务器
美国vps服务器的Linux公共服务组件之时间同步chrony
2026-01-21 09:49
美国vps服务器的Linux公共服务组件之时间同步chrony:
一、简介
定义:chrony是网络时间协议(NTP)的通用实现。
chrony包含两个target="_blank">程序:chronyd是一个可以在启动时启动的守护程序。chronyc是一个命令行界面程序,用于监视chronyd的性能并在运行时更改各种操作参数。
时间概念:
UTC(UniversalTimeCoordinated):世界标准时间,属于世界统一世界
GMT(GreenwichMeanTime):英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,因此不做区分)
CST(ChinaStandardTime):中国标准时间,CMT+8=UTC+8=CST
DST(DaylightSavingTime):夏令时指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光的使用。
二、安装配置
测试环境:
IP备注
120.10.10.10Chrony服务端
120.10.10.11Chrony客户端
服务端和客户端均安装软件包:
yum-yinstallchrony
systemctlenablechronyd
systemctlstartchronyd
服务端配置,注意两个改动:
#使用pool.ntp.org项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以。
#建议添加ping较低的公网服务器地址
#改动1
#Usepublicserversfromthepool.ntp.orgproject.
#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).
serverntp.aliyun.comiburst
servertime.asia.apple.comiburst
servertime.windows.comiburst
servercn.pool.ntp.orgiburst
#根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
#Recordtherateatwhichthesystemclockgains/lossestime.
driftfile/var/lib/chrony/drift
#如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。
#Allowthesystemclocktobesteppedinthefirstthreeupdatesifitsoffsetislargerthan1second.
makestep1.03
#启用实时时钟(RTC)的内核同步。
#Enablekernelsynchronizationofthereal-timeclock(RTC).
rtcsync
#通过使用hwtimestamp指令启用硬件时间戳
#Enablehardwaretimestampingonallinterfacesthatsupportit.
#hwtimestamp*
#Increasetheminimumnumberofselectablesourcesrequiredtoadjustthesystemclock.
#minsources2
#改动2
#指定NTP客户端地址或网段,以允许或拒绝连接到扮演时钟服务器的机器
#AllowNTPclientaccessfromlocalnetwork.
allow120.10.10.0/24
#Servetimeevenifnotsynchronizedtoatimesource.
#localstratum10
#指定包含NTP身份验证密钥的文件。
#SpecifyfilecontainingkeysforNTPauthentication.
#keyfile/etc/chrony.keys
#指定日志文件的目录。
#Specifydirectoryforlogfiles.
logdir/var/log/chrony
#选择日志文件要记录的信息。
#Selectwhichinformationislogged.
#logmeasurementsstatisticstracking
服务端开启同步功能:
systemctlenablechronyd
systemctlrestartchronyd
#查看时间同步状态
timedatectlstatus
#开启网络时间同步
timedatectlset-ntptrue
客户端配置,也注意两个改动:
#使用pool.ntp.org项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以。
#Usepublicserversfromthepool.ntp.orgproject.
#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).
#改动1
server120.10.10.10iburst
#根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
#Recordtherateatwhichthesystemclockgains/lossestime.
driftfile/var/lib/chrony/drift
#如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。
#Allowthesystemclocktobesteppedinthefirstthreeupdatesifitsoffsetislargerthan1second.
makestep1.03
#启用实时时钟(RTC)的内核同步。
#Enablekernelsynchronizationofthereal-timeclock(RTC).
rtcsync
#通过使用hwtimestamp指令启用硬件时间戳
#Enablehardwaretimestampingonallinterfacesthatsupportit.
#hwtimestamp*
#Increasetheminimumnumberofselectablesourcesrequiredtoadjustthesystemclock.
#minsources2
#指定NTP客户端地址,以允许或拒绝连接到扮演时钟服务器的机器
#AllowNTPclientaccessfromlocalnetwork.
#改动2
allow120.10.10.10
#Servetimeevenifnotsynchronizedtoatimesource.
#localstratum10
#指定包含NTP身份验证密钥的文件。
#SpecifyfilecontainingkeysforNTPauthentication.
#keyfile/etc/chrony.keys
#指定日志文件的目录。
#Specifydirectoryforlogfiles.
logdir/var/log/chrony
#选择日志文件要记录的信息。
#Selectwhichinformationislogged.
#logmeasurementsstatisticstracking
三、使用
修改时区或日期时间(首先配置):
#查看日期时间、时区及NTP状态
timedatectl
#查看时区列表
timedatectllist-timezones
timedatectllist-timezones|grep-E"Asia/S.*"
#修改时区
timedatectlset-timezoneAsia/Shanghai
#修改日期时间(可以只修改其中一个)
timedatectlset-time"2019-09-1915:50:20"
#开启NTP,true表示开启
timedatectlset-ntptrue/flase
#查看日期时间、时区及NTP状态
timedatectl
#查看时区列表
timedatectllist-timezones
timedatectllist-timezones|grep-E"Asia/S.*"
#修改时区
timedatectlset-timezoneAsia/Shanghai
#修改日期时间(可以只修改其中一个)
timedatectlset-time"2019-09-1915:50:20"
#开启NTP,true表示开启
timedatectlset-ntptrue/flase
Chronyc命令:
#查看ntp_servers
chronycsources-v
#查看ntp_servers状态
chronycsourcestats-v
#查看ntp_servers是否在线
chronycactivity-v
#查看ntp详细信息
chronyctracking-v
购买使用一诺网络美国VPS,可以极大降低初创企业、中小企业以及个人开发者等用户群体的整体IT使用成本,无需亲自搭建基础设施、简化了运维和管理的日常工作量,使用户能够更专注于自身的业务发展和创新。美国VPS低至49元/月,购买链接:https://www.enuoidc.com/vpszq.html?typeid=3