CentOS设置系统时间、硬件时间、以及定时校对时间

本文介绍在 CentOS 系统中如何设置系统时间和时区。提供了三种不同的方法来设置时区,包括使用 setup 工具、tzselect 工具及直接修改配置文件。此外还介绍了如何通过 ntpdate 命令同步系统时间,并利用 crontab 定时任务确保时间的准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://hi.baidu.com/zj8la8la/blog/item/fbaa941797f0675c21a4e958.html

 

CentOS设置系统时间和时区

一、设置时区

方法一:使用setup工具
setup

选择Timezone configuration

选择Asia/Shanghai

空格键勾选上System clock uses UTC

就OK了。


方法二:使用tzselect工具
tzselect

选择亚洲Asia
5

选择国家China
9

选择地区central China
3

确认选择Yes
1

设置好tzselect后,一定要重写/etc/localtime
rm /etc/localtime

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


方法三:直接修改/etc/sysconfig/clock文件
vi /etc/sysconfig/clock

ZONE="Asia/Shanghai"
UTC=true
ARC=false

重写/etc/localtime
rm /etc/localtime

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


二、重启系统使时区生效
reboot

三、更新时间
更新系统时间
ntpdate cn.pool.ntp.org

更新硬件时间
hwclock --systohc


四、crontab定时较对时间
设置crontab定时较对时间
crontab -e

30 1 * * * ntpdate cn.pool.ntp.org ;hwclock --systohc


PS:
ntpdate命令安装
yum -y install ntp

setup工具安装
yum -y install setuptool

crontabs安装
yum -y install gcc gcc-c++ autoconf vixie-cron crontabs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值