搭建ntp

搭建ntp,第1张

概述1、关闭iptables防火墙或者开放UDP协议的123端口  /etc/init.d/iptables stop 或者  sudo iptables -I INPUT -p udp --dport 123 -j ACCEPT  sudo service iptables save 2、关闭SELinux  getenforce 查看当前状态  vi /etc/selinux/config   S 1、关闭iptables防火墙或者开放UDP协议的123端口
 /etc/init.d/iptables stop
或者
 sudo iptables -I input -p udp --dport 123 -j ACCEPT
 sudo service iptables save
2、关闭SElinux
 getenforce 查看当前状态
 vi /etc/selinux/config 
 SEliNUX=Disabled
3、配置主机名ntp-server
 vim /etc/hosts 在每行的最后加想改的名称 ntp-server
 vim /etc/sysconfig/network HOSTname=ntp-server
 hostname ntp-server
 logout 
4、安装ntp服务程序
 rpm -qa | grep ntp 查询是否需要安装ntp服务
 yum install -y ntp 安装ntp服务程序
 date 查看当前服务器时间
 ntpdate ntp1.aliyun.com 手动同步时间服务器,可以同步两次
备注:需要手动同步服务器时间是因为如果当前服务器时间与目标NTP服务器时间误差过大时,ntpd是不会进行时间同步的。
 date 查看同步后的服务器时间
特别注意:使用ntpdate命令手动同步时间之前不能启动ntpd服务,否则会提示端口被占用。
5、修改主配置文件 /etc/ntp.conf  # mv /etc/ntp.conf /etc/ntp.conf.bak  # vim /etc/ntp.conf 新增如下代码:  driftfile /var/lib/ntp/drift 有不用加  logfile /var/log/ntp.log  pIDfile /var/run/ntpd.pID  includefile /etc/ntp/crypto/pw 有不用加  keys /etc/ntp/keys 有不用加 # 允许任何IP的客户端进行时间同步,但不允许修改NTP服务端参数,default类似于0.0.0.0  restrict default kod nomodify notrap nopeer noquery 有不用加  restrict -6 default kod nomodify notrap nopeer noquery 有不用加 # 允许通过本地回环接口进行所有访问  restrict 127.0.0.1 有不用加   restrict -6 ::1 有不用加 # 只允许192.168.1网段的客户端进行时间同步,但不允许修改NTP服务端参数  restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap nopeer noquery 有不用加  restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap restrict default #default指所有的IP #将原有的 server 0.centos.pool.ntp.org iburst 全部注释掉  server ntp1.aliyun.com iburst 新增 # 指定上层NTP服务器为阿里云提供的公网NTP服务器,并设置访问权限  restrict ntp1.aliyun.com nomodify notrap nopeer noquery  restrict ntp2.aliyun.com nomodify notrap nopeer noquery  restrict ntp3.aliyun.com nomodify notrap nopeer noquery  restrict ntp4.aliyun.com nomodify notrap nopeer noquery  restrict ntp5.aliyun.com nomodify notrap nopeer noquery  restrict ntp6.aliyun.com nomodify notrap nopeer noquery  restrict ntp7.aliyun.com nomodify notrap nopeer noquery  server ntp1.aliyun.com iburst minpoll 4 maxpoll 10  server ntp2.aliyun.com iburst minpoll 4 maxpoll 10  server ntp3.aliyun.com iburst minpoll 4 maxpoll 10  server ntp4.aliyun.com iburst minpoll 4 maxpoll 10  server ntp5.aliyun.com iburst minpoll 4 maxpoll 10  server ntp6.aliyun.com iburst minpoll 4 maxpoll 10  server ntp7.aliyun.com iburst minpoll 4 maxpoll 10 # 阿里云提供的公网NTP服务器不可用时,采用本地时间作为同步标准  server 127.127.1.0  fudge 127.127.1.0 stratum 10 备注:常用指令说明  kod:访问违规时发送KOD包  nomodify:客户端不能更改服务端的参数信息,但是客户端可以通过服务端进行网络校时  notrap:不提供trap远程事件登录  nopeer:用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟  noquery:不提供客户端时间查询,客户端不能使用ntpq、ntpdc等命令来查询NTP服务器  notrust:客户端除非通过认证,否则该客户端来源将被视为不信任网域  iburst:如果服务端在一个标准轮询间隔内没有应答,客户端会发送一定数量的包(8个而不是通常的1个)给NTP服务端,如果在短时间内呼叫NTP服务端几次,都没有出现可辨识的应答,那么本地时间将不会发生变化  minpoll:NTP消息轮询间隔的最小值,默认为6(64秒)  maxpoll:NTP消息轮询间隔的最大值,默认为10(1024秒) 7、修改配置文件/etc/sysconfig/ntpd,末尾新增代码:SYNC_HWCLOCK=yes 备注:默认情况下,CentOS系统时间和硬件时间并不会自动同步。在CentOS运行过程中,系统时间和硬件时间以异步的方式运行,互不干扰。硬件时间的运行是靠BIOS电池来维持,而系统时间是靠cpu tick来维持。在系统开机时,会自动从BIOS中读取硬件时间,并设置为系统时间。NTP一般只会同步系统时间,如果需要使硬件时间和系统时间同步,就需要修改配置文件/etc/sysconfig/ntpd。 8、修改用于初始同步的服务器列表配置文件/etc/ntp/step-tickers: # vim /etc/ntp/step-tickers,新增如下代码:  ntp1.aliyun.com  ntp2.aliyun.com  ntp3.aliyun.com  ntp4.aliyun.com  ntp5.aliyun.com  ntp6.aliyun.com  ntp7.aliyun.com 9、启动ntpd服务:  service ntpd start 启动ntp服务器   ss -tunlp | grep -w :123  yum -y install lsof   lsof -i :123  chkconfig ntpd on 设为开机启动  chkconfig --List ntpd 10、在5~10分钟后查看时间同步状态:  ntpstat  备注:  120.25.115.20为ntp1.aliyun.com域名解析后的地址  本地服务器与上层服务器的时间偏差小于28ms  本地服务器每隔64s主动同步一次时间  查看所有作为时钟源校正过本地NTP服务器的上层NTP服务器列表:# ntpq -p 总结

以上是内存溢出为你收集整理的搭建ntp全部内容,希望文章能够帮你解决搭建ntp所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1024720.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存