it你好linux学习之ntp服务器的配置

简介:

  由于时间不同步,造成的服务器故障,相信大家都有遇到过,如比较常见的cacti取图无法显示。本文就NTP的配置,做以简单的说明

  • 主配置文件
 
  1. #yum install ntp*
  2. #vim /etc/ntp.conf (ntp的主配置文件)
  3. # Permit time synchronization with our time source, but do not 
  4. # permit the source to query or modify the service on this system. 
  5. #用法,restrict<IP地址><子网掩码>|<网段><子网掩码> [ignore|nomodiy|noquery|notrap|notrust|nokod]:指定可以进行NTP通信的ip地址> 
  6. 或网段 
  7. #ignore:关闭所有额NTP服务 
  8. #nomodiy:表示客户端不能更改NTP服务器的时间参数,但可以通过NTP服务器进行时间校对 
  9. #noquery:不提供NTP服务 
  10. #notrap:不提供他人安排远程事件登陆(Remote Event Logging)的功能 
  11. #notrust:拒绝没有通过认证的客户端 
  12. #kod:kod技术可以阻止“Kiss of Death”包(一种DOS攻击)对服务器的破坏。使用此参数将开启该功能 
  13. #nopeer:不与其他同一层的NTP服务器进行时间同步 
  14. restrict default kod nomodify notrap nopeer noquery 
  15. restrict -6 default kod nomodify notrap nopeer noquery 
  16.  
  17. # Permit all access over the loopback interface.  This could 
  18. # be tightened as well, but to do so would effect some of 
  19. # the administrative functions. 
  20.  
  21. restrict 127.0.0.1 
  22. restrict -6 ::1 
  23.  
  24. # Hosts on local network are less restricted. 
  25. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 
  26.  
  27. # Use public servers from the pool.ntp.org project. 
  28. # Please consider joining the pool (http://www.pool.ntp.org/join.html). 
  29. #server[IP|FQDN][prefer]:指定该NTP服务器上层NTP服务器,也就是为该服务器对自身进行时间校对的NTP服务器,如果有多个上层NTP服务器 
  30. 时,使用prefer参数的服务器优先级最高,没有prefer参数,根据配置文件的顺序从上到下,依次由高到低,在指定上层NTP服务器后,默认情 
  31. 况下至少15min后才会与上层NTP服务器进行时间校对。 
  32. server 0.rhel.pool.ntp.org 
  33. server 1.rhel.pool.ntp.org 
  34. server 2.rhel.pool.ntp.org 
  35. #broadcast网段 子网掩码:指定进行NTP时间广播的网段,在不指定此参数时NTP服务器会对所有能访问的网段广播 
  36. #broadcast 192.168.1.255 key 42         # broadcast server 
  37. #broadcastclient                        # broadcast client 
  38. #broadcast 224.0.1.1 key 42             # multicast server 
  39. #multicastclient 224.0.1.1              # multicast client 
  40. #manycastserver 239.255.254.254         # manycast server 
  41. #manycastclient 239.255.254.254 key 42  # manycast client 
  42.  
  43. # Undisciplined Local Clock. This is a fake driver intended for backup 
  44. # and when no outside source of synchronized time is available.  
  45. server  127.127.1.0     # local clock 
  46. #fudge 修改NTP服务器的相关参数 
  47. fudge   127.127.1.0 stratum 10 
  48. # Drift file.  Put this in a directory which the daemon can write to. 
  49. # No symbolic links allowed, either, since the daemon updates the file 
  50. # by creating a temporary in the same directory and then rename()'ing 
  51. # it to the file. 
  52. #driftfile文件名:默认情况下NTP服务器的时间计算是依据BIOS的芯片震动周期频率来计算的,但是这个数值与上层NTP服务器可能不一致,> 
  53. 所以NTP服务器会自动去计算NTP服务器的频率与上层NTP服务器的频率,并且将两个频率的误差记录在driftfile指定的文件中,该参数一般不> 
  54. 需要修改,使用配置文件中默认配置即可。 
  55. driftfile /var/lib/ntp/drift 
  56.  
  57. # Key file containing the keys and key identifiers used when operating 
  58. # with symmetric key cryptography.  
  59. keys /etc/ntp/keys 
  60.  
  61. # Specify the key identifiers which are trusted. 
  62. #trustedkey 4 8 42 
  63.  
  64. # Specify the key identifier to use with the ntpdc utility. 
  65. #requestkey 8 
  66.  
  67. # Specify the key identifier to use with the ntpq utility. 
  68. #controlkey 8 
  69.   
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.                  
  • 其他设置   

此外,系统的另外几个参数的设置,对NTP也有影响

/usr/share/zoneinfo 各时区文件的配置

/etc/localtime 此为选择的时区配置文件,由/usr/share/zoneinfo/Asia/Shanghai

拷贝而来

/etc/sysconfig/clock 

 
  1. ZONE="Asia/Shanghai"  
  2. UTC=true  
  3. ARC=false 

如果希望系统中每个用户拥有单独的时区设置,则可以在每个用户的环境变量中设置

vim /home/user/.bashrc 加入export TZ="/usr/share/zoneinfo/Asia/Shanghai" 

在rhel里面设置时区可以通过管理工具system-config-date来实现

  • 配置实例

 

 
  1. restrict default kod nomodify notrap nopeer noquery 
  2. restrict 127.0.0.1 
  3. restrict -6 ::1 

 本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/755891,如需转载请自行联系原作者

相关文章
|
17天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
18天前
|
安全 Ubuntu Java
Linux配置使用篇
Linux配置使用篇
|
4天前
|
Unix Linux Windows
Linux的学习之路:3、基础指令(2)
Linux的学习之路:3、基础指令(2)
28 0
|
17天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
1天前
|
Linux
如何将一个linux服务器挂载到另外一个linux服务器上
如何将一个linux服务器挂载到另外一个linux服务器上
13 1
|
1天前
|
Oracle Java 关系型数据库
Linux环境安装配置JDK11
Linux环境安装配置JDK11
17 0
|
1天前
|
Ubuntu Linux
Linux(Ubuntu)系统临时IP以及静态IP配置(关闭、启动网卡等操作)
请注意,以上步骤是在临时基础上进行配置的。如果要永久保存静态IP地址,通常还需要修改 `/etc/network/interfaces`文件,以便在系统重启后保持配置。同时,确保备份相关配置文件以防止出现问题。
13 1
|
2天前
|
监控 Linux 网络安全
Linux服务器如何查询连接服务器的IP
【4月更文挑战第15天】Linux服务器如何查询连接服务器的IP
9 1
|
3天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
41 2
|
3天前
|
Ubuntu Linux 测试技术
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试(下)
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试
35 1