系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64

软件版本:chrony-3.1-2.el7.centos.x86_64

     ntp-4.2.6p5-25.el7.centos.2.x86_64

     ntpdate-4.2.6p5-25.el7.centos.2.x86_64

一、NTPd作为时间服务器

1、安装

# yum install ntp

2、修改配置文件

restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict :: #系统若启用了ipv6,该项必须保留,否则会报错
#增加允许查询的网络范围
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
restrict 10.20.20.0 mask 255.255.255.0 nomodify notrap
#修改或保持默认的时间服务器列表
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst

restrict的参数说明:

ignore:拒绝连接到NTP服务器
nomodiy: 忽略所有改变NTP服务器配置的报文,但可以查询配置信息
noquery: 忽略所有mode字段为6或7的报文,客户端不能改变NTP服务器配置,也不能查询配置信息
notrap: 不提供trap远程登录功能,trap服务是一种远程时间日志服务。
notrust: 不作为同步的时钟源。
nopeer: 提供时间服务,但不作为对等体。
kod: 向不安全的访问者发送Kiss-Of-Death报文

3、配置防火墙并启动服务

# iptables -I INPUT -m state --state NEW -m udp -p udp --dport  -j ACCEPT
# iptables-save >/etc/sysconfig/iptables
# systemctl start ntpd.service
# systemctl enable ntpd.service

4、确认服务运行正常

# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+biisoni.miuku.n 207.224.49.219 u 188.586 -5.387 19.552
---. 211.22.103.157 u 44.326 -6.224 13.534
*85.199.214.100 .GPS. u 224.549 4.580 2.672
+ntp8.flashdance 194.58.202.148 u 241.409 -18.026 30.000

二、chrony作为时间服务器

1、安装

# yum install chrony

2、修改配置文件

#使用默认的时间服务器或指定其他服务器
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst
server .centos.pool.ntp.org iburst
#允许查询的客户端范围
allow 192.168.10.0/
allow 10.20.20.0/

iburst参数:在一个标准的轮询间隔内没有应答,客户端会发送4个包给 NTP 服务器,以便在客户端首次快速同步时间

3、配置防火墙并启动服务

# iptables -I INPUT -m state --state NEW -m udp -p udp --dport  -j ACCEPT
# iptables-save >/etc/sysconfig/iptables
# systemctl start chrony.service
# systemctl enable chrony.service

4、确认服务运行正常

# chronyc sources
Number of sources =
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ ntp1.ams1.nl.leaseweb.net +17ms[ +17ms] +/- 241ms
^+ ---.HINET-IP.> 38m +8127us[ +14ms] +/- 93ms
^? ---.HINET-IP.> 36m +12ms[ +20ms] +/- 84ms
^* makaki.miuku.net +7939us[ +11ms] +/- 242ms

三、NTP客户端

1、使用NTP服务器软件

把上面配置中的server替换成内部NTP服务器即可
server 10.20.20.2 prefer
server 10.20.20.3 iburst

使用prefer参数将优先使用该服务器

2、使用ntpdate

安装ntpdate,并修改/etc/ntp/step-tickers。当然也可以使用默认的公共时间服务器

# vi /etc/ntp/step-tickers

#.centos.pool.ntp.org
10.20.20.2 iburst # systemctl start ntpdate.service
# systemctl enable ntpdate.service

这里同样支持iburst或prefer等参数

参考

https://www.server-world.info/en/note?os=CentOS_7&p=ntp&f=1

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-configuring_ntp_using_the_chrony_suite

