CentOS 7如何搭建本地时间同步服务器
1、服务器(ip:192.168.56.118)安装ntp# yum install ntp -y编辑配置文件[root@localhost ansible-k8s]# cat /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), n
·
1、服务器(ip:192.168.56.118)
安装ntp
# yum install ntp -y
编辑配置文件
[root@localhost ansible-k8s]# 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.56.0 mask 255.255.255.0 nomodify notrap # 新增:添加可以同步时间的网段
# 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 0,1,2,3 注释掉网络服务器
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#指明局域网中作为NTP服务器的IP
#service 192.168.56.118
server 127.127.1.0 # 新增:外部时间服务器不可用时,以本地时间作为时间服务
fudge 127.127.1.0 stratum 10 # 新增
#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
修改/etc/sysconfig/ntpd 文件
# vim /etc/sysconfig/ntpd
// 增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
启动服务
# systemctl start ntpd
查看服务
[root@localhost ansible-k8s]# netstat -anput | grep ntpd
udp 0 0 172.18.0.1:123 0.0.0.0:* 20525/ntpd
udp 0 0 172.17.0.1:123 0.0.0.0:* 20525/ntpd
udp 0 0 192.168.56.118:123 0.0.0.0:* 20525/ntpd
udp 0 0 10.4.7.132:123 0.0.0.0:* 20525/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 20525/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 20525/ntpd
2、客户端(IP: 192.168.56.11)
安装ntpdate
# yum install ntpdate -y
测试
# ntpdate 192.168.56.118
15 Jun 15:35:12 ntpdate[16461]: step time server 192.168.56.118 offset 0.710982 sec
3、注意事项
-
对于centos7系统有默认的时间服务chronyd,他会默认开机自启,系统就会略过ntpd的开机自启,就会出现ntpd虽然加入开机自启,但是服务并未启动,此时关闭chronyd的开机自启即可
-
如果出现端口不通的情况,需要关闭防火墙
更多推荐
已为社区贡献2条内容
所有评论(0)