[新手村] ntpdate centos7.9同步时间

网上的教程都是安装ntpd server,但局域网已经有server,总不能100个虚拟机装100个ntp server吧。

用ntpdate就可以同步时间,仅有client, 不需要server.
先看看当前时间,差了四个小时

[kingsy@k8s-master01-k ~]$ date
Thu Jun  1 07:11:59 EDT 2023

安装ntpdate

[root@k8s-master01-k kingsy]# yum install ntpdate -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.njupt.edu.cn
 * extras: mirrors.njupt.edu.cn
 * updates: mirrors.jlu.edu.cn
base                                                                                                                                                                                   | 3.6 kB  00:00:00
extras                                                                                                                                                                                 | 2.9 kB  00:00:00
updates                                                                                                                                                                                | 2.9 kB  00:00:00
(1/4): updates/7/x86_64/primary_db                                                                                                                                                     |  21 MB  00:00:02
(2/4): base/7/x86_64/group_gz                                                                                                                                                          | 153 kB  00:00:02
(3/4): base/7/x86_64/primary_db                                                                                                                                                        | 6.1 MB  00:00:03
(4/4): extras/7/x86_64/primary_db                                                                                                                                                      | 249 kB  00:00:06
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================
 Package                                       Arch                                         Version                                                          Repository                                  Size
==============================================================================================================================================================================================================
Installing:
 ntpdate                                       x86_64                                       4.2.6p5-29.el7.centos.2                                          base                                        87 k

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

Total download size: 87 k
Installed size: 121 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm is not installed
ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm                                                                                                                                             |  87 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) "
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                                                                                                                                                     1/1
  Verifying  : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                                                                                                                                                     1/1

Installed:
  ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2

Complete!

安装完成,试试同步时间

[root@k8s-master01-k kingsy]# ntpdate 10.8.108.233
31 May 23:17:32 ntpdate[9981]: step time server 10.8.108.233 offset -28799.124964 sec
[root@k8s-master01-k kingsy]# date
Wed May 31 23:20:03 EDT 2023

变成晚上11点了,差了12个小时,一看时区是EDT,改成中国的时区吧

[root@k8s-master01-k kingsy]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite ‘/etc/localtime’? y
[root@k8s-master01-k kingsy]# date
Thu Jun  1 11:20:22 CST 2023

嗯,这回对了,就这样吧,完。

你可能感兴趣的:(linux新手村,linux,centos,bash)