centos7时间同步命令(centos7配置时间同步服务器)

背景

最近要做阿里云迁移 IDC 机房,整理下 Linux 运维基线,简单记录,以备后用~

安装

#默认已经安装$yuminstall-ychrony

配置文件

$cat/etc/chrony.conf#Usepublicserversfromthepool.ntp.orgproject.#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).#国家服务器server0.cn.pool.ntp.orgserver1.cn.pool.ntp.orgserver2.cn.pool.ntp.orgserver3.cn.pool.ntp.org#阿里serverntp.aliyun.com#腾讯servertime1.cloud.tencent.comservertime2.cloud.tencent.comservertime3.cloud.tencent.comservertime4.cloud.tencent.comservertime5.cloud.tencent.com#苹果servertime.asia.apple.com#微软servertime.windows.com#其他servercn.ntp.org.cn#Recordtherateatwhichthesystemclockgains/lossestime.driftfile/var/lib/chrony/drift#Allowthesystemclocktobesteppedinthefirstthreeupdates#ifitsoffsetislargerthan1second.makestep1.03#Enablekernelsynchronizationofthereal-timeclock(RTC).rtcsync#Enablehardwaretimestampingonallinterfacesthatsupportit.#hwtimestamp*#Increasetheminimumnumberofselectablesourcesrequiredtoadjust#thesystemclock.#minsources2#AllowNTPclientaccessfromlocalnetwork.#allow192.168.0.0/16#Servetimeevenifnotsynchronizedtoatimesource.#localstratum10#SpecifyfilecontainingkeysforNTPauthentication.#keyfile/etc/chrony.keys#Specifydirectoryforlogfiles.logdir/var/log/chrony#Selectwhichinformationislogged.#logmeasurementsstatisticstracking

启动服务及时区设置

#启动服务$systemctlstartchronyd#开机启动$systemctlenablechronyd#查看当前状态$systemctlstatuschronyd#查看亚洲时区$timedatectllist-timezones|grepAsia#设置时区$timedatectlset-timezoneAsia/Shanghai

验证服务

#查看现有的时间服务器$chronycsources-v#查看时间服务器状态$chronycsourcestats-v#显示时钟同步相关参数$chronyctracking#查看当前时区及时间$timedatectl

手动同步时间

#使用ntpdate同步时间$ntpdatentp.aliyun.com#chronyd未启动时,如下命令同步时间$chronyd-q\'serverpool.ntp.orgiburst\'#chronyd启动时,使用如下命令同步时间$chronyc-a\'burst4/4\'&&sleep10&&chronyc-amakestep

手动设置时间

#date设置时间$date-s\'2021-06-0319:00:00\'#关闭ntp同步后,才可以使用timedatectl进行时间设置$timedatectlset-ntpfalse#设置日期和时间$timedatectlset-time\'2021-06-0319:00:00\'#设置日期$timedatectlset-time\'2021-06-03\'#设置时间$timedatectlset-time\'19:00:00\'#设置完成后,再开启$timedatectlset-ntptrue
(0)
小多多的头像小多多创始人

相关推荐

发表回复

登录后才能评论