淘主机论坛

 找回密码
 成为淘友

QQ登录

只需一步,快速开始

KT服务器促销中 100M带宽 10T流量 超值传送门:会员注册及发帖规则 发帖看过来
查看: 2232|回复: 2

[Linux应用] 设置修改CentOS系统时区(方法)

[复制链接]
发表于 2012-12-7 09:42:12 | 显示全部楼层 |阅读模式
练习使用CentOS操作系统时发现了一个问题,系统时区是刚开始安装的时候选择的,找了一些资料分享如下:

1、我们可以查看当前的时区

命令:date -R

2、修改时区

步骤a、命令:tzselect

  • 会要你选择新的时区,分为几步:
  • 第一步是选择大洲,亚洲 Asia一般都是5
  • 第二步是选择国家,中国China一般是9
  • 第三步是选时区,一般就是East China 选择1
  • 第四步确认修改,yes,选择1

步骤b、时区文件建立好了,做一个链接(这里以修改为中国时区为例)
命令:ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
复制时区文件到默认时区: cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 选择y

步骤c、查看现在的时间
命令:date
如: [root@localhost ~]# date
结果:Tue Jan 24 16:17:14 CST 2012

步骤d、修改时间
命令:date -s "2012-12-21 0:0:0"
结果:Fri Dec 21 00:00:00 CST 2012

其他e、可以在线更新时间
命令:ntpdate time.scau.edu.cn

结果:24 Jan 16:28:58 ntpdate[2094]: step time server 210.72.145.44 offset -28812.507076 sec

f、同步时间到BIOS
命令:hwclock -w

这样时区和时间都设置好了,赶紧重启后再试试吧!
 楼主| 发表于 2012-12-7 09:42:25 | 显示全部楼层

同步linux centos 时区的其他方法参考

在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况。如果没有安装,而你使用的是 CentOS系统 那使用命令 yum install ntp

然后:ntpdate us.pool.ntp.org 。

因为CentOS系统是用rhas的源码再编译的,很多地方是完全一样的。

rhas5的时区是以文件形式存在的,当前的时区文件是在/etc/localtime

那么其他时区的文件存放在哪里呢?

在/usr/share/zoneinfo下

我们用东八区,北京,上海的时间

#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#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系统日期设定成1996年6月10日的命令
date -s 06/22/96
将CentOS系统时间设定成下午1点52分0秒的命令
date -s 13:52:00

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

三、定时同步时间
# /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

这样我们就完成了关于设置修改CentOS系统时区的问题了。希望大家可以学习到更多的知识。
 楼主| 发表于 2012-12-8 14:46:04 | 显示全部楼层

Linux下ntp时间同步服务ntpd出现the NTP socket is in use,exiting解决

[root@EPDDB log]#
[root@EPDDB log]# ntpdate 10.154.8.200
6 Sep 09:35:09 ntpdate[30210]: the NTP socket is in use, exiting
[root@EPDDB log]#


[root@EPDDB init.d]# pwd
/etc/rc.d/init.d
[root@EPDDB init.d]# ./ntpd stop
Shutting down ntpd: [ OK ]
[root@EPDDB init.d]# ntpdate 10.154.8.200
6 Sep 09:37:19 ntpdate[30658]: step time server 10.161.8.200 offset -51.869609 sec
[root@EPDDB init.d]# ntpdate 10.161.8.200
6 Sep 09:37:20 ntpdate[30659]: adjust time server 10.161.8.200 offset -0.000145 sec
[root@EPDDB init.d]# ntpdate 10.161.8.200
6 Sep 09:37:21 ntpdate[30662]: adjust time server 10.161.8.200 offset -0.000036 sec
[root@EPDDB init.d]# ntpdate 10.161.8.200
6 Sep 09:37:22 ntpdate[30663]: adjust time server 10.161.8.200 offset -0.000041 sec
[root@EPDDB init.d]#

或在 # setup 进入服务关闭ntpd服务。
您需要登录后才可以回帖 登录 | 成为淘友

本版积分规则

小黑屋|手机版|Archiver|淘主机

GMT+8, 2024-4-23 21:20

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表