大家好,我是沈工,一位喜欢结交朋友的资深通信技术爱好者,同时也是业内人士!
今天我们要聊聊:LINUX时钟服务搭建及数通设备时钟同步设置-Centos搭建时钟服务器①
- Let‘s Go-
NTP时钟服务器用于网络内设备保持时间同步,用于对时间一致性需求高的业务。比如日志信息、录像时间、通话时间等等
Last login: Thu Apr 2 14:26:32 2026 from 192.168.2.158[bg2etu@localhost ~]$ ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:bd:41:5b brd ff:ff:ff:ff:ff:ff inet 192.168.2.43/24 brd 192.168.2.255 scope global noprefixroute ens33 //当前服务器网卡及IP地址 valid_lft forever preferred_lft forever3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:84:ad:6b brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:84:ad:6b brd ff:ff:ff:ff:ff:ff5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:86:10:b1:b2 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever7: veth54c1317@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group defa ult link/ether 02:24:78:6b:91:05 brd ff:ff:ff:ff:ff:ff link-netnsid 0[bg2etu@localhost ~]$ ping www.baidu.com //服务器与互联网保持连接获取准确时间(或者自建GPS\北斗\GLONASS的时钟服务器)PING www.a.shifen.com (183.2.172.177) 56(84) bytes of data.64 bytes from 183.2.172.177 (183.2.172.177): icmp_seq=1 ttl=48 time=68.0 ms64 bytes from 183.2.172.177 (183.2.172.177): icmp_seq=2 ttl=48 time=65.0 ms64 bytes from 183.2.172.177 (183.2.172.177): icmp_seq=3 ttl=48 time=68.2 ms--- www.a.shifen.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2003msrtt min/avg/max/mdev = 65.028/67.108/68.244/1.503 ms[root@localhost /]# rpm -qa | grep ntp //查询系统是否安装NTP模块fontpackages-filesystem-1.44-8.el7.noarchpython-ntplib-0.3.2-1.el7.noarch[root@localhost /]# yum install ntp ntp date //安装NTP模块已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* epel: ftp.iij.ad.jp* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com没有可用软件包 date。正在解决依赖关系--> 正在检查事务---> 软件包 ntp.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装--> 正在处理依赖关系 ntpdate = 4.2.6p5-29.el7.centos.2,它被软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要--> 正在检查事务---> 软件包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装--> 解决依赖关系完成依赖关系解决===============================================================================================================Package 架构 版本 源 大小===============================================================================================================正在安装:ntp x86_64 4.2.6p5-29.el7.centos.2 base 549 k为依赖而安装:ntpdate x86_64 4.2.6p5-29.el7.centos.2 base 87 k事务概要===============================================================================================================安装 1 软件包 (+1 依赖软件包)总下载量:635 k安装大小:1.5 MIs this ok [y/d/N]: yDownloading packages:(1/2): ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm | 87 kB 00:00:00(2/2): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:00:01---------------------------------------------------------------------------------------------------------------总计 402 kB/s | 635 kB 00:00:01Running transaction checkRunning transaction testTransaction test succeededRunning transaction正在安装 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/2正在安装 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2验证中 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/2验证中 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2已安装:ntp.x86_64 0:4.2.6p5-29.el7.centos.2作为依赖被安装:ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2完毕![root@localhost]# rpm -qa | grep ntpntpdate-4.2.6p5-29.el7.centos.2.x86_64 //安装完成ntpdatefontpackages-filesystem-1.44-8.el7.noarchpython-ntplib-0.3.2-1.el7.noarchntp-4.2.6p5-29.el7.centos.2.x86_64 //安装完成ntp[root@localhost /]# cd etc [root@localhost etc]# vim ntp.conf
添加新的时钟服务器地址
server 127.127.1.0 //将当前主机作为时间服务器fudge 127.127.1.0 stratum 5 //fudge和server必须一起用 stratum 5代表层数在ntp.conf配置文件添加以上两条信息,目的是让时钟服务器与自身同步,使用local时间作为ntp服务提供给终端使用。
127.127.1.0 是 NTP 协议中用于表示本地系统时钟的伪 IP 地址,并非真实的网络接口地址或公网 IP。该地址专用于网络时间协议(NTP)的配置文件中,指代本机硬件时钟作为时间源。
[root@localhost /]# systemctl start ntpd.service //启动ntp服务[root@localhost /]# systemctl enable ntpd.service //设置ntp服务开启启动Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.[root@localhost /]# systemctl status ntpd.service //查看ntp服务和设置开机启动的状态● ntpd.service - Network Time ServiceLoaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)Active: active (running) since 四 2026-04-02 15:28:18 CST; 24s agoMain PID: 30563 (ntpd)CGroup: /system.slice/ntpd.service └─30563 /usr/sbin/ntpd -u ntp:ntp -g4月 02 15:28:18 localhost.localdomain ntpd[30563]: Listen normally on 2 lo 127.0.0.1 UDP 1234月 02 15:28:18 localhost.localdomain ntpd[30563]: Listen normally on 3 ens33 192.168.2.43 UDP 1234月 02 15:28:18 localhost.localdomain ntpd[30563]: Listen normally on 4 virbr0 192.168.122.1 UDP 1234月 02 15:28:18 localhost.localdomain ntpd[30563]: Listen normally on 5 docker0 172.17.0.1 UDP 1234月 02 15:28:18 localhost.localdomain ntpd[30563]: Listening on routing socket on fd #22 for interface updates4月 02 15:28:18 localhost.localdomain ntpd[30563]: 0.0.0.0 c016 06 restart4月 02 15:28:18 localhost.localdomain ntpd[30563]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM4月 02 15:28:18 localhost.localdomain ntpd[30563]: 0.0.0.0 c011 01 freq_not_set4月 02 15:28:18 localhost.localdomain systemd[1]: Started Network Time Service.4月 02 15:28:19 localhost.localdomain ntpd[30563]: 0.0.0.0 c514 04 freq_modeHint: Some lines were ellipsized, use -l to show in full.[root@localhost /]# ntpq -p remote refid st t when poll reach delay offset jitter==============================================================================47.96.149.233 100.100.61.91 2 u 40 64 1 55.406 7.486 0.000203.107.6.88 100.107.25.114 2 u 39 64 1 35.999 6.987 0.000*LOCAL(0) .LOCL. 5 l 38 64 1 0.000 0.000 0.000实时查看时钟同步情况

