centos系统同步网络时间
-
安装
ntpdate
程序yum install -y ntpdate
-
同步
ntpdate cn.pool.ntp.org
-
设置系统时区为shanghai
timedatectl set-timezone Asia/Shanghai
-
可编写为脚本定时执行
- 脚本示例(/home/syncTime.sh)
#!/bin/bash ntpdate cn.pool.ntp.org timedatectl set-timezone Asia/Shanghai
- 赋予可执行权限
chmod +x /home/syncTime.sh
- 创建crontab定时任务
crontab -e
0 * * * * /home/syncTime.sh //每月每天每小时的第 0 分钟执行一次同步