NTP for centos7配置

安装NTP包 

检查是否安装了ntp相关包。如果没有安装ntp相关包,使用rpm或yum安装,安装也非常简单方便。 

 如何检查是否安装:service ntp status 查看是否有此服务 

yum install -y ntp 

2.进入ntp配置目录: 

vim /etc/ntp.conf 

http://blog.csdn.net/scorpio3k/article/details/49645219 

常见错误解决: 

http://www.blogjava.net/spray/archive/2008/07/10/213964.html 

NTP 4.2.7p441-1 "No association ID's returned" 

问题解决:https://bbs.archlinux.org/viewtopic.php?id=181370 

开机自启: 

systemctl enable ntpd.service  

如果不能自启: 

systemctl disable chronyd.service    

一.首先检查机器是否装有NTP: 

systemctl start ntpd 

如果没有 就GG了。。。或者联网  yum install –y ntp 

  

二.NTP详细配置步骤(默认机器上装有ntp,红字部分为修改部分) 

首先进入ntp配置文件: 

vim /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 

#禁止从网上同步 

restrict -4 default kod nomodify notrap nopeer noquery 

restrict -6 default kod 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 

  

# Use public servers from the pool.ntp.org project. 

# Please consider joining the pool (http://www.pool.ntp.org/join.html). 

#此处为设置NTP上层服务器,即从此机器同步 

#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.9.100 perfer  

  

#此处为运行上层server的所有权限 这句话和上头的server必须有 

restrict 192.168.9.100 

  

#设置本地时钟以及层数 当同步不好用的时候就将本机作为服务器 

server 127.127.1.0 

fudge 127.127.1.0 startum 1 

#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 

  

到此为止 配置文件结束  保存退出即可 

  

三.配置自动同步开机自启 

命令行输入 

crontab –e 

然后在配置文件输入: 

*/5 * * * *  /usr/sbin/ntpdate -u pool.ntp.org ;/sbin/hwclock --systohc  >> /root/sync_date.log 2>&1 

意思是每5分钟执行一次同步语句   

随后: 

systemctl restart ntpd 

systemctl restart crond 

systemctl enable ntpd 

systemctl enable crond 

   

http://francs3.blog.163.com/blog/static/40576727201211231254105/ 

查看方式 :可使用ntpq -p 和 watch ntpq -p查看ntp服务器状态以及联通情况 

猜你喜欢

转载自blog.csdn.net/qq249356520/article/details/89208021