【Linux专题】CentOS7虚拟机与主机时间同步

199 阅读1分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第20天,点击查看活动详情

工作中发现有的虚拟机的时间与主机时间不一致,导致有些问题不好定位,所以研究了一下修改虚拟机时间的方法,使其与宿主机时间同步,记录一下过程!

方法一

  1. 查看系统版本
 [root@bogon ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:    7.3.1611
Codename:   Core123456

2.设置虚拟机的时间

[root@bogon sbin]# date -s 01/21/2018
20180121日 星期日 00:00:00 CST
[root@bogon sbin]# date -s 21:55:00
20180121日 星期日 21:55:00 CST1234

3.保存当前系统时间为硬件时间

[root@bogon sbin]# clock -w1

4.设置硬件时间同步系统时间

[root@bogon sbin]# clock --hctosys

5.重启

[root@bogon sbin]# reboot

6.重新查看虚拟机的时间

[root@bogon ~]# date
20180121日 星期日 22:08:51 CST12

方法二

将服务器时间同步与系统时间保持一致的命令:

[root@bogon ~]# ntpdate 0.centos.pool.ntp.org
21 Jan 22:08:59 ntpdate[31360]: step time server 85.199.214.100 offset 1.025257 sec

欢迎点赞关注评论,感谢观看ヾ(◍°∇°◍)ノ゙