通过NTP同步Linux服务器时间

通过NTP同步Linux服务器时间

大多数服务器会自动设置成网络时间,但是如果你想自己设置,或者说是想更换时间同步服务器,这篇文章可能会对你有帮助。

因为最近正好有这样的需要,于是我就觉得写下来作为下次的参考应该是很有意义的,这正适合我。

首先你需要安装NTP,如果你没有安装过,对于Debian和Ubuntu,用下面的命令即可

sudo apt-get install ntp

对于RedHat和CentOS,你需要用这个

yum install ntp

接着你就需要编辑 /etc/ntp.conf 文件,可能已经给你自动写好了。

你可能会在这里看到很多行,但是最重要的是server行,你可以在www.pool.ntp.org 找到服务器地址的列表,选择最适合你所在区域的,然后把他们添加到文件中。对于我来说,这样就够了:

server 0.north-america.pool.ntp.org

server 1.north-america.pool.ntp.org

server 2.north-america.pool.ntp.org

server 3.north-america.pool.ntp.org

接着你需要启动NTPD服务:

/etc/init.d/ntpd restart

如果你现在就想同步时间,可以通过下面的命令更换首选服务器

/usr/sbin/ntpdate pool.ntp.org

这是不是很简单。

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注