CentOS7虚拟机与主机时间同步

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

方法一

  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:   Core

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 CST

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

[root@bogon sbin]# clock -w

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

[root@bogon sbin]# clock --hctosys

5.重启

[root@bogon sbin]# reboot

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

[root@bogon ~]# date
2018年 01月 21日 星期日 22:08:51 CST

方法二

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

[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

猜你喜欢

转载自blog.csdn.net/zxy987872674/article/details/79123606