服务器托管控制面板

CentOS系统的时间同步方法

CentOS系统的时间同步对很多web应用和C/S架构程序有着非常重要的操作,如果没有时间同步,许多记录的信息就会出现偏差,下面我们来介绍一下使用NTP服务来自动同步CentOS系统时间的方法.

在CentOS 5不再区分客户端和服务器,只要配置了NTP,它就会提供NTP服务。

(1)先安装ntp服务:

# yum -y install ntp

(2)配置时间源

# vi /etc/ntp.conf
server pool.ntp.org

供参考的其他时间服务器

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
time.nist.gov
ntp.fudan.edu.cn
timekeeper.isi.edu
subitaneous.cpsc.ucalgary.ca
usno.pa-x.dec.com
time.twc.weather.com
swisstime.ethz.ch
ntp0.fau.de
ntp3.fau.detime-a.nist.gov
time-b.nist.gov
time-nw.nist.gov
nist1-sj.glassey.com
210.72.145.44 

(3)配置是否为其他计算机提供时间服务

# vi /etc/ntp.conf
restrict 192.168.1.0
mask 255.255.255.0
nomodify notrap

(4)配置开机自动运行时间同步服务

# chkconfig ntpd on

(5)启动或停止时间同步服务

# service ntpd start
# service ntpd stop
# service ntpd restart

(6)验证NTP服务是否已经运行

# pgrep ntpd

(7)初始同步

# ntpdate -u time.lib.tsinghua.edu.cn

(8)确认同步成功

# ntpq -p

(9)同时建议修改一下 /etc/sysconfig/ntpd 文件,是服务器BIOS时间一并更新

# vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
#service ntpd restart

把SYNC_HWCLOCK改成 yes 之后, 主机 BIOS 的时间也会跟着一起改变。
当然,如果要提供时间服务,还相应的开放udp 123端口。

(10) 调整服务器时区设置(以东八区-北京时间为例)

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

最后一定要记得重启服务器使时区设置生效。其他的时区文件在/usr/share/zoneinfo/,根据需要做相应的调整即可。


PCCW-T14 香港服务器租用

  • Dell R730xd 2x Xeon E5-2620v3 v12核24线程
  • 内存: 64GB
  • 硬盘: 4x2TB 硬体磁盘阵RAID 1
  • 5M
  • 免费5个IP
  • 4190元/月

PCCW-T13 香港服务器租用

  • Dell R430 2x Xeon E5-2620v3 12核24线程
  • 内存: 32GB
  • 硬盘: 2x2TB 硬体磁盘阵RAID 1
  • 5M
  • 免费5个IP
  • 2890元/月

PCCW-T12 香港服务器租用

  • Dell R430 Xeon E5-2620v3 6核12线程
  • 内存: 16GB
  • 硬盘: 2x2TB 硬体磁盘阵RAID 1
  • 5M
  • 免费5个IP
  • 2390元/月

PCCW-T11 香港服务器租用

  • Dell RDSS 1500 2xXeon E5-2620v4 16 核心32
  • 内存: 32GB
  • 硬盘: 2x2TB 硬体磁盘阵RAID 1
  • 5M
  • 免费5个IP
  • 2690元/月

PCCW-T10 香港服务器租用

  • Dell DSS 1500 2x Xeon E5-2620v4 16 核心32
  • 内存: 32GB
  • 硬盘: 2x2TB
  • 5M
  • 免费5个IP
  • 2490元/月