Linux 时区设置

  1. 1. 1. 时间设置
    1. 1.1. 查看、设置硬件时间
    2. 1.2. 硬件时钟与系统时钟同步
    3. 1.3. 同步 ntp 服务器
  2. 2. 2. 时区设置
    1. 2.1. tzselect
    2. 2.2. 修改配置文件

1. 时间设置

查看、设置硬件时间

1
2
3
4
5
hwclock --show
clock --show
## 月/日/年时:分:秒
hwclock --set --date="06/18/14 14:55"
clock --set --date="06/18/14 14:55"

硬件时钟与系统时钟同步

1
2
3
4
5
6
7
## hc代表硬件时间,sys代表系统时间
## 硬件时钟同步系统时钟
hwclock --hctosys
clock --hctosys
## 系统时钟同步硬件时钟
hwclock --systohc
clock --systohc

同步 ntp 服务器

1
2
3
4
5
6
## 安装 ntp、ntpdate
yum -y install ntp
ntpdate <IP>
## 添加定时任务
crontab -e
0 0 * * * /usr/sbin/ntpdate <IP>

2. 时区设置

tzselect

1
TZ='Asia/Shanghai'; export TZ

修改配置文件

1
2
3
4
vim etc/sysconfig/clock
ZONE=Asia/Shanghai
rm /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1
2
3
4
5
timedatectl
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
yum -y install ntp
vim /etc/ntp.conf