Linux系统之部署Chrony时间服务器

举报
江湖有缘 发表于 2022/10/25 19:50:50 2022/10/25
【摘要】 一、检查本地服务器系统版本[root@docker ~]# cat /etc/os-release NAME="CentOS Linux"VERSION="7 (Core)"ID="centos"ID_LIKE="rhel fedora"VERSION_ID="7"PRETTY_NAME="CentOS Linux 7 (Core)"ANSI_COLOR="0;31"CPE_NAME="c...

一、检查本地服务器系统版本


[root@docker ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7

二、配置yum源

1.配置yum仓库

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

2.检查yum仓库状态

[root@docker ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                                         repo name                                                          status
!base/7/x86_64                                                  CentOS-7 - Base - mirrors.aliyun.com                               enabled: 10,072
centosplus/7/x86_64                                             CentOS-7 - Plus - mirrors.aliyun.com                               disabled
contrib/7/x86_64                                                CentOS-7 - Contrib - mirrors.aliyun.com                            disabled
docker-ce-nightly/7/x86_64                                      Docker CE Nightly - x86_64                                         disabled
docker-ce-nightly-debuginfo/7/x86_64                            Docker CE Nightly - Debuginfo x86_64                               disabled
docker-ce-nightly-source/7                                      Docker CE Nightly - Sources                                        disabled
!docker-ce-stable/7/x86_64                                      Docker CE Stable - x86_64                                          enabled:    169
docker-ce-stable-debuginfo/7/x86_64                             Docker CE Stable - Debuginfo x86_64                                disabled
docker-ce-stable-source/7                                       Docker CE Stable - Sources                                         disabled
docker-ce-test/7/x86_64                                         Docker CE Test - x86_64                                            disabled
docker-ce-test-debuginfo/7/x86_64                               Docker CE Test - Debuginfo x86_64                                  disabled
docker-ce-test-source/7                                         Docker CE Test - Sources                                           disabled
!extras/7/x86_64                                                CentOS-7 - Extras - mirrors.aliyun.com                             enabled:    515
!updates/7/x86_64                                               CentOS-7 - Updates - mirrors.aliyun.com                            enabled:  4,30

三、安装chrony软件

1.yum安装安装chrony

[root@docker ~]# yum -y install chrony
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                       | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                           | 3.5 kB  00:00:00     
extras                                                                                                                     | 2.9 kB  00:00:00     
updates                                                                                                                    | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package chrony.x86_64 0:3.4-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================
 Package                           Arch                              Version                                Repository                       Size
==================================================================================================================================================
Installing:
 chrony                            x86_64                            3.4-1.el7                              base                            251 k

Transaction Summary
==================================================================================================================================================
Install  1 Package

Total download size: 251 k
Installed size: 491 k
Downloading packages:
chrony-3.4-1.el7.x86_64.rpm                                                                                                | 251 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : chrony-3.4-1.el7.x86_64                                                                                                        1/1 
  Verifying  : chrony-3.4-1.el7.x86_64                                                                                                        1/1 

Installed:
  chrony.x86_64 0:3.4-1.el7                                                                                                                       

Complete!



2.设置chrony服务开机自启

systemctl enable --now chronyd

3.查看chronyd服务状态

[root@docker ~]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2022-10-25 19:26:15 CST; 7min ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 42246 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 42240 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 42242 (chronyd)
    Tasks: 1
   Memory: 364.0K
   CGroup: /system.slice/chronyd.service
           └─42242 /usr/sbin/chronyd

Oct 25 19:26:15 docker systemd[1]: Starting NTP client/server...
Oct 25 19:26:15 docker chronyd[42242]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +... +DEBUG)
Oct 25 19:26:15 docker systemd[1]: Started NTP client/server.
Oct 25 19:26:21 docker chronyd[42242]: Selected source 108.59.2.24
Oct 25 19:26:21 docker chronyd[42242]: System clock wrong by 23.871267 seconds, adjustment started
Oct 25 19:26:45 docker chronyd[42242]: System clock was stepped by 23.871267 seconds
Oct 25 19:26:48 docker chronyd[42242]: Source 5.79.108.34 replaced with 162.159.200.123
Oct 25 19:27:51 docker chronyd[42242]: Selected source 116.203.151.74
Hint: Some lines were ellipsized, use -l to show in full.

四、修改/etc/chrony.conf文件

1.编辑/etc/chrony.conf

[root@docker ~]# grep -iEv "^#|^ " /etc/chrony.conf 
server ntp.aliyun.com iburst

driftfile /var/lib/chrony/drift

makestep 1.0 3

rtcsync

logdir /var/log/chrony

2.重启chrony服务

systemctl restart chronyd

五、查看服务器时间同步情况

1.查看时间同步源状态

[root@docker ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6    77    31   +762us[+1132us] +/-   26ms


2.查看系统时间参数信息

[root@docker ~]# chronyc tracking
Reference ID    : CB6B0658 (203.107.6.88)
Stratum         : 3
Ref time (UTC)  : Tue Oct 25 11:41:21 2022
System time     : 0.000142983 seconds slow of NTP time
Last offset     : +0.000602810 seconds
RMS offset      : 0.002404696 seconds
Frequency       : 6.137 ppm fast
Residual freq   : -12.949 ppm
Skew            : 6.782 ppm
Root delay      : 0.047122456 seconds
Root dispersion : 0.003335197 seconds
Update interval : 64.8 seconds
Leap status     : Normal


六、测试时间同步

1.修改服务器错误时间

[root@docker ~]# date
Tue Oct 25 19:43:01 CST 2022
[root@docker ~]# date 110322092022.11
Thu Nov  3 22:09:11 CST 2022

2.手动同步

[root@docker ~]# chronyc -a makestep
200 OK

3.查看系统时间

[root@docker ~]# chronyc -a makestep
200 OK
[root@docker ~]# date
Tue Oct 25 19:49:00 CST 2022

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。