
正文
Linux NTP时间服务器
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
NTP 时间服务器
ntp也是一种协议
ntp软件(支持ntp协议) CentOS6自带 CentOS7需要安装
chrony软件(支持ntp协议) CentOS7自带
安装ntp
CentOS6系统自带ntp,CentOS7需要自己安装
[root@m02 ~]# yum -y install ntp
[root@m02 ~]# rpm -qa ntp
ntp-4.2.6p5-.el7.centos..x86_64
配置ntp权限参数含义
noquery:不提供ntp服务
notrap:不提供trap远程事件登录的功能
nomodiy:表示客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间矫正
notrust:拒绝没有通过认证的客户端
nokod:kod技术可以组织一种dos攻击
ignore :关闭所有ntp服务
配置文件更改
noquery:不提供ntp服务
notrap:不提供trap远程事件登录的功能
nomodiy:表示客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间矫正
notrust:拒绝没有通过认证的客户端
nokod:kod技术可以组织一种dos攻击
ignore :关闭所有ntp服务
更改之前可以备份一下,以防改错
[root@m02 ~]# vim /etc/ntp.conf
server ntp1.aliyun.com 加上这个,因为默认是国外的时间同步服务器,使用国外的相对于使用阿里的,速度对比可想而知。
加权限限制
格式:restrict IP 权限参数
IP可以为ip地址或者default
权限参数:nomodify notrap nopeer noquery
例如:restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
ntp服务改后和改前配置文件对比
[root@m02 ~]# diff /etc/ntp.conf{,.ori}
18c18
< restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
---
>
21d20
< server ntp1.aliyun.com
启动ntp
[root@m02 ~]# systemctl start ntpd
服务端可以先查看一下
利用ntpq -p命令和ntpstat命令
[root@m02 ~]# ntpq -p #显示上一级连接的服务器
remote refid st t when poll reach delay offset jitter
==============================================================================
*time5.aliyun.co 10.137.38.86 u 4.209 3.841 2.685
time-d-b.nist.g .STEP. u - 0.000 0.000 0.000
[root@m02 ~]# ntpstat #显示同步结果 现在的状态信息
synchronised to NTP server (182.92.12.11) at stratum
time correct to within ms
polling server every s
客户端测试结果
客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。
而且同步有时会很慢
ntpdate -d 显示同步过程
[root@Cobbler ~]# ntpdate 172.16.1.62
Nov :: ntpdate[]: adjust time server 172.16.1.62 offset -0.002221 sec
[root@Cobbler ~]# ntpdate -d 172.16.1.62
Nov :: ntpdate[]: ntpdate 4.2.6p5@1.2349-o Wed Apr :: UTC ()
Looking for host 172.16.1.62 and service ntp
host found : 172.16.1.62
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
server 172.16.1.62, port
stratum , precision -, leap , trust
refid [172.16.1.62], delay 0.02592, dispersion 0.00142
transmitted , in filter
reference time: ddb7c566.e8e2acda Thu, Nov ::58.909
originate timestamp: ddb7c665.aa402c9b Thu, Nov ::13.665
transmit timestamp: ddb7c665.abf2c8a8 Thu, Nov ::13.671
filter delay: 0.02592 0.02596 0.02597 0.02599
0.00000 0.00000 0.00000 0.00000
filter offset: -0.00994 -0.00890 -0.00785 -0.00686
0.000000 0.000000 0.000000 0.000000
delay 0.02592, dispersion 0.00142
offset -0.009942 Nov :: ntpdate[]: adjust time server 172.16.1.62 offset -0.009942 sec
step和adjust的区别
[root@Cobbler ~]# date -s 20080101
Tue Jan :: CST
[root@Cobbler ~]# ntpdate 172.16.1.62
Nov :: ntpdate[]: step time server 172.16.1.62 offset 311703675.400154 sec
说明: adjust和step,adjust同步时间的时候小于一秒,step同步时间的时候大于一秒
CentOS7自带软件chrony配置文件
vim /etc/chrony.conf
内容和ntp是一样的,知识顺序颠倒了
systemctl status chronyd 查看状态
注意:chrony 不能和ntp同时存在 只有centos7上有chrony
vim /etc/chrony.conf
内容和ntp是一样的,知识顺序颠倒了
systemctl status chronyd 查看状态
注意:chrony 不能和ntp同时存在 只有centos7上有chrony






