首页 > 其他分享 >时间同步 ntp服务器

时间同步 ntp服务器

时间:2023-07-26 14:56:16浏览次数:29  
标签:同步 ntp 192.168 restrict 0.0 服务器 pool

目录

一. 定义

#01 简介:ntp全名 network time protocol 。NTP服务器可以为其他主机提供时间校对服务

#02 ntp和ntpdate区别
1) 两个服务都是centos自带的(centos7中不自带ntp)。ntp的安装包名是ntp;ntpdate的安装包是ntpdate。他们并非由一个安装包提供。
2) ntp守护进程为ntpd,配置文件是/etc/ntp.conf
3) ntpdate用于客户端的时间矫正,非NTP服务器可以不启动NTP。

二. 项目要求

## 由于容器内时区不对,且无外网环境,需要ntp服务器 进行时间同步

## 准备两台服务器 一台作为NTP服务器,另一台作为client端向服务器同步时间测试。

服务器 IP 备注
NTP服务端 192.168.5.15 Cenost7
客户端 192.168.5.9 ubuntu (docker 容器内)

三. 部署服务端

#01 安装并启动
yum install -y ntp
service ntpd start

#02 修改配置文件
[root@kq_mysql ~]# grep -Ev '^$|^#' /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap     #允许同步的网段
restrict 127.0.0.1                                          #设置为时间同步主服务器
restrict ::1
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 127.127.1.0 prefer																		#设置本机为NTP服务器
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

注意:这里只添加下面两行即可
    server 127.127.1.0 prefer   #设置本机为NTP服务器
    restrict 192.168.5.0        #允许客户端156.0.26.7向本机请求时间同步
    restrict 192.168.5.0  mask 255.255.255.0 #允许客户端156.0.26.0网段的所有主机向本机请求时间同步


#03 启动检查
1)检查进程
[root@kq_mysql ~]# service ntpd start
Redirecting to /bin/systemctl start ntpd.service
[root@kq_mysql ~]# netstat -tunlp |grep ntp
udp        0      0 172.17.0.1:123          0.0.0.0:*                           16712/ntpd
udp        0      0 172.18.0.1:123          0.0.0.0:*                           16712/ntpd
udp        0      0 192.168.5.15:123        0.0.0.0:*                           16712/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           16712/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           16712/ntpd
udp6       0      0 :::123                  :::*                                16712/ntpd

2)检查服务
[root@kq_mysql ~]# ntpq  -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+stratum2-1.ntp. 194.190.168.1    2 u   56   64  377  102.792   -0.286   6.553
+119.28.206.193  100.122.36.196   2 u   65   64  377   51.545    0.244  10.349
+ntp1.flashdance 194.58.202.20    2 u   65   64  377  289.813   16.525  13.405
+tick.ntp.infoma .GPS.            1 u   55   64  377  147.590    6.641   8.143
*LOCAL(0)        .LOCL.           5 l   32   64  377    0.000    0.000   0.000


	解释下:ntpq  -p:此命令可以列出当前主机的NTP和上层NTP的状态。
	

四. 部署客户端

#01 安装服务
apt-get install -y ntp

#02 修改配置文件
root@centos_4c8g:/# grep -E -v '^$|^#' /etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
pool ntp.ubuntu.com
server 192.168.5.15                                                     #设置上游的服务器
restrict 192.168.5.15 nomodify notrap noquery                           #允许上游服务器修改本本机IP
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery


客户端需要修改/etc/ntp.conf,添加以下内容
  server 192.168.5.15    															#指名上层NTP服务器
  restrict 192.168.5.15  															#放行156.0.26.6
  restrict 192.168.5.15 nomodify notrap noquery   		 #允许上游服务器修改本本机IP
	


#03 启动 检查
root@centos_4c8g:/# ntpd
root@centos_4c8g:/# ntpq  -p


标签:同步,ntp,192.168,restrict,0.0,服务器,pool
From: https://www.cnblogs.com/saas-open/p/17582448.html

