[linux]centOS 7.6 安装ntp

目录

配置ntp服务器

配置客户端


NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

配置ntp服务器

1.查看ntp是否安装

rpm -qa |grep ntp

2.安装ntp

如果没安装ntp,执行以下命令进行安装

yum install -y ntp ntpdate

3.修改ntp配置文件

vim /etc/ntp.conf

添加修改上层时间服务器,如果能联通外网,则不需要修改,否则注释掉:

#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 192.168.23.41

fudge 192.168.23.41 stratum 8

 

#stratum说明:

# 正常情况下stratum值范围“0~15”

# Stratum-2则从Stratum-1获取时间,Stratum-3从Stratum-2获取时间,以此类推,

# 但Stratum层的总数限制在15以内。所有这些服务器在逻辑上形成阶梯式的架构相互连接,

# 而Stratum-1的时间服务器是整个系统的基础

4. 启动ntp服务,并开机自启动

systemctl start ntpd

systemctl enable ntpd

5. 查看ntp服务器与上层ntp的状态

ntpq –p

命令查看时间同步状态

ntpstat   

配置客户端

1. 配置ntp文件

vim /etc/ntp.conf

#配置允许NTP Server时间服务器主动修改本机的时间

restrict 192.168.23.41 nomodify notrap noquery

# 参数详解:

ignore  :关闭所有的 NTP 联机服务

nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网

noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器

notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。

nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟

kod : 访问违规时发送 KoD 包。

restrict -6 表示IPV6地址的权限设置

#注释掉其他时间服务器

#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

#配置时间服务器为本地搭建的NTP Server服务器

server 192.168.23.41

fudge 192.168.23.41 stratum 8

2.启动ntp

service ntpd start

systemctl enable ntpd

3.与ntp服务器手工同步时间

ntpdate -u 192.168.23.41

猜你喜欢

转载自blog.csdn.net/henku449141932/article/details/112918729