Centos 5.6下面架设NTP服务器

简介:
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://navyaijm.blog.51cto.com/4647068/809455

最近公司在搞运维自动化这一块,要实现批量更新服务器的配置文件等等操作,需要用到NTP服务器,下面把搭建的过程分享一下:
1.安装ntp服务包
 

  # yum install ntp -y
2. 让本服务器时间与 3.cn.pool.ntp.org 时间同步;
   [root@localhost ~]# ntpdate
  3.cn.pool.ntp.org
3. 自动同步服务器时钟
   [root@localhost ~]# crontab -e
   * */4 * * * /usr/sbin/ntpdate 3.cn.pool.ntp.org
   [root@localhost ~]# service crond restart
4.配置
ntp.conf
   [root@localhost ~]# vi /etc/ntp.conf
restrict default nomodify notrap noquery
restrict 10.20.220.0 mask 255.255.254.0 nomodify notrap
restrict 10.20.216.0 mask 255.255.254.0 nomodify notrap
restrict 10.20.221.0 mask 255.255.254.0 nomodify notrap
restrict 127.0.0.1
restrict -6 ::1
server 3.cn.pool.ntp.org
server 10.20.220.251
server time.lib.tsinghua.edu.cn
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 8
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
logfile /var/log/ntp.log
broadcastdelay 0.008


5.
启动或停止时间服务
   # service ntpd start
   # service ntpd stop
   # service ntpd restart
6.验证ntp服务已经运行
   # pgrep ntpd
   #123端口是否开启
7.初始同步
   # ntpdate -u 3.cn.pool.ntp.org
8.确认同步成功
[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*61.153.197.226  66.220.9.122     2 u  188  256  377   25.124   12.510   2.999
 10.20.220.251   .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 web.lib.tsinghu .INIT.          16 u    - 1024    0    0.000    0.000   0.000
+114.80.81.1     209.81.9.7       2 u  168  256  377   27.492  -31.989   1.283
 LOCAL(0)        .LOCL.           8 l   23   64  377    0.000    0.000   0.001

9.linux客户端设置NTP

目前 Linux 系统上面有两个时间,一个是 Linux 系统,另一个则是 BIOS 时间(真正的硬件记录的时间)!

我们可以使用 date 这个指令来手动修正目前主机的时间,date 这个指令仅修正 Linux 时间而已,所以需要以 hwclock 这个指令来将 BIOS 时间也更新才行

[root@test root]# date MMDDhhmmYYYY
MM:月份
DD:日期
hh:小时
mm:分钟
YYYY:公元年

 
[root@test root]# hwclock [-rw]

-r:检视目前的 BIOS 时间
-w:将目前 Linux 的时间写入 BIOS 当中!

[root@localhost ~]# date ; hwclock -r
2011年 03月 23日 星期三 01:03:59 CST
2011年03月23日 星期三 03时05分00秒  -0.914570 seconds

#  date 与 hwclock -r 所显示的时间是『不一致的』!
# 因为 Linux 时间与 BIOS 时间不一致所导致的一个问题!
# 需要以 hwclock -w 来将 Linux 时间写入 BIOS

[root@localhost ~]# hwclock -w
[root@localhost ~]# date ; hwclock -r
2011年 03月 23日 星期三 01:03:59 CST
2011年03月23日 星期三 01时04分00秒  -0.814770 seconds


#自动同步服务器时钟
[root@localhost ~]# crontab -e
# 加入这一行:
10 5 * * * root /usr/bin/ntpdate 10.20.220.251 ; /sbin/hwclock -w

[root@localhost ~]# service crond restart

10.windows客户端设置NTP

设置 Windows Time 服务:在“控制面板”中打开“管理工具”,再打开“服务”;在服务中找到“Windows Time”,双击服务名称,在打开的“Windows Time的属性”中设置“启动类型”为“自动”,再按下启动按钮。

在“运行(R)”中用“cmd”命令进入在DOS命令行窗体;执行以下命令(注意空格):

net time /setsntp:192.168.1.232

net stop w32time

net start w32time

w32tm –s

(设置时间服务器地址)

(停止时间服务)

(启动时间服务)

(立即同步时间)

 

11.客户端常见错误:

错误1.Server dropped: Strata too high

ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。

ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。

这是因为NTP server还没有和其自身或者它的server同步上。

以下的定义是让NTP Server和其自身保持同步,如果在/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。

server  127.127. 1.0
fudge  127.127. 1.0 stratum  8 

 

ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。

那么如何知道何时ntp server完成了和自身同步的过程呢?

ntp server上使用命令:

#  watch ntpq -p


出现画面:

Every 2.0s: ntpq -p                                                                                                             Thu Jul 10 02:28:32 2008

     remote           refid      st t when poll reach   delay   offset jitter

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

 192.168.30.22   LOCAL(0)         8 u   22   64    1    2.113 179133.   0.001

 LOCAL(0)        LOCAL(0)        10 l   21   64    1    0.000   0.000  0.001

注意LOCAL的这个就是与自身同步的ntp server

注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0175次的变更,每一次是poll的值的秒数,是64*5=320秒的时间。

如果之后从ntp客户端同步ntp server还失败的话,用ntpdate –d来查询详细错误信息,再做判断。

错误2.Server dropped: no data

从客户端执行
netdate –d时有错误信息如下:

transmit(192.168.30.22)

transmit(192.168.30.22)

transmit(192.168.30.22)

transmit(192.168.30.22)

transmit(192.168.30.22)

192.168.30.22: Server dropped: no data

server 192.168.30.22, port 123

.....
28 Jul 17:42:24 ntpdate[14148]: no server suitable for synchronization found

出现这个问题的原因可能有2

1。检查ntp的版本,如果你使用的是ntp4.2(包括4.2)之后的版本,在restrict的定义中使用了notrust的话,会导致以上错误。

使用以下命令检查ntp的版本:

#  ntpq -c version


下面是来自ntp官方网站的说明:
The behavior of 
notrust changed between versions 4.1 and 4.2.

In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".

In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client)ntpd

解决:

notrust去掉。


2
。检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。

可以用命令

# service iptables stop


来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。

 

本文出自 “屌丝运维男” 博客,请务必保留此出处http://navyaijm.blog.51cto.com/4647068/809455

目录
相关文章
|
2月前
|
弹性计算 数据安全/隐私保护
2024年阿里云雾锁王国/Enshrouded服务器搭建架设教程(保姆级)
随着游戏行业的日新月异,玩家们对游戏体验的期待也不断攀升。阿里云针对这一需求,推出了快速、便捷的游戏联机服务器一键部署方案。在本篇教程中,我们将向大家展示如何在短短的10秒钟内,利用阿里云服务器轻松搭建雾锁王国游戏服务器,为您的游戏体验增添更多流畅与顺畅。跟随我们的步骤,让您的游戏世界更加精彩!
|
2月前
|
缓存 关系型数据库 MySQL
百度搜索:蓝易云【CentOS8服务器安装MySQL报错:no match mysql-community-server】
现在,你已经成功安装了MySQL服务器并解决了"no match mysql-community-server"的报错问题。祝你使用愉快!
42 1
|
3月前
|
Linux
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
210 0
|
3月前
|
Linux 网络安全
CentOS7服务器SSH登陆时自动显示服务器基础信息
CentOS7服务器SSH登陆时自动显示服务器基础信息
42 0
|
10天前
|
Linux
centos 查看服务器信息 版本cpu
centos 查看服务器信息 版本cpu
9 0
|
1月前
|
Oracle 关系型数据库 Linux
服务器Centos7 静默安装Oracle Database 12.2
服务器Centos7 静默安装Oracle Database 12.2
71 0
|
1月前
|
存储 弹性计算 Linux
阿里云ECS(CentOS镜像)安装docker
阿里云ECS(CentOS镜像)安装docker
374 0
|
2月前
|
弹性计算 Linux 数据安全/隐私保护
1分钟幻兽帕鲁社区服务器搭建架设开服教程(Linux)
1分钟幻兽帕鲁社区服务器搭建架设开服教程(Linux)玩转幻兽帕鲁服务器,幻兽帕鲁Palworld多人游戏专用服务器一键部署教程,阿里云推出新手0基础一键部署幻兽帕鲁服务器教程,傻瓜式一键部署,3分钟即可成功创建一台Palworld专属服务器,成本仅需26元,阿里云百科分享2024年新版基于阿里云搭建幻兽帕鲁服务器教程
72 3
|
2月前
|
Linux 应用服务中间件 nginx
国服浪潮服务器操作系统——KeyarchOS多容器架设体验心得
国服浪潮服务器操作系统——KeyarchOS多容器架设体验心得
55 0
|
2月前
|
弹性计算 Ubuntu Linux
帕鲁服务器多少钱?2024年幻兽帕鲁服务器搭建架设教程(保姆级)
帕鲁服务器多少钱?阿里云帕鲁服务器26.52元1个月在帕鲁的世界中,与神奇的生物共度悠闲时光是一种无与伦比的乐趣。然而,有时官方服务器的不稳定性可能会给游戏体验带来延迟和卡顿。 为了告别这些问题,部署自己的幻兽帕鲁服务器成为了一个不错的选择。通过搭建专属的游戏服务器(Dedicated Server),和小伙伴们获得一个专属的服务空间,获得顺畅流畅的游戏体验。 在本文中,我们将介绍如何使用自己的服务器来部署属于自己的幻兽帕鲁服务器,与小伙伴们共同展开一场精彩的冒险之旅。
146 0

热门文章

最新文章