一、安装ntp服务

首先检查服务器上是否已安装ntp服务:

[root@centos7 /]rpm -qa | grep ntp

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

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

如果有上述内容输出,测说明ntp服务已安装;否则需要安装ntp服务

[root@centos7 /]yum install -y ntpd

安装有yum、rpm、源码安装等多种方式,本次安装使用yum安装。如果服务器能联网,建议采用yum安装。

二、配置ntp

采用yum或rpm安装情况下,ntp的配置文件路径为/etc/ntp.conf

1、首先找到互联网上提供时间时间同步的ntp server

http://www.pool.ntp.org是NTP的官方网站,在这上面我们可以找到离我们城市最近的NTP Server. NTP建议我们为了保障时间的准确性,最少找两个个NTP Server。

比如在中国可以选择下面几台服务器

server 1.cn.pool.ntp.org

server 0.asia.pool.ntp.org

server 2.asia.pool.ntp.org

2、在配置之前最好先手动和上面的服务器同步一次时间,使服务器时间尽量接近标准时间

[root@centos7 /]ntpdate 1.cn.pool.ntp.org

假如你的时间差的很离谱的话第一次会看到调整的幅度比较大,所以保险起见可以运行两次。 那么为什么在打开NTP服务之前先要手动运行同步呢?1. 因为根据NTP的设置,如果你的系统时间比正确时间要快的话那么NTP是不会帮你调整的,所以要么你把时间设置回去,要么先做一个手动同步

2. 当你的时间设置和NTP服务器的时间相差很大的时候,NTP会花上较长一段时间进行调整.所以手动同步可以减少这段时间

3、配置/etc/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

# 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

# Hosts on local network are less restricted.

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

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

server 1.cn.pool.ntp.org  #向该服务器同步时间,下同

server 0.asia.pool.ntp.org

server 2.asia.pool.ntp.org

#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

####restrict参数####

#kod 使用kod技术防范“kiss of death”***

#ignore 拒绝任何NTP连接

#nomodify 用户端不能使用ntpc,ntpq修改时间服务器参数,但是可以进行网络校时

#noquery 用户端不能使用ntpc,ntpq查询时间服务器参数,不可以进行网络校时

#notrap 不提供远程日志功能

#notrust 拒绝没有认证的客户端

restrict 1.cn.pool.ntp.org nomodify notrap noquery

restrict 0.asia.pool.ntp.org nomodify notrap noquery

restrict 2.asia.pool.ntp.org nomodify notrap noquery

server 127.0.0.1

fudge 127.127.1.0 stratum 5

#设置本地时间级别是5,如果上级时间服务器均失效,对外发布本地时间,时间层级是4。

#这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0

# 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

配置好之后,启动ntp服务

[root@centos7 /]systemctl start ntpd

[root@centos7 /]ntpq -p #查询运行情况

更多细节

表头remote – 用于同步的远程节点或服务器。“LOCAL”表示本机 (当没有远程服务器可用时会出现)

refid – 远程的服务器进行同步的更高一级服务器

st – 远程节点或服务器的 Stratum(级别,NTP 时间同步是分层的)

t – 类型 (u: unicast(单播) 或 manycast(选播) 客户端, b: broadcast(广播) 或 multicast(多播) 客户端, l: 本地时钟, s: 对称节点(用于备份), A: 选播服务器, B: 广播服务器, M: 多播服务器, 参见“Automatic Server Discovery“)

when – 最后一次同步到现在的时间 (默认单位为秒, “h”表示小时,“d”表示天)

poll – 同步的频率:rfc5905建议在 NTPv4 中这个值的范围在 4 (16秒) 至 17 (36小时) 之间(即2的指数次秒),然而观察发现这个值的实际大小在一个小的多的范围内 :64 (26 )秒 至 1024 (210 )秒

reach – 一个8位的左移移位寄存器值,用来测试能否和服务器连接,每成功连接一次它的值就会增加,以 8 进制显示

delay – 从本地到远程节点或服务器通信的往返时间(毫秒)

offset – 主机与远程节点或服务器时间源的时间偏移量,offset 越接近于0,主机和 NTP 服务器的时间越接近(以方均根表示,单位为毫秒)

jitter – 与远程节点同步的时间源的平均偏差(多个时间样本中的 offset 的偏差,单位是毫秒),这个数值的绝对值越小,主机的时间就越精确

[root@centos7 /]ntpstat #查看是否同步状态,下图可以看出同步成功

如需其它服务器从本机同步时间,还需将ntp服务开放

[root@centos7 /]firewall-cmd --zone=public --add-service=ntp --permanent

[root@centos7 /]firewall-cmd --reload

最后设置开机启动

[root@centos7 /]systemctl enable ntpd

参考资料:http://www.centoscn.com/CentOS/config/2015/1105/6385.html

http://blog.csdn.net/iloli/article/details/6431757

