1.设置时区为北京时间
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai
2.查看系统时间
[root@localhost ~]# timedatectl
Local time: 四 2023-03-02 17:40:41 CST #系统时间
Universal time: 四 2023-03-02 09:40:41 UTC #国际协调时间
RTC time: 六 2023-02-25 05:35:45 #硬件时间
Time zone: Asia/Shanghai (CST, +0800) #时区
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
3.设置时间同步网络
本节所有命令均在root用户下运行。
3.1 安装ntp服务
如果已经安装,此命令会自动无效。
[root@localhost ~]# yum install -y ntp
3.2 修改ntp相关参数
[root@localhost ~]# vi /etc/sysconfig/ntpd
下图是初始参数
将其修改为:
用于修改的文本如下:
SYNC_HWCLOCK=yes
OPTIONS="-g -x"
3.3 启动ntp服务
在这里实际调用的是重启命令,这样可以忽略ntp服务的当前状态。
systemctl restart ntpd
3.4 设置ntp服务开机启动
systemctl enable ntpd
3.5 设置Linux系统时钟与远程NTP服务器同步
timedatectl set-ntp true
3.6 再用 hwclock -w 将系统时间赋值给硬件时间
[root@localhost ~]# hwclock -r
2023年02月25日 星期六 13时56分24秒 -0.323442 秒
[root@localhost ~]# hwclock -w

注:我们常用的date命令,获取的是系统时间
[root@localhost ~]# date
2023年 03月 02日 星期四 18:18:44 CST
Linux系统时区与NTP时间同步配置指南
该文详细介绍了如何在Linux系统中设置时区为北京时间,以及如何进行时间同步。首先通过timedatectl命令设置时区,然后安装并配置ntp服务,包括修改ntp相关参数,启动服务,设置开机启动,并使系统时间与远程NTP服务器同步。最后,使用hwclock命令处理硬件时间与系统时间的同步问题。
1049

被折叠的 条评论
为什么被折叠?



