分类: 电脑技术
作者: admin
Debian更新系统时间
 
A 更新源,并安装ntpdate:
0.date 查看当前的系统时间
1.sudo apt-get update 更新源
2.sudo apt-get install ntpdate 安装ntpdate
3.sudo ntpdate ntp1.aliyun.com 更新系统时间
出现错误可以停止ntp服务再同步时系统时间
/etc/init.d/ntp stop

B 更新时区:
4.date -R 可查看时区 不是08区,则更新时区
5.sudo tzselect
6.选择5 Asia
7.选择9 China
8.选择1 Beijing Time
9.选择1 Yes

C 更新系统变量:
10.执行 sudo nano /etc/profile
11.在export PATH 前加一行:export TZ='Asia/Shanghai'
12.export PATH 添加:export PATH=$JAVA_HOME/bin:$TZ:$PATH
13.Crtl+O写入、Ctrl+X退出
14.执行:source /etc/profile更新系统变量

15.再date查看时间,完成。
 
debian10系统一键修改时区
 
timedatectl set-timezone  Asia/Shanghai
 

Debian 9上设置或更改时区。

先决条件

您所登录的用户必须具有 sudo权限,才能更改系统的时区。

检查当前时区

在Debian和其他现代Linux发行版中,timedatectl命令允许您显示和设置当前系统的时间和时区。

timedatectl

如下面的输出所示,系统的时区设置为“美国/芝加哥”:

      Local time: Mon 2019-03-11 16:46:45 CDT   Universal time: Mon 2019-03-11 21:46:45 UTC         RTC time: Mon 2019-03-11 21:46:45        Time zone: America/Chicago (CDT, -0500)  Network time on: yes NTP synchronized: no  RTC in local TZ: no

通过将/etc/localtime符号链接到/usr/share/zoneinfo目录中的二进制时区标识符来配置系统时区。检查时区的另一个选项是使用 ls命令

显示符号链接指向的路径。

ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 Jan 23 03:19 /etc/localtime -> ../usr/share/zoneinfo/America/Chicago

更改Debian中的时区

更改时区之前,您需要找出要使用的时区的长名称。时区命名约定通常使用“地区/城市”格式。

要列出所有可用时区,可以列出/usr/share/zoneinfo目录中的文件,也可以使用timedatectl命令。

timedatectl list-timezones
... Europe/Lisbon Europe/Ljubljana Europe/London Europe/Luxembourg Europe/Madrid Europe/Malta ...

确定了您所在位置的时区后,以sudo用户身份运行以下命令:

sudo timedatectl set-timezone your_time_zone

例如,要将系统的时区更改为Europe/Ljubljana,您可以运行:

sudo timedatectl set-timezone Europe/Ljubljana

通过发出timedatectl命令验证更改:

timedatectl
      Local time: Mon 2019-03-11 22:51:27 CET   Universal time: Mon 2019-03-11 21:51:27 UTC         RTC time: Mon 2019-03-11 21:51:26        Time zone: Europe/Ljubljana (CET, +0100)  Network time on: yes NTP synchronized: yes  RTC in local TZ: no

通过创建符号链接来更改时区

如果您正在运行Debian 的较旧版本,并且系统上没有timedatectl命令,则可以通过将/etc/localtime符号链接到/usr/share/zoneinfo目录中的时区来更改时区。

删除当前的/etc/localtime文件或符号链接:

sudo rm -f /etc/localtime

确定要配置的时区,然后创建符号链接

sudo ln -s /usr/share/zoneinfo/Europe/Ljubljana /etc/localtime

您可以通过列出/etc/localtime文件或发出date命令来确认更改:

date
Mon Mar 11 22:55:04 CET 2019