CentOS系统中设置时间的基本方法总结

软件发布|下载排行|最新软件

当前位置:首页操作系统Centos/RedHat

CentOS系统中设置时间的基本方法总结

  2020-12-11 我要评论

1、安装ntp


#yum install ntp

2、执行命令:


#ntpdate us.pool.ntp.org 。

rhas5的时区是以文件形式存在的,当前的时区文件是在/etc/localtime
其他时区的文件存放在/usr/share/zoneinfo下

3、我们使用的是东八区(+0800),北京,上海的时间
所以将#cp -f /usr/share/zoneinfo/Asia/Shanghai拷贝到/etc/localtime


#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</p> <p>#reboot

重启之后,date查看时间、查看当前时区 date -R、查看/修改Linux时区和时间

一、时区
1. 查看当前时区


date -R

2. 修改设置时区
方法(1)


tzselect

方法(2) 仅限于RedHat Linux 和 CentOS系统


timeconfig

方法(3) 适用于Debian


dpkg-reconfigure tzdata

3. 复制相应的时区文件,替换CentOS系统时区文件;或者创建链接文件


cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime

在中国可以使用:


cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

二、时间

1、查看时间和日期


date

2、设置时间和日期
将CentOS系统日期设定成2011年11月30日的命令


date -s 11/30/11

将CentOS系统时间设定成下午09点13分0秒的命令


date -s 09:13:00

3. 将当前时间和日期写入BIOS,避免重启后失效


hwclock -w

三、定时同步时间
让系统时间与硬件时钟同步,用:


wclock –hctosys
#或
clock –hctosys

 相反地,让硬件时钟与系统时间同步:


hwclock –systohc
#或
clock –systohc

让系统时间每隔十分钟去同步一下硬件时间。


[hqw@localhost root]$ vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/10 * * * * root hwclock --hctosys #加入此行,每隔10分钟执行一次hwclock --hctosys

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们