ntp时间同步

安装

服务端与客户端都要执行安装

#yum install ntp ntpdate -y

配置

目录:/etc/ntp.conf

服务端

driftfile /var/lib/ntp/drift

logconfig all

restrict 127.0.0.1
restrict ::1

restrict default nomodify notrap nopeer noquery

# 因为是内网,没有外部网络,所以注释以下server
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

# 表示从本机获取时间
server 127.127.1.0
fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

客户端

driftfile /var/lib/ntp/drift
logconfig all

restrict 127.0.0.1 
restrict ::1

restrict default nomodify notrap nopeer noquery

server 192.168.0.1
server 192.168.0.1 iburst minpoll 4 maxpoll 4

server 127.127.1.0
Fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw


keys /etc/ntp/keys


disable monitor

参数

restrict

对ntp做权限控制,如果没有任何参数则表示不做任何限制

参数描述
ignore忽略所以类型的ntp连接请求
nomodify限制客户端不能使用命令ntpc和ntpq来修改服务器端的时间
noquery不提供NTP网络校时服务
notrap不接受远程登录请求
notrust不接受没有经过认证的客户端的请求

server

指定ntp服务器地址

fudge

设置时间服务器的层级,fudge必须和server一块用, 而且是在server的下一行

fudge ip [stratum int]

stratum:0~15

0: 表示顶级
10: 用于给局域网主机提供时间服务

启动

服务端与客户端都要执行

#timedatectl set-ntp no

#timedatectl set-time "当前时间" 
或 
#ntpdate "服务端ntp地址"

#timedatectl set-ntp yes
#timedatectl set-local-rtc 0
#ntpd -gq

#systemctl start ntpd
#systemctl enable ntpd

状态

#ntpq -p

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值