首页 > 编程知识 正文

架设ntp服务器,手动添加ntp服务器

时间:2023-05-06 03:12:14 阅读:235709 作者:3190

离线NTP服务器搭建(Linux)

如果没能帮你解决问题,请在下方留言

实例:
服务端-192.168.111.143
客户端-192.168.111.170

1. 获取rpm包
解压操作系统的镜像文件,获取rpm包
.CentOS-7.4-x86_64-DVD-1708Packages
2. 安装rpm

rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpmrpm -ivh ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpmrpm -ivh ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm

3. 设置服务器时间
查看当前时区

timedatectl

如果不是预期的时区,继续执行以下步骤
查看时区完整名称

timedatectl list-timezones | grep Shanghai

设置服务器的时区为香港时区

timedatectl set-timezone Asia/Hong_Kong

手动配置当前时间

timedatectl set-time "2019-07-17 14:45:10"

写入硬件时钟

hwclock --hctosys

重启

reboot

查看配置结果

date

4. 修改/etc/ntp.conf文件

服务端:

rm -rf /etc/ntp.confvi /etc/ntp.conf

将以下内容写进文件

#系统时间与BIOS事件的偏差记录 driftfile /var/lib/ntp/drift #允许任何主机进行时间同步 restrict default ignore #确保服务器本身有足够权限 restrict 127.0.0.1 restrict ::1 #授权192.168.0.0网段上的所有机器可以从这台机器上查询和同步时间. restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap server 192.168.111.143 iburst #当外部时间不可用时,使用本地时间. server 127.127.1.0 fudge 127.127.1.0 stratum 10 interface ignore wildcard interface listen 192.168.111.143 interface listen 127.0.0.1 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor

5. 停止ntpd时钟服务

service ntpd stop

6. 设置不与网络服务同步

timedatectl set-ntp no

7. 开启ntp服务

service ntpd start

8. 查看ntp服务状态

service ntpd status

9. 设置开机自启动

systemctl enable ntpd

客户端:

rm -rf /etc/ntp.confvi /etc/ntp.confdriftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 server 192.168.111.143 iburst restrict 192.168.111.143 nomodify notrap noquery server 127.127.1.0 fudge 127.127.1.0 stratum 10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor

10. 连接NTP服务器同步时间

ntpdate 192.168.111.143

11. 开启ntp服务

service ntpd start

12. 设置开机自启动

systemctl enable ntpd

13. 结果检查

timedatectl

14. 查看客户端的时间和时区是否和服务端保持一致,NTP 同步是否开启

watch ntpq -pchkconfig --level 35 ntpd on

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。