【Linux网络】系统调优之时间同步,搭建内网时间同步服务器

编程入门 行业动态 更新时间:2024-10-27 14:19:12

【Linux网络】系统调优之<a href=https://www.elefans.com/category/jswz/34/1771441.html style=时间同步,搭建内网时间同步服务器"/>

【Linux网络】系统调优之时间同步,搭建内网时间同步服务器

目录

一、时间同步是什么

二、时间同步实验

pc1的chrony配置修改:

pc2和pc3时间同步配置一样

关于时间调整再同步回来:ntpdate命令

最后,再总结一下(关于服务端口):

三、命令记录 


一、时间同步是什么

顾名思义就是时间保持一样,好处就是可以再生产中,可以有一台时间同步服务器将所有的设备时间一致,方便统一管理

二、时间同步实验

实验准备

计划准备2-3台主机,其中一台为时间同步服务器,理解为在内网中唯一可以访问外网的主机,将其作为时间同步服务器,另外2台客户机通过chrony配置,与其做到时间同步;

思路:pc1与阿里时间同步服务器同步,pc2和pc3与pc1同步

注意关闭安全机制和防火墙!!!

pc1的chrony配置修改:

pc2和pc3时间同步配置一样

关于时间调整再同步回来:ntpdate命令

 

最后,再总结一下(关于服务端口):

三、命令记录 

服务端

[root@localhost chrony]#setenforce 0
[root@localhost chrony]#systemctl stop firewalld[root@localhost ~]#vim /etc/chrony.conf# Use public servers from the pool.ntp project.
# Please consider joining the pool (.html).
#server 0.centos.pool.ntp iburst
#server 1.centos.pool.ntp iburst
#server 2.centos.pool.ntp iburst
#server 3.centos.pool.ntp iburst
这里是将官方的时间同步改为与阿里云同步的时间同步服务器
server ntp.aliyun iburst
server ntp1.aliyun iburst
server ntp2.aliyun iburst作为服务器的时候,允许哪些主机与自己时间同步
# Allow NTP client access from local network.
allow 192.168.20.8,192.168.20.10 
#allow 192.168.20.0/24
可以是单个ip地址,也可以是一个网段,可以理解为网络学习的acl规则开启允许关机也时间同步
# Serve time even if not synchronized to a time source.
local stratum 10重启一下服务
[root@localhost ~]#systemctl restart chronyd查看时间同步服务器
[root@localhost ~]#chronyc sources -v
210 Number of sources = 1.-- Source mode  '^' = server, '=' = peer, '#' = local clock./ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6    17     1  -3011us[+2076us] +/-   81ms解析一下域名,对应一下ip地址
[root@localhost ~]#nslookup ntp.aliyun
Server:		114.114.114.114
Address:	114.114.114.114#53Non-authoritative answer:
Name:	ntp.aliyun
Address: 203.107.6.88

客户端

[root@localhost ~]#rpm -qc chrony
/etc/chrony.conf
/etc/chrony.keys
/etc/logrotate.d/chrony
/etc/sysconfig/chronyd
[root@localhost ~]#vim /etc/chrony.conf[root@localhost ~]#vim /etc/chrony.conf# Use public servers from the pool.ntp project.
# Please consider joining the pool (.html).
#server 0.centos.pool.ntp iburst
#server 1.centos.pool.ntp iburst
#server 2.centos.pool.ntp iburst
#server 3.centos.pool.ntp iburst
这里是将官方的时间同步改为192.168.20.18
server 192.168.20.18 iburst[root@localhost ~]#systemctl restart chronyd
[root@localhost ~]#chronyc sources -v
210 Number of sources = 1.-- Source mode  '^' = server, '=' = peer, '#' = local clock./ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? 192.168.20.18                 0   7     0     -     +0ns[   +0ns] +/-    0ns

修改时间验证一下

[root@localhost ~]#date -s '-10 days'
2023年 11月 01日 星期三 16:55:04 CST
[root@localhost ~]#ntpdate 192.168.20.18
11 Nov 16:55:24 ntpdate[60492]: step time server 192.168.20.18 offset 863999.999104 sec
[root@localhost ~]#date
2023年 11月 11日 星期六 16:57:29 CST
[root@localhost ~]#date -s '-10 days'
2023年 11月 01日 星期三 17:04:49 CST
[root@localhost ~]#ntpdate ntp.aliyun 
11 Nov 17:05:16 ntpdate[60609]: step time server 203.107.6.88 offset 863999.993853 sec
[root@localhost ~]#date
2023年 11月 11日 星期六 17:05:20 CST
[root@localhost ~]#date -s '-10 days'
2023年 11月 01日 星期三 17:14:21 CST
[root@localhost ~]#systemctl restart chronyd
[root@localhost ~]#date
2023年 11月 01日 星期三 17:14:42 CST
[root@localhost ~]#date
2023年 11月 11日 星期六 17:14:53 CST
[root@localhost ~]#

更多推荐

【Linux网络】系统调优之时间同步,搭建内网时间同步服务器

本文发布于:2023-11-15 06:52:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   内网   服务器   系统   网络

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!