安装
服务端与客户端都要执行安装
#yum install ntp ntpdate -y
配置
目录:/etc/ntp.conf
服务端
driftfile /var/lib/ntp/drift
logconfig all
restrict 127.0.0.1
restrict ::1restrict 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 10includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
客户端
driftfile /var/lib/ntp/drift
logconfig all
restrict 127.0.0.1
restrict ::1restrict default nomodify notrap nopeer noquery
server 192.168.0.1
server 192.168.0.1 iburst minpoll 4 maxpoll 4server 127.127.1.0
Fudge 127.127.1.0 stratum 10includefile /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