现象描述:
在openEuler20.03上查看时间,发现与当前时间不一致:
[root@localhost etc]# date 2022年 11月 09日 星期三 20:49:31 EST
可能原因:
可能是虚拟机创建时时区选择有误或者手动修改了时区
定位思路:
尝试搭建ntp时间同步服务,以此同步时间
处理步骤:
选用一台centos7.6且时间正确的虚拟机作为服务端搭建ntp服务,openEuler20.03也安装ntp,但都暂时不启动
服务端配置:
[root@centos-01 log]# yum install ntp -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed --> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos.2 for package: ntp-4.2.6p5-29.el7.centos.2.x86_64 --> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.2.x86_64 --> Running transaction check ---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed ---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed --> Finished Dependency Resolution ....... [root@centos-01 ~]# vim /etc/ntp.conf restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap#授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间 server 127.127.1.0#当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步 fudge 127.127.1.0 stratum 10 #server 0.centos.pool.ntp.org iburst#集群在局域网中,不使用其他互联网上的时间 #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst [root@centos-01 ~]# vim /etc/sysconfig/ntpd 新增 SYNC_HWCLOCK=yes #让硬件时间与系统时间一起同步 [root@centos-01 ~]# systemctl start ntpd && systemctl enable ntpd
客户端操作:
由于客户端此时时间是英国时间EST,所以需要将它改为北京时间CST
正常处理方法是:ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@localhost etc]# ll /etc/localtime lrwxrwxrwx 1 root root 33 11月 9 22:54 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
但查看发现localtime本就是shanghai的,不合理,选择从其他正常机器上将Asia/Shanghai文件copy过来
[root@localhost etc]# scp -r root@192.168.137.11:/usr/share/zoneinfo/Asia/Shanghai . The authenticity of host '192.168.137.11 (192.168.137.11)' can't be established. ECDSA key fingerprint is SHA256:+lsg7Ynp9BeJulFbSm0IauJA5/T1aogMrmPeZ43052Q. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.137.11' (ECDSA) to the list of known hosts. root@192.168.137.11's password: Shanghai [root@localhost etc]# mv Shanghai /usr/share/zoneinfo/Asia/ mv:是否覆盖'/usr/share/zoneinfo/Asia/Shanghai'? y
此时再次查看时间
[root@localhost etc]# date 2022年 11月 09日 星期三 22:55:43 CST 时区已经变回CST,不过时间还是不对
客户端执行ntp命令(不用启动ntp服务,服务端启动即可)
[root@localhost etc]# ntpdate 192.168.137.11 10 Nov 09:58:17 ntpdate[3682]: step time server 192.168.137.11 offset +39601.956141 sec [root@localhost etc]# date 2022年 11月 10日 星期四 09:58:23 CST
时间已恢复。
参考信息:
无