最近更新博文,显示的发布时间总是显示N分钟后,估计就是服务器时间不对了,下面雨辰跟大家一起复习下centos关于时间方面的一些命令。
1.查看时间
[root@yuchen ~]# date
Thu Apr 4 11:24:24 CST 2020
2.使用date -s修改时间
[root@yuchen ~]# date -s "2020/4/4 11:26"
Thu Apr 4 11:26:00 CST 2020
3.修改时区
使用新的时区文件覆盖系统默认时区
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
4.安装ntpdate
yum install ntpdate -y
5.同步网络时间
ntpdate ntp1.aliyun.com
6.保存为bios时间
同步BIOS时钟,强制将系统时间写入CMOS,使之永久生效,避免系统重启后恢复成原时间。
# clock -w
7.设置crontab同步时间
59 23 * * * ntpdate ntp1.aliyun.com
* * * * * command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
8.查看bios时间
[root@bogon ~]# hwclock -r
Thu 04 Apr 2019 11:35:20 AM CST -0.365289 seconds