CentOS7下部署NTP Server的更多相关文章

  1. Centos7下部署两套python版本并存

    Centos7下部署两套python版本并存   需求说明:centos7.2系统的开发机器上已经自带了python2.7版本,但是开发的项目中用的是python3.5版本,为了保证Centos系统的 ...

  2. CentOS7下部署rsync服务

    说明: 在CentOS7下部署rsync服务和在CentOS6上部署基本上是一样的,只是CentOS7自带了rsyncd启动脚本,由systemd管理而已. rsync服务端配置 [root@SERV ...

  3. CentOS7下部署java+tomcat+mysql项目及遇到的坑

    CentOS 7 下安装部署java+tomcat+mysql 前置:CentOS7安装:https://jingyan.baidu.com/article/b7001fe1d1d8380e7382d ...

  4. centos7下部署elasticSearch集群

    OS:Centos7x虚拟机 1H2Gjdk:1.8elasticsearch:5.6.0 单节点配置请参考:centos7下elasticSearch安装配置 配置master节点 # 在配置文件的 ...

  5. Centos7下部署ceph 12.2.1 (luminous)集群及RBD使用

    前言 本文搭建了一个由三节点(master.slave1.slave2)构成的ceph分布式集群,并通过示例使用ceph块存储. 本文集群三个节点基于三台虚拟机进行搭建,节点安装的操作系统为Cento ...

  6. centos下部署NTP时间服务器同步环境记录

    1)服务端部署 安装所需软件包 [root@test ~]# yum -y install ntp ntpdate 服务端自己先手工同步一次时间. [root@test ~]# ntpdate ntp ...

  7. 转载:CentOS7下部署Django项目详细操作步骤

    部署是基于:centos7+nginx+uwsgi+python3+django 之上做的 文章转自:Django中文网        https://www.django.cn/article/sh ...

  8. centos7下部署FastDFS分布式文件系统

    前言 项目中用到文件服务器,有朋友推荐用FastDFS,所以就了解学习了一番,感觉确实颇为强大,在此再次感谢淘宝资深架构师余庆大神开源了如此优秀的轻量级分布式文件系统,本篇文章就记录一下FastDFS ...

  9. centos7下部署Django(nginx+uwsgi+python3+django)

    系统版本 centos7 python版本 使用官方python3.6.3正式版 django版本 使用本文发布时最新的1.11.7 uwsgi版本 使用本文发布时最新的2.0.15 nginx版本 ...

随机推荐

  1. 异常处理的设计与重构 pdf

    百度网盘: https://pan.baidu.com/s/1hsQIEGk

  2. python文件操作与字符编码

    知识内容: 1.文件对象与文件处理流程 2.基本操作 3.上下文管理 4.文件的修改与文件内光标的移动 5.字符编码 一.文件对象与文件处理流程 1.文件对象 (1)文件分类 按文件中数据的组织形式可 ...

  3. string hashcode 解读

    偶尔看到string hashcode方法如下 public int hashCode() { int h = hash; if (h == 0 && value.length > ...

  4. QT中使用自己定的类和Vector出现错误

    关于QT自定义类不能调用问题: 在Main()函数里面一定要定义include“XXX.cpp”include“XXX.h”,具体原因我也不知道为什么这样定义,是在一个贴吧看见的,弄了好久才解决. 第 ...

  5. tornado-通过判断后台数据限制登陆--简单的

    import tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 import tornado.options # 提供 ...

  6. 循环神经网络(RNN)

    1.    场景与应用 在循环神经网络可以用于文本生成.机器翻译还有看图描述等,在这些场景中很多都出现了RNN的身影. 2.    RNN的作用 传统的神经网络DNN或者CNN网络他们的输入和输出都是 ...

  7. centos7环境下的Mysql5.7.22安装

    参考网站: https://blog.csdn.net/vipbupafeng/article/details/80271089 1.下载 官网链接:https://dev.mysql.com/dow ...

  8. 15. Studio上字符串转整形、整形转字符串例子

    var v1=ABS_SQLVALUE("select 1 from dual");var v2=ABS_SQLVALUE("select 2 from dual&quo ...

  9. Redis 集合 set 操作, 有序集合

    01, 唯一性, 确定性, 无序性 ( 结合的三大特性 ) 02, 新建集合, 或者往集合中添加数据 => sadd key value1 value2 value3 ....... 03, 查 ...

  10. MYSQL三大范式

    第一范式:确保每列的原子性. 第一范式是最基本的范式. 数据库表中的字段都是单一属性的,不可再分. 只要是关系数据库都满足第一范式 如果每列(或者每个属性)都是不可再分的最小数据单元(也称为最小的原子 ...