阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux之使用NTP服务管理/同步服务器时间

172次阅读
没有评论

共计 1612 个字符,预计需要花费 5 分钟才能阅读完成。

当有多台 Web Server 时,而且每台服务器的时间需要保持一致,这时就可以考虑使用 NTP 服务了。

1. 先用用 ntpstat 查看一下 NTP service 当前的状态。

#ntpstat

如果输出下面内容,说明还没有启动,需要设置服务器重启时 NTP 服务自启动:

Unable to talk to NTP daemon. Is it running?

如果输出下面内容说明已经在工作了:

synchronised to NTP server (198.55.111.5) at stratum 3

time correct to within 238 ms

polling server every 64 s

如果输出:unsynchronised, 需要重新启动 (ntpd restart) 一下进行同步。

2. 使用 ntpq - p 查看 NTP server 列表

#ntpq -p

remote          refid      st t when poll reach  delay  offset  jitter

==============================================================================

*dns1.synet.edu. 202.118.1.46    2 u  46  64  377  19.924  11.896  5.692

+dns2.synet.edu. 202.118.1.46    2 u  45  64  317  20.518  11.833  6.992

dns.sjtu.edu.cn .STEP.          16 u    –  64    0    0.000    0.000  0.000

3. 手动同步时间

#ntpdate

如果输出下面内容,说明 ntp 服务已经启动导致手动同步时间失败,需要先停止 ntp 服务:

the NTP socket is in use. exiting

#service ntpd stop

#ntpdate cn.pool.ntp.org

如果输出下面内容,说明手动同步时间成功:

adjust time server xxx

最后记得将 ntp 服务启动,让他自动更新。

4. 启动 NTP 服务

#service ntpd start

Starting ntpd:                                            [OK]

Enable NTP to start at boot time with the chkconfig command.

5. 开启 NTP 自启动

#chkconfig ntpd on

Verify that NTP is enabled with the following command.

6. 检查 NTP 自启动情况

#chkconfig –list ntpd

ntpd          0:off 1:off 2:on 3:on 4:on 5:on 6:off

Here ntpd is on in runlevels 2, 3, 4, and 5, which is correct.

7. 自定义 NTP server

CentOS NTP 服务器安装与配置 http://www.linuxidc.com/Linux/2014-01/95258.htm

Linux 实战部署系列之 NTP 服务器 http://www.linuxidc.com/Linux/2013-11/92275.htm

多种操作系统 NTP 客户端配置 http://www.linuxidc.com/Linux/2013-10/91928.htm

搭建企业级 NTP 时间服务器 http://www.linuxidc.com/Linux/2014-02/97205.htm

Linux 下快速搭建 ntp 时间同步服务器 http://www.linuxidc.com/Linux/2014-07/104371.htm

CentOS 6.3 下实现 NTP 时间服务器 http://www.linuxidc.com/Linux/2014-08/105414.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/129277.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计1612字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中