一、安装环境:
CentOS 7 Linux version 3.10.0-229.el7.x86_64
ntp-4.2.6p5-19.el7.centos.x86_64
二、安装及配置
2.1 安装
NTP可以直接通过yum来安装,使用 rpm -qa ntp可以查看是否已安装ntp服务,如有安装可使用yum install ntp 来升级,当然也可以不用升级。
命令:
yum install ntp #安装NTP服务器
2.2 配置
cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift #默认配置,无需改动
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery #默认配置,无需改动
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 #默认配置,无需改动
restrict ::1 #默认配置,无需改动
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.30.0 mask 255.255.255.0 nomodify notrap #增加这一行,允许哪些IP 地址可以同步NTP服务器,也可以不用配置,默认所有网段
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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服务器,在香港就会使用香港的NTP服务器。当然也可以注释上面四行,自己添加,如 server 0.210.72.145.44
#broadcast 192.168.1.255 autokey# broadcast server
#broadcastclient# broadcast client
#broadcast 224.0.1.1 autokey# multicast server
#multicastclient 224.0.1.1# multicast client
#manycastserver 239.255.254.254# manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw #默认配置,无需改动
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys #默认配置,无需改动
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor #默认配置,无需改动
2.3 启动NTP服务
命令:
systemctl start ntpd.service 开启服务
systemctl stop ntpd.service 停止服务
三、测试
命令:
ntpstat #查看ntp服务器是否连通,启动服务后需要三五分钟后才会连通
ntpq -p #查看ntp服务器连接状态
netstat -tunlp | grep ntpd #查看服务端口
在另一台linux上测试ntp同步是否可用
命令:
yum install ntpdate
ntpdate 172.31.251.196
四、交换机同步
配置命令:
conf t
ntp server 172.31.251.196
谢谢你打开这篇博文,并一直坚持看到了这里,如果觉得对你有帮助,请不要吝啬点一下右下角的赞。
本文出自 “点滴技术” 博客,请务必保留此出处http://tryrus.blog.51cto.com/10914693/1788562
原文地址:http://tryrus.blog.51cto.com/10914693/1788562