-
安装ntpdate工具
yum -y install ntp ntpdate
这一步偶尔会出错(比如我重装了centos的python,导致这步出错),报错内容类似以下:
root@iZ23t4pnz63Z ~]# yum update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyuncs.com * epel: mirrors.aliyuncs.com * extras: mirrors.aliyuncs.com * updates: mirrors.aliyuncs.com Traceback (most recent call last): File "/usr/libexec/urlgrabber-ext-down", line 22, in <module> from urlgrabber.grabber import \ ImportError: No module named urlgrabber.grabber Traceback (most recent call last): File "/usr/libexec/urlgrabber-ext-down", line 22, in <module> from urlgrabber.grabber import \ ImportError: No module named urlgrabber.grabber
-
解决办法
vi /usr/libexec/urlgrabber-ext-down
把头部的python改成和/usr/bin/yum中一样的,可以先cat /usr/bin/yum查看,我的是#!/usr/bin/python_old
cat /usr/bin/yum #!/usr/bin/python_old
-
设置系统时间与网络时间同步
ntpdate cn.pool.ntp.org
-
将系统时间写入硬件时间
hwclock --systohc
-
查看系统时间
timedatectl #得到 Local time: 四 2017-09-21 13:54:09 CST Universal time: 四 2017-09-21 05:54:09 UTC RTC time: 四 2017-09-21 13:54:09 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: yes DST active: n/a
如果没有执行步骤3,则Local time与RTC time显示的值可能不一样
-
如果上一步时区不是上海,可以更改时区
此处鸣谢:https://blog.csdn.net/superlover_/article/details/83655646
timedatectl list-timezones
:列出所有时区timedatectl set-local-rtc 1
将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间timedatectl set-timezone Asia/Shanghai
设置系统时区为上海
centos 7 时间与网络同步及更改时区
最新推荐文章于 2024-05-12 13:21:24 发布