linux7配置ntp服务器,centos7 搭建ntp服务器相关推荐

  1. linux7做服务器,centos7 搭建yum服务器

    准备工作 接下来就要开始正式的安装工作了,不过在正式开始之前,还需稍作准备,以确保实验的成功.由于yum服务器是在局域网里面为众多的客户机提供访问服务,所以要在防火墙上打开相应的访问端口,客户机才能进 ...

  2. centos下搭建网站服务器,Centos7搭建web服务器

    搭建web服务器  提供网站服务 1.配置IP地址 vim /etc/sysconfig/network-scripts/ifcfg-ens33 2.  启动 network服务    查看IP地址 ...

  3. Linux Centos7搭建邮件服务器

    Linux Centos7搭建邮件服务器 基于sendmail和Dovecot 一.关闭防火墙和selinux systemctl stop firewalld setenctoce 0 二.下载se ...

  4. centos7搭建CA服务器颁发ssl证书

    2019年12月16日 星期一 CQCEE 使用ssl来保证web通信安全 apache服务器与客户机采用明文通信 对HTTP传输加密的协议为HTTPS,是通过ssl进行http传输的协议,它通过公用 ...

  5. CentOS7搭建Git服务器

    CentOS7搭建Git服务器 文章目录 CentOS7搭建Git服务器 前言 搭建步骤 参考链接 前言 现有一台操作系统为CentOS 7的服务器,要将其作为代码库服务器使用,要求使用Git进行代码 ...

  6. Centos7搭建sftp服务器

    Centos7搭建sftp服务器 一.什么sftp服务器 二.安装sftp服务器 三.修改配置文件 四.测试sftp 一.什么sftp服务器 sftp是Secure File Transfer Pro ...

  7. 使用Zerotier在私有云服务器中搭建Moon服务器

    参考文章链接: 使用Zerotier在私有云服务器中搭建Moon服务器 – Rookie diary导读:我自己在家搭建了一台黑nas,由于使用需求,需要在外访问,但是通过frp又比较麻烦所以选用ze ...

  8. 【Android RTMP】RTMP 直播推流 ( 阿里云服务器购买 | 远程服务器控制 | 搭建 RTMP 服务器 | 服务器配置 | 推流软件配置 | 直播软件配置 | 推流直播效果展示 )

    文章目录 安卓直播推流专栏博客总结 一. 阿里云服务器购买 二. 远程服务器控制软件 三. 配置 Ubuntu 服务器 1 . 更新 apt 源 2 . 安装 pcre.OpenSSL.zlib 库 ...

  9. windowsServer服务器上搭建GIt服务器

    摸索了一天,终于把服务器端Git搭建完毕.记录下来,省的以后踩坑. 如下: 1.下载JavaSDK,通过oracle官网下载,网址: https://www.oracle.com/index.html ...

最新文章

  1. 征文 | “‘互联网+’背景下大数据与税收征管的深度融合研究” 专题征文启事...
  2. 电大本科计算机考试题库及答案,电大计算机考试题题库及答案.doc
  3. 【Python】Django生成API 文档
  4. 关于火狐中使用jquery的animate做动画效果的问题解决
  5. C++堆和栈详解(转)
  6. 5926. 买票需要的时间
  7. phpredis -- Redis编译安装,PHP 7 安装 Redis 扩展
  8. 【codevs1869】硬币购物,背包+神奇的容斥原理
  9. oracle rsm0进程,12c DG broker DMON自动重启过程分析
  10. 基于Spring+Struts2+Hibernate开发易买网商城系统
  11. 服务器装系统就蓝屏,重装了下系统老是蓝屏
  12. 数据质量检查【整理】
  13. jQuery实现一个备忘录
  14. Excel遇到错误div/0显示为0或者不显示
  15. 【Java版算法思想】双指针算法
  16. CSS3实现毛玻璃(图片模糊)效果
  17. 带alpha通道四通道的图片转成rgb三通道
  18. 小红书X千瓜联合发布|小红书2021年4月创作者红人榜
  19. 搭建VUE大屏展示项目(一)环境搭建
  20. 吴恩达 DeepLearning 第二课第三周题目(包括选择题)

热门文章

  1. Python每日一练19、简单的加减法数学游戏
  2. Markdown常用符号及排版
  3. 无线调制解调器的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  4. java课后习题及答案_《java基础入门》课后习题及答案.doc
  5. DDD(领域驱动设计)系列主题:失血模型,贫血模型,充血模型和胀血模型详细解读和代码案例说明!
  6. Android-Skillful-Craftsman(Android能工巧匠)
  7. VMProtect使用教程
  8. 虚拟摄像头之七:《详解 CameraService 都做了什么》之 CameraService 与 cameraclient 通讯
  9. 淡入淡出的图片轮显幻灯片类
  10. 将dlia.c拥塞控制算法文件以添加选项的方式编译到内核中去