Ntp时间服务器

    NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

NTP服务器就是利用NTP协议提供时间同步服务的。

     时间对服务器之间的通信,信息交流非常重要

    一般情况下我们可以同步时间服务器,例如:ntp1.aliyun.com

  0.0.0 普通机器时间同步定时任务

crontab -e
#sync time by yanshichneg 2018
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1

 

1.1.1 Ntp服务器搭建

[root@Linux-node6-example ~]# rpm -qa ntp
ntp-4.2.6p5-28.el7.centos.x86_64

yum -y install ntp

1.1.2 修改ntp配置文件

[root@oldboyedu ~]# vim /etc/ntp.conf
#控制时间服务器同步权限
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# 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 ntp1.aliyun.com
server time.nist.gov

#sed替换
[root@Linux-node6-example ~]# sed -i.bak '8s#restrict.*noquery#restrict default nomodify#;21,24d;20a server ntp1.aliyun.com\nserver time.nist.gov' /etc/ntp.conf 

1.1.3 启动

[root@Linux-node6-example ~]# systemctl start ntpd
[root@Linux-node6-example ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2018-09-04 20:34:16 CST; 6s ago

1.1.4 检查

#查看上级时间服务器的状态
[root@Linux-node6-example ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   10.137.53.7      2 u   50   64    1   45.899    0.364   0.000
 time-b-wwv.nist .INIT.          16 u    -   64    0    0.000    0.000   0.000
#查看时间同步状态

  [root@Linux-node6-example ~]# ntpstat
  synchronised to NTP server (120.25.115.20) at stratum 3
  time correct to within 980 ms
  polling server every 64 s

 

1.1.5 客户端使用ntp服务器

[root@Linux-node7-example ~]# ntpdate 192.168.10.22
 4 Sep 20:39:55 ntpdate[33164]: adjust time server 192.168.10.22 offset 0.004388 sec

#放入定时任务

crontab -e
#sync time by yanshichneg 2018
*/5 * * * * /usr/sbin/ntpdate 192.168.10.22 >/dev/null 2>&1

 

转载于:https://www.cnblogs.com/yanshicheng/p/9588387.html

### 配置和使用NTP时间服务器 #### Windows平台下的NTP时间服务器配置 在Windows平台上,可以通过修改注册表来启用NTP服务器功能。具体操作是在路径`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer`下找到名为「Enabled」的键值并将其设置为1[^1]。此操作会激活NTP Server服务,默认情况下该服务并未开启。 #### Linux平台下的NTP时间服务器配置 对于Linux系统而言,无论是基于RedHat系还是Debian系的操作系统都可以通过安装ntp软件包来进行NTP时间服务器的相关配置。以CentOS为例,可以利用yum工具完成ntp程序包的部署;而针对Ubuntu,则可采用apt-get实现相同目的[^2]。 ##### 安装ntp服务 确认是否已经安装了ntp服务是非常重要的第一步。如果尚未安装,可以根据所使用的发行版执行相应的命令进行安装。 ##### 修改配置文件/etc/ntp.conf 编辑位于根目录下的ntp.conf文件,主要涉及以下几个方面的调整: - **权限管理** 设置哪些网络地址能够访问您的NTP服务器至关重要。这通常涉及到添加或修改restrict指令的内容。例如,为了允许来自特定IPv4子网(如192.168.100.0/24)内的设备连接至NTP服务器,可以在配置文件中加入如下行: ```bash restrict 192.168.100.0 mask 255.255.255.0 nomodify ``` - **指定上游时间源** 可以为本地NTP服务器定义多个上级时间源作为参考标准。这些时间源既可以是公共互联网上的权威时间服务器也可以是其他内部网络中的可靠节点。下面是一个例子展示如何指向上游时间提供者: ```bash server 220.130.158.71 prefer server 59.124.196.83 server 59.124.196.84 ``` - **内置时钟选项** 当无法获取外部精确时间信号时,考虑使用系统的内部计时器作为一种退化模式下的解决方案也是合理的做法之一。不过需要注意适当降低其层次等级以免影响整体精度。 ```bash server 127.127.1.0 fudge 127.127.1.0 stratum 10 ``` - **日志记录与密钥支持** 对于长期稳定运行来说,保持漂移数据的日志有助于后续维护工作开展。同时还可以引入加密机制提高安全性。 ```bash driftfile /var/lib/ntp/drift keys /etc/ntp/keys ``` ##### 启动及验证ntp服务状态 最后一步便是确保ntpd进程正常启动并且持续监听端口等待请求到来。依据不同版本控制系统间可能存在些许差异,请参照以下指导原则操作: ```bash # CentOS 7及以上版本 systemctl start ntpd.service systemctl enable ntpd.service # CentOS 6及其更低版本 service ntpd start chkconfig ntpd on ``` 另外值得注意的一点在于刚初始化完毕后的短时间内可能不会立即看到预期效果因为存在一定的同步延迟现象[^3][^4]。 #### 常见问题排查技巧 假如遇到诸如“no server suitable for synchronization found”的报错提示信息,则建议耐心等候一段时间直至reach字段达到预定数值后再重新尝试发起新的同步动作。此外借助调试模式可以帮助定位潜在故障原因所在位置: ```bash ntpdate -d <server_address> ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值