时钟服务查询结果参数解释
时钟服务器需要关闭防火墙或者在防火墙规则中放行UDP协议 | 123端口
<Huawei>undo terminal monitor Info: Current terminal monitor is off.<Huawei>system-view Enter system view, return user view with Ctrl+Z.[Huawei]vlan 254[Huawei-vlan254]quit[Huawei]interface Vlanif 254[Huawei-Vlanif254]ip address 192.168.2.43 24[Huawei-Vlanif254]quit[Huawei]interface GigabitEthernet 0/0/1[Huawei-GigabitEthernet0/0/1]port link-type access [Huawei-GigabitEthernet0/0/1]port default vlan 254[Huawei-GigabitEthernet0/0/1]quit[Huawei]quit<Huawei>clock timezone Beijing add 08:00:00<Huawei>system-view Enter system view, return user view with Ctrl+Z.[Huawei]ntp-service refclock-master 8 //声明自身为NTP主时钟(层级8,1-15均可,<16表示时间可靠)[Huawei]ntp-service authentication enable //[Huawei]ntp-service authentication-keyid 8 authentication-mode md5 admin123456[Huawei]ntp-service reliable authentication-keyid 8[Huawei]ntp-service source-interface Vlanif 254[Huawei]ntp-service sync-interval 600[Huawei]quit<Huawei>save<Huawei>dis ntp-service status clock status: synchronized clock stratum: 8 reference clock ID: LOCAL(0)nominal frequency: 64.0000 Hz actual frequency: 64.0000 Hz clock precision: 2^11clock offset: 0.0000 ms root delay: 0.00 ms root dispersion: 0.00 ms peer dispersion: 10.00 ms reference time: 07:03:35.250 UTC Apr 3 2026(ED79E4C7.40213A0C)synchronization state: clock set but frequency not determined 