下面会分别说明CentOS系统和Ubuntu系统下服务器同步标准时间的方法:
CentOS系统同步时间的方法
- 安装ntp服务
copy
sudo yum install ntp
- 修改成国内时区并同步
copy
timedatectl set-timezone Asia/Shanghai
timedatectl set-ntp yes
- 查看时间确保同步
copy
timedatectl
Ubuntu系统同步时间的方法
- 安装tzdata
copy
dpkg-reconfigure tzdata
按照提示进行时区选择
- 防止系统重启后时区改变
copy
sudo cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime
- 网上同步时间
copy
sudo apt-get install ntpdate
ntpdate cn.ntp.org.cn
hwclock -w