CentOS调整时区及同步时间

新装的服务器可能设置了错误的,需要调整时区并调整时间.如下是使用NTP来从一个时间服务器同步

安装NTP

[root@callcenterbak ~]# yum install ntp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: centos.mirror.cdnetworks.com
 * base: centos.ustc.edu.cn
 * extras: centos.mirror.cdnetworks.com
 * updates: centos.mirror.cdnetworks.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.2p1-9.el5.centos.2.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                Arch                      Version                                      Repository               Size
=============================================================================================================================
Updating:
 ntp                    x86_64                    4.2.2p1-9.el5.centos.2.1                     base                    1.3 M

Transaction Summary
=============================================================================================================================
Install      0 Package(s)        
Update       1 Package(s)        
Remove       0 Package(s)        

Total download size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
ntp-4.2.2p1-9.el5.centos.2.1.x86_64.rpm                                                               | 1.3 MB     00:00    
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
base/gpgkey                                                                                           | 1.5 kB     00:00    
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : ntp                                                                                                   1/2
  Cleanup        : ntp                                                                                                   2/2

Updated:
  ntp.x86_64 0:4.2.2p1-9.el5.centos.2.1                                                                                     

Complete!

 

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

[root@callcenterbak ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp:是否覆盖“/etc/localtime”? y

这一句是把当前时区调整为上海就是+8区,想改其他时区也可以去看看/usr/share/zoneinfo目录;

最后同步时间:

[root@callcenterbak ~]# ntpdate us.pool.ntp.org
17 Nov 17:18:42 ntpdate[9562]: step time server 66.172.42.32 offset -28366.880328 sec

[root@localhost u01]# clock -w

 

你可能感兴趣的:(服务器,的)