离线NTP服务器搭建(Linux)

离线NTP服务器搭建(Linux)

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

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

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

rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpm
rpm -ivh ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm
rpm -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.conf
vi /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.conf
vi /etc/ntp.conf
driftfile /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 -p
chkconfig --level 35 ntpd on
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值