相关文章

  • 流媒体协议之WebRTC简易服务器搭建20230726
    流媒体协议之WebRTC简易服务器搭建1.简介        由于官网的peerconnection_server和apprtc对SDP以及登录流程有特定要求,不便于调试自己实现的WebRTC,所以计划自己搭建服务器,网上开源的服务器有很多:licode/janus/kurento/mediasoup/jitsi等等,但是这些服务器的搭建又比较......
  • Docker部署之使用docker-compose部署(全新的干净的服务器,从0开始搭建)
    部署环境准备安装yum#安装yum工具yuminstall-yyum-utilsdevice-mapper-persistent-datalvm2--skip-broken安装dcoker#设置docker镜像源yum-config-manager--add-repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reposed-i's/download.d......
  • 使用maxwell实现数据库主从同步
    前置条件maxwell使用1.29.2版本,再高的版本不支持JDK1.8。使用Maxwell之前需要准备搭建以下环境 在https://www.cnblogs.com/szhNJUPT/p/17574193.html有详细搭建过程mysql采用5.7.43,尝试过mysql8.0版本,但是由于utf8mb3字符集在mysql8.0版本被舍弃,导致maxwell连接失败。数据......
  • linux服务器性能调优(udp为主)
    udp的好处很明显,效率高,减少了建立连接的流程,减少了报文头的占比,也减少了维护连接的开销。缺点就是不稳定,会丢包。还有就是由于udp的高效,导致用于udp的一些应用开发,并发都比较大,更容易丢包。io复用SO_REUSEADDRSO_REUSEPORT创建listener用来监听数据时,有时候需要配置io复用。也......
  • nginx实现服务器端集群搭建(五)
    nginx与tomcat部署环境准备(tomcat)1.准备Tomcat环境,并在Tomcat上部署一个web项目2.准备Nginx环境,使用Nginx接收请求,并把请求分发到Tomat上3、浏览器访问:http://192.168.200.146:8080/demo/index.html获取动态资源的连接地址http://192.168.200.146:8080/demo/getAddress......
  • 服务器防火墙,放行443端口,命令
    查看服务器防火墙是什么iptables和firewalld都是用于配置Linux系统防火墙的工具。两者的主要差异在于使用的命令和配置语法的不同。iptables是传统的防火墙工具,适用于几乎所有的Linux发行版,而firewalld更加适用于最新的CentOS7和RHEL7系统。命令sudofirew......
  • 万字长文浅析配置对MySQL服务器的影响
    有很多的服务器选项会影响这MySQL服务器的性能,比如内存中临时表的大小、排序缓冲区等。有些针对特定存储引擎(如InnoDB)的选项,也会对查询优化很有用。调整服务器的配置从某种程度来说是一个影响全局的行为,因为每个修改都可能对该服务器上的每个查询造成影响。不过有些选项是针对特......
  • 从另一电脑复制下来的MYSQL的数据文件(包括FRM IBD)快速恢复到另一MYSQL服务器过程
    从另一电脑复制下来的MYSQL的数据文件(包括FRMIBD)快速恢复到另一MYSQL服务器过程:1.安装mysql最好相同的版本,安装Navicateformysql,连接相应的服务器2.安装mysql-utilities,地址:https://downloads.mysql.com/archives/utilities/以恢复td_gov_company_abnormal.frm为例:3.C......
  • SRS 流媒体服务器部署及设计思路和一些想法
    1、参考地址SRSgithub地址:https://github.com/ossrs/srs自带的信令github地址:https://github.com/ossrs/signaling#usage中文文档:https://ossrs.net/lts/zh-cn/docs/v4/doc/introduction2、环境部署我是在centos上使用的源码编译模式,官方还提供了docker模式的,看文档中有介......
  • C# 控制台服务 调用cmd命令 重启重启重启 服务器上的指定windows服务
    先贴核心重启服务命令(没错先停止再开启合并成一句话用&连接)CMD管理员运行,直接输入下面语句进行重启。netstoprabbitmq&netstartrabbitmq完整C#代码:参数ServiceName是配置的重启服务名称(后缀没有.exe,例:RabbitMQ)Process命名空间引用:usingSystem.Diagnostics......