美文网首页
VirtualBox安装最小化CentOS的时间同步

VirtualBox安装最小化CentOS的时间同步

作者: AydanLinux | 来源:发表于2020-08-16 06:16 被阅读0次

问题描述

VirtualBox 虚拟机里面最小化安装了 CentOS 6.10,安装时选择的时区是上海,并取消勾选 UTC,但是安装重启之后显示系统时间是格林威治时间,即零时区的时间,由此虚拟机和宿主机之间差了八个小时。

Linux 的时间分为系统时间和硬件时间。
系统时间:System Clock
硬件时间:Real Time Clock, RTC

解决

1、禁用UTC

# 编辑时间配置文件,添加 UTC=false 和 UTC=false 选项
vim /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false

2、设置系统时区为上海时区

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

3、将系统时间和时间服务器上的时间同步

yum install ntp -y    # 安装 ntp server
ntpdate cn.pool.ntp.org    # 同步时间

4、将系统时间写入硬件时间,下面两个命令用一个就行

hwclock -w
hwclock --systohc

5、还可以写一个定时任务来同步时间

crontab -e
00 12 * * * /usr/sbin/ntpdate cn.pool.ntp.org

参考资料
Linux系统时间同步方法小结
https://www.cnblogs.com/ibnode/p/3573302.html

相关文章

网友评论

      本文标题:VirtualBox安装最小化CentOS的时间同步

      本文链接:https://www.haomeiwen.com/subject/kdmwdktx.html