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

Linux下搭建NTP服务器

122次阅读
没有评论

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

背景
当服务器多了,时间准确与否,一致与否是个大问题。虽然这个问题总是被忽略,但是统一一致的时间是很有必要的。下面说一下在局域网内配置 Linux 时间服务器的方法。

假设在 50.50.50.0/24 网段内,要以 IP50.50.50.14 为的 Linux 机器时间服务器。

50.50.50.14 服务器能上外网,能与比较权威的公网时间服务器同步。

同网段内的其他机器每小时自动向 50.50.50.14 同步时间。

配置方法
一、配置 NTP 服务器(假定要配置的服务器的 IP 地址为 50.50.50.14)
1.NTP server 的主配置文件为 /etc/ntp.conf 现对 /etc/ntp.conf 的各项进行说明

 #配置前做好备份
 cd /etc/
 cp ntp.conf ntp.bak.conf

2.vi /etc/ntp.conf(以下是 ntp.conf 文件的内容)
# 设置默认策略为允许任何主机进行时间同步
restrict default ignore
# 开启内部递归网络接口 lo
restrict 127.0.0.1
# 开启 50.50.50.0/24 的网段内的机器,可以使用该服务器进行网络较时,但是不能修改 NTP 时间参数。

restrict 50.50.50.0 mask 255.255.255.0 nomodify
# 设置此服务器同上层服务器做时间同步的 IP 地址,prefer 意味着首选 IP 地址
下面的几个服务器感觉时间反应速度不错

server 210.72.145.44 prefer

server 218.21.130.42
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
# 指定阶层编号为 10,降低其优先度。
server  127.127.1.0
fudge  127.127.1.1 stratum 10
# 漂移文件

driftfile /var/lib/ntp/drift

3.NTP server 的维护
—- 添加为服务
 chkconfig –level 345 ntpd on
—- 启动
 
service ntpd start
 或
 /etc/rc.d/init.d/ntpd start
—- 停止
 service ntpd stop
 或
 /etc/rc.d/init.d/ntpd stop

# 查看本机和上层服务器的时间同步结果
[root@DBServer10414 etc]# ntpq -p
    remote          refid      st t when poll reach  delay  offset  jitter
==============================================================================
 210.72.145.44  .INIT.          16 u    –  64    0    0.000    0.000  0.000
 218.21.130.42  .INIT.          16 u    –  64    0    0.000    0.000  0.000
 125.62.193.121  .INIT.          16 u    –  64    0    0.000    0.000  0.000
 82.200.209.194  .INIT.          16 u    –  64    0    0.000    0.000  0.000
 218.189.210.4  .INIT.          16 u    –  64    0    0.000    0.000  0.000

ntptrace    #可以用來追踪某台时间服务器的时间对应关系
ntpdate IP  #客户端要和 NTP server 进行时钟同步。
 
3.NTP clent 配置

# 停用 nptd 服务
service ntpd stop
# 手动与服务器同步时间
ntpdate 50.50.50.14
24 Feb 18:32:10 ntpdate[7192]: adjust time server 50.50.50.14 offset 0.050908 sec
# 建 crontab,每天 8 点半定时把 ntp 服务器时间写进本机的时钟
crontab -e

30 8 * * * root /usr/sbin/ntpdate 50.50.50.14; /sbin/hwclock -w
# 重启 crontab

service crontab restart

注意:主机防火墙要打开 udp 的 123 端口,供外网访问。

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/129126.htm

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