因为工作需要要在内网搭建NTP服务器来同步摄像机,服务器、PC机和网络设备时间,记录下搭建步骤。
一、windows搭建NTP服务器
搭建环境:windows 11专业版
方法一、修改注册表
在运行中输入“regedit”打开注册表,定位注册表项到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time
修改\TimeProviders\NtpServer项中AllowNonstandardModeCombinations和Enabled的值为1,如图
修改\Config项中AnnounceFlags值为5,如图
在运行中输入services.msc 打开服务,找到"windows time“服务,设置启动类型为自动,启动服务。即可
在cmd窗口中输入w32tm /stripchart /computer:127.0.0.1 ,如果有回显则服务正常。
注意:NTP服务使用123端口,如局域网不能同步成功,请检查防火墙。
方法二、保存以下注册表为.REG文件,双击导入即可
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config] "AnnounceFlags"=dword:00000005 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters] "Type"="NTP" [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer] "AllowNonstandardModeCombinations"=dword:00000001 "Enabled"=dword:00000001
二、linux 搭建NTP服务器
搭建环境:Centos 7
检查ntp服务是否已安装,CentOS7默认已安装,但未启用)
[root@localhost ~]# rpm -qa | grep ntp
如没有手动安装NTP服务
[root@localhost ~]# yum install ntp ntpdate -y
修改NTP配置文件,加黑部分为主要配置,添加NTP服务器地址
[root@localhost ~]# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift #会把时间误差记录下来写入driftfile,这样即使重新开机以后之前的计算结果也就不会丢失了 logfile /var/log/ntpd.log #新增日志目录 restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap #控制允许哪些网络查询和同步时间,这里允许192.168.10.0网段上的所有机器可以从这台机器上查询和同步时间 server 0.cn.pool.ntp.org iburst server 1.cn.pool.ntp.org iburst server 2.cn.pool.ntp.org iburst server 3.cn.pool.ntp.org iburst server 192.168.10.30 iburst #新增当外部时间不可用时可以使用本地时间 fudge 127.0.0.1 stratum 10 #startum为时间服务器的层次;设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0,默认为10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
启动服务并加入开机自启动项
[root@localhost ~]# systemctl restart ntpd ; systemctl enable ntpd
配置防火墙,允许访问NTP服务
[root@localhost ~]# firewall-cmd --permanent --add-service=ntp && firewall-cmd --reload
查看NTP状态
[root@localhost ~]# systemctl status ntpd | grep Active ; netstat -tlunp | grep ntp
查看同步信息
[root@localhost ~]# ntpq -p
还没有评论,来说两句吧...