23.1、ntp 服务

名称

ntp 网络时钟协议,也是一种时钟软件,使用 UDP 123 端口

 

安装

[root@mini-1 ~]# yum -y install ntp
[root@mini-1 ~]# systemctl start ntpd
[root@mini-1 ~]# systemctl enable ntpd

 

默认配置

[root@mini-1 etc]# cat ntp.conf 
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

#系统时间和硬件时间偏差记录
driftfile /var/lib/ntp/drift

#默认允许任何人同步
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery

#开启内部递归网络接口lo
# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 
restrict ::1

#设置一个网段(一般为内部子网)的客户端可以进行网络校时,但不能修改NTP服务器的时间,由于只做客户端,此步可忽略
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

#同步的时钟源
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

#将自己设置为10级服务器,0为最高级
fudge  10.17.228.80 stratum 1

[root@mini-1 etc]#

 

参数注释

1. 权限设定

restrict [ 客户端IP ]  mask  [ IP掩码 ]  [参数]

“客户端IP” 和 “IP掩码” 指定了对网络中哪些范围的计算机进行控制,如果使用default关键字,则表示对所有的计算机进行控制,参数指定了具体的限制内容,常见的参数如下:

◆ ignore:拒绝连接到NTP服务器

◆ nomodiy: 客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

◆ noquery: 不提供客户端的时间查询

◆ notrap: 不提供trap远程登录功能,trap服务是一种远程时间日志服务。

◆ notrust: 客户端除非通过认证,否则该客户端来源将被视为不信任子网 。

◆ nopeer: 提供时间服务,但不作为对等体。

◆ kod: 向不安全的访问者发送Kiss-Of-Death报文。

 

2. 上层主机设定

server host  [ key n ] [ version n ] [ prefer ] [ mode n ] [ minpoll n ] [ maxpoll n ] [ iburst ]

其中host是上层NTP服务器的IP地址或域名,随后所跟的参数解释如下所示:

◆ key: 表示所有发往服务器的报文包含有秘钥加密的认证信息,n是32位的整数,表示秘钥号。

◆ version: 表示发往上层服务器的报文使用的版本号,n默认是3,可以是1或者2。

◆ prefer: 如果有多个server选项,具有该参数的服务器有限使用。

◆ mode: 指定数据报文mode字段的值。

◆ minpoll: 指定与查询该服务器的最小时间间隔为2的n次方秒,n默认为6,范围为4-14。

◆ maxpoll:  指定与查询该服务器的最大时间间隔为2的n次方秒,n默认为10,范围为4-14。

◆ iburst: 当初始同步请求时,采用突发方式接连发送8个报文,时间间隔为2秒。

 

命令

查看时钟同步情况

[root@mini-1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*203.107.6.88    10.137.55.181    2 u    7   64  377   24.879   -1.455 203.748
[root@mini-1 ~]# ntpstat
synchronised to NTP server (203.107.6.88) at stratum 3
   time correct to within 33 ms
   polling server every 128 s
[root@mini-1 ~]#

 

手动同步时钟源

[root@mini-1 ~]# ntpdate ntp2.aliyun.com

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值