网站首页 > 教程文章 正文
默认我们的Ubuntu是自动开启时间同步的。当你安装完系统之后,本地时间就是你设置的时区时间。如果你要改变时间,只要系统联网会立马同步到你选择的时区时间。
1、查看Ubuntu的时间设置信息
$ timedatectl
可以看到我的机器是已经开启系统时间同步的。
2、设置Ubuntu同步阿里云(ntp.aliyun.com)时间?
当系统已开启时间同步服务的时候,你去执行”ntpdate ntp.aliyun.com”时间同步,是没有任何意义的。因为此时已开启时间同步的Ubuntu系统会立马把时间更新回来。可以用如下方式检测:
结论:
可以看到你通过命令设置的时间并没有生效。
(1)如何让命令设置的时间生效呢?
通过如下方式:
$ sudo timedatectl set-ntp false #此命令停止ubuntu系统自带的时间同步服务。
$ sudo timedatectl set-local-rtc 1 #此命令是设置硬件时钟(rtc)为本地时间
$ sudo date 090523012008.30 #设置时间为2008年 09月 05日 星期五 23:01:30 CST
$ sudo hwclock –systohc #此命令是将当前设置的时间写入(rtc),防止一段时间后rtc时间同步到系统时间
$ sudo hwclock –hctosys #设置系统时间,使得系统时间变为跟硬件时间同步
结论:
Ubuntu18.04 的系统时间会每隔一段时间同步到设置的时区时间。即使你使用上述命令(timedatectl set-ntp false、sudo timedatectl set-local-rtc 1等)都不好使,唯一能做的是在设置rtc时间成功后,要不断地更新rtc时间为系统时间(sudo hwclock –hctosys)。
同步阿里云(ntp.aliyun.com)时间没有任何意义。
其它:(sudo hwclock –systohc 设置硬件时间,使得硬件时钟变为跟系统时间同步)( sudo systemctl restart systemd-timesyncd.service 重启系统时间同步服务)
3、时间同步的有效方法?
真正的有效方法:
$ sudo vim /etc/systemd/timesyncd.conf #添加如下行:
NTP=ntp.aliyun.com
FallbackNTP=ntp.ubuntu.com
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048
$ sudo timedatectl set-ntp false
$ sudo timedatectl set-ntp true
这样就生效了吗?
可以查看系统日志:
$ less /var/log/syslog
猜你喜欢
- 2024-12-20 阿里云部署的AI绘图效果展播 阿里云图形工作站
- 2024-12-20 ubuntu下轻量级跨平台git服务器gitblit安装和使用详细过程
- 2024-12-20 Ubuntu中搭建EMQ MQTT服务器 ubuntu怎么做服务器
- 2024-12-20 如何使用C LinkSDK(4.x)快速接入阿里云物联网平台?
- 2024-12-20 阿里云无需高深技术,搭建stable diffision平台实现AI文生图自由
- 2024-12-20 Ubuntu安装Tomcat Ubuntu安装图形界面
- 2024-12-20 使用阿里云服务器搭建个人网站 利用阿里云服务器搭建网站
- 2024-12-20 在阿里云上快速跑起来自己本地部署的类chatgpt(llama.cpp)
- 2024-12-20 [网络]openwrt的阿里云编译 openwrt阿里云域名解析
- 2024-12-20 最详细的Ubuntu Linux服务器版安装过程及更新数据包
- 最近发表
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- md5 sha1 (32)
- mybatis plus page (35)
- semaphore 使用详解 (32)
- update from 语句 (32)
- vue @scroll (38)
- 堆栈区别 (33)
- 在线子域名爆破 (32)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)