centos7同步网络时间并修改时区

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mjp_erhuo/article/details/83895177

安装ntpdate工具
# yum -y install ntp ntpdate

设置系统时区为上海
# timedatectl set-timezone Asia/Shanghai 

设置系统时间与网络时间同步
# ntpdate 0.asia.pool.ntp.org
# ntpdate 1.asia.pool.ntp.org
# ntpdate 2.asia.pool.ntp.org  # 我使用是  2.asia.pool.ntp.org
# ntpdate 3.asia.pool.ntp.org

vi /etc/crontab   编辑时间配置文件每个2天同步一次

# * */48* * * ntpdate 2.asia.pool.ntp.org

将系统时间写入硬件时间
# hwclock --systohc


强制系统时间写入CMOS中防止重启失效
# hwclock -w  或     clock -w

如果没有安装ntp服务器,刚需要先执行以下命令:
# yum install ntp #安装ntp服务器

4、/sbin/hwclock --systohc   #设置硬件时间和系统时间一致并校准
 

猜你喜欢

转载自blog.csdn.net/mjp_erhuo/article/details/83895177