系统时间NTP和RTC同步,Debian的时区配置
系统及架构:
Linux Matrix_061001 5.10.42-yocto-standard #1 Thu Jun 3 07:00:52 UTC 2021 armv7l armv7l armv7l GNU/Linux
参考文章:
https://www.cnblogs.com/aaronLinux/p/7732542.html
https://blog.csdn.net/weixin_41528941/article/details/103504178
A. 更新源,并安装ntpdate
[root@Matrix_061001 ~]apt-get update
[root@Matrix_061001 ~]
[root@Matrix_061001 ~]apt-get install ntpdate
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
ntpdate
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 52.4 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://www.artila.com/download/sama5/linux/deb/cortexa5t2hf-vfp cortexa5t2hf-vfp/main armhf ntpdate armhf 4.2.8p15-r0 [52.4 kB]
Fetched 52.4 kB in 6s (8264 B/s)
Selecting previously unselected package ntpdate.
(Reading database ... 32438 files and directories currently installed.)
Preparing to unpack .../ntpdate_4.2.8p15-r0_armhf.deb ...
Unpacking ntpdate (4.2.8p15-r0) ...
Setting up ntpdate (4.2.8p15-r0) ...
adding crontab
[root@Matrix_061001 ~]
B. 与ntp server同步系统时间,发现设备时区问题
[root@Matrix_061001 ~]ntpdate ntp1.aliyun.com
28 Jun 01:33:37 ntpdate[636]: step time server 120.25.115.20 offset +58409.431346 sec
[root@Matrix_061001 ~]date -R
Sun, 27 Jun 2021 09:19:14 +0000
[root@Matrix_061001 ~]
C. 修改时区
-
修改设置Linux服务器时区
方法 A 命令 : “tzselect”
方法 B 仅限于RedHat Linux 和 CentOS 命令 : “timeconfig”
方法 C 适用于Debian 命令 : “dpkg-reconfigure tzdata”
-
通过/etc/profile来修改
echo “export TZ=‘UTC’” >> /etc/profile
source /etc/profile 更新系统变量
采用本方式进行修改时区配置
[root@Matrix_061001 ~]echo "export TZ='Asia/Shanghai'" >> /etc/profile
[root@Matrix_061001 ~]source /etc/profile
-
复制相应的时区文件,替换系统时区文件;或者创建链接文件
cp /usr/share/zoneinfo/主时区/主时区/次时区 /etc/localtime
例如:在设置中国时区使用亚洲/上海(+8)
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ln -sf /usr/share/zoneinfo/UTC /etc/localtime 设置为UTC时间
D. NTP和RTC时间同步
[root@Matrix_061001 ~]cat /etc/default/ntpdate
NTPSERVERS="ntp1.aliyun.com"
UPDATE_HWCLOCK="yes"
[root@Matrix_061001 ~]
[root@Matrix_061001 ~]
至此,系统重启后便会自动同步系统时间
___ ____ ____________ ___
/ | / __ |_ __/ _/ / / |
/ /| | / /_/ // / / // / / /| |
/ ___ |/ __ _// / _/ // /___/ ___ |
/_/ |_/_/ |_|/_/ /___/_____/_/ |_|
http://www.artila.com
[root@Matrix_061001 ~]
[root@Matrix_061001 ~]
[root@Matrix_061001 ~]date -R
Mon, 28 Jun 2021 12:54:56 +0800
[root@Matrix_061001 ~]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)