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,如需转载请自行联系原作者

相关文章
|
14天前
|
消息中间件 安全 Unix
SSH配置多台服务器之间的免密登陆以及登陆别名
SSH配置多台服务器之间的免密登陆以及登陆别名
26 1
|
4天前
|
Unix Linux Windows
Linux的学习之路:3、基础指令(2)
Linux的学习之路:3、基础指令(2)
28 0
|
1天前
|
Linux
如何将一个linux服务器挂载到另外一个linux服务器上
如何将一个linux服务器挂载到另外一个linux服务器上
13 1
|
3天前
|
监控 Linux 网络安全
Linux服务器如何查询连接服务器的IP
【4月更文挑战第15天】Linux服务器如何查询连接服务器的IP
9 1
|
3天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
41 2
|
4天前
|
消息中间件 Unix Linux
Linux的学习之路:17、进程间通信(1)
Linux的学习之路:17、进程间通信(1)
20 1
|
4天前
|
存储 安全 Linux
Linux的学习之路:9、冯诺依曼与进程(1)
Linux的学习之路:9、冯诺依曼与进程(1)
18 0
|
7天前
|
网络协议 安全 Linux
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
IDEA通过内网穿透实现固定公网地址远程SSH连接本地Linux服务器
|
12天前
|
存储 弹性计算 安全
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
2核2G、2核4G配置是很多个人和企业建站以及部署中小型的web应用等场景时首选的云服务器配置,这些配置的租用价格也是用户非常关心的问题,本文为大家整理汇总了2024年阿里云服务器2核2G、2核4G配置不同实例规格及地域之间的收费标准,同时整理了这些配置最新活动价格,以供大家参考和选择。
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
|
13天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
1242 8