在是用虛擬機(jī)的時(shí)候,往往時(shí)間對(duì)不上,這就使強(qiáng)迫癥不得安心學(xué)習(xí)了,解決方法如下:
作為中國的一員,在安裝虛擬機(jī)的時(shí)候,可以設(shè)置上海時(shí)間作為參考:
1.把上海時(shí)間文件cp到etc文件下的localtime文件里。
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp:是否覆蓋"/etc/localtime"? y
2.同步時(shí)間需要用到ntpdate服務(wù),虛擬機(jī)沒有的就簡(jiǎn)單安裝一下:
[root@localhost ~]# yum install -y ntpdate
已加載插件:fastestmirror, refresh-packagekit, security
設(shè)置安裝進(jìn)程
Loading mirror speeds from cached hostfile
base: mirror.bit.edu.cn
extras: mirror.bit.edu.cn
updates: mirrors.163.com
包 ntpdate-4.2.6p5-15.el6.centos.x86_64 已安裝并且是最新版本
無須任何處理
3.安裝完之后,同步服務(wù)器時(shí)間與虛擬機(jī)時(shí)間:
[root@localhost ~]# ntpdate time.nist.gov
7 Sep 19:00:17 ntpdate[3064]: no server suitable for synchronization found
如果出現(xiàn)報(bào)錯(cuò),嘗試啟動(dòng)一下ntpdate服務(wù):
[root@localhost ~]# service ntpdate start
ntpdate: 與時(shí)間服務(wù)器同步: [確定]
8.ntpdate服務(wù)啟動(dòng)后,輸入命令date,發(fā)現(xiàn)時(shí)間已經(jīng)同步:
[root@localhost ~]# date
2019年 09月 07日 星期六 11:06:55 CST
9.如果想看同步過程,可以安裝ntp-perl服務(wù):
[root@localhost ~]# yum install -y ntp-perl(查看同步過程)
已加載插件:fastestmirror, refresh-packagekit, security
設(shè)置安裝進(jìn)程
Loading mirror speeds from cached hostfile
base: mirror.bit.edu.cn
extras: mirror.bit.edu.cn
完畢!
[root@localhost ~]# ntptrace
/usr/sbin/ntpq: read: Connection refused
10.最后一步,把系統(tǒng)時(shí)間同步到硬件,防止系統(tǒng)重啟后時(shí)間恢復(fù):
[root@localhost ~]# hwclock -w
[root@localhost ~]# hwclock
2019年09月07日 星期六 11時(shí)08分01秒 -0.250896 seconds
[root@localhost ~]#
11.重啟虛擬機(jī),執(zhí)行date命令:
[E:~]$
Connecting to 10.0.0.11:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Sat Sep 7 11:12:03 2019 from 10.0.0.1
Welcome to HSP's system,please not use rm command.
大膽折騰,百味才是人生!
2019-09-07 11:12:35 星期六
===========================================
[root@localhost ~]# ntpdate time.nist.gov
7 Sep 11:21:01 ntpdate[2694]: no server suitable for synchronization found
[root@localhost ~]# date
2019年 09月 07日 星期六 11:21:04 CST
[root@localhost ~]#
原文鏈接:https://blog.csdn.net/youmatterhsp/article/details/100593317