一 centos7从外网同步时间和时区设置
第一种方法
yum install ntpdate -y
ntpdate time1.aliyun.com
或
1. 安装ntpdate工具
# yum -y install ntp ntpdate
2. 设置系统时间与网络时间同步
# ntpdate cn.pool.ntp.org
3. 将系统时间写入硬件时间
# hwclock --systohc
第二种方法
# 安装
yum install chrony
# 启用
systemctl start chronyd
systemctl enable chronyd
# 设置亚洲时区
timedatectl set-timezone Asia/Shanghai
# 启用NTP同步
timedatectl set-ntp yes
二 查看当前系统时间
timedatectl
timedatectl status
date
date +%F-%H-%M-%S
2019-12-01-15-32-55
三 查看所有可用的时区
timedatectl list-timezones
# 亚洲
timedatectl list-timezones | grep -E "Asia/S.*"
四 设置时区
timedatectl set-timezone Asia/Shanghai