CentOS设置系统时间与网络时间同步
温馨提示:
本文最后更新于 2023年03月07日,已超过 204 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
1.设置时区为北京时间
[root@S125783 ~]# timedatectl set-timezone Asia/Shanghai
2.查看系统时间
[root@S125783 ~]# timedatectl
Local time: Tue 2023-03-07 00:21:41 CST
Universal time: Mon 2023-03-06 16:21:41 UTC
RTC time: Mon 2023-03-06 16:21:41
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
3.设置时间同步网络
本节所有命令均在root用户下运行。3.1 安装ntp服务
如果已经安装,此命令会自动无效。[root@S125783 ~]# yum install -y ntp
3.2 修改ntp相关参数
[root@S125783 ~]# vi /etc/sysconfig/ntpd
下图是初始参数

将其修改为:

用于修改的文本如下:
SYNC_HWCLOCK=yes
OPTIONS="-g -x"
3.3 启动ntp服务
在这里实际调用的是重启命令,这样可以忽略ntp服务的当前状态。[root@S125783 ~]# systemctl restart ntpd
3.4 设置ntp服务开机启动
[root@S125783 ~]# systemctl enable ntpd
3.5 设置Linux系统时钟与远程NTP服务器同步
[root@S125783 ~]# timedatectl set-ntp true
3.6 再用 hwclock -w 将系统时间赋值给硬件时间
[root@S125783 ~]# hwclock -r Tue 07 Mar 2023 12:27:28 AM CST -0.851539 seconds
[root@S125783 ~]# hwclock -w
[root@S125783 ~]# timedatectl
Local time: Mon 2023-03-06 16:29:07 CST
Universal time: Mon 2023-03-06 08:29:07 UTC
RTC time: Mon 2023-03-06 08:29:07
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
注:date命令,获取的是系统时间
[root@localhost ~]# date
2023年 03月 06日 星期四 16:29:07 CST
正文到此结束
- 本文标签: CentOS
- 本文链接: http://www.92cxy.cn/article/96
- 版权声明: 本文由王小东原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
相关文章
该篇文章的评论功能已被站长关闭