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

相关文章
|
22天前
|
Ubuntu Linux vr&ar
IM跨平台技术学习(十二):万字长文详解QQ Linux端实时音视频背后的跨平台实践
本文详细记录了新版QQ音视频通话在 Linux 平台适配开发过程中的技术方案与实现细节,希望能帮助大家理解在 Linux 平台从 0 到 1 实现音视频通话能力的过程。
50 2
|
3天前
|
Ubuntu 算法 Linux
嵌入式Linux的学习误区
**嵌入式Linux学习误区摘要** 1. **过度聚焦桌面Linux** - 许多学习者误将大量时间用于精通桌面Linux系统(如RedHat、Fedora、Ubuntu),认为这是嵌入式Linux开发的基石。 - 实际上,桌面Linux仅作为开发工具和环境,目标不应是成为Linux服务器专家,而应专注于嵌入式开发工具和流程。 2. **盲目阅读Linux内核源码** - 初学者在不了解Linux基本知识时试图直接研读内核源码,这往往导致困惑和挫败感。 - 在具备一定嵌入式Linux开发经验后再有针对性地阅读源码,才能有效提升技能。
13 4
|
7天前
|
Java Linux 应用服务中间件
Windows和Linux的最佳Web服务器
【7月更文挑战第20天】Windows和Linux的最佳Web服务器
19 3
|
14天前
|
Ubuntu 应用服务中间件 Linux
Linux学习之Ubuntu 20中OpenResty的nginx目录里内容和配置文件
总的来说,OpenResty的Nginx配置文件是一个强大的工具,它允许你以非常灵活的方式定义你的Web服务的行为。
17 2
|
2天前
|
Linux 网络安全 Android开发
Termux-远程管理Linux服务器
在手机上通过termux管理Linux服务器
|
21天前
|
网络协议 Linux
云服务器内部端口占用,9090端口已经存在了,如何关闭,Linux查询端口,查看端口,端口查询,关闭端口写法-netstat -tuln,​fuser -k 3306/tcp​
云服务器内部端口占用,9090端口已经存在了,如何关闭,Linux查询端口,查看端口,端口查询,关闭端口写法-netstat -tuln,​fuser -k 3306/tcp​
|
21天前
|
大数据 Linux 程序员
软件开发常见流程之服务器+Linux部署项目,会用服务器+Linux部署项目资料
软件开发常见流程之服务器+Linux部署项目,会用服务器+Linux部署项目资料
|
22天前
|
负载均衡 Java Linux
黑马头条01,环境搭建,今日头条的介绍,今日头条的功能架构图,技术栈的说明,服务层,nacos(奶靠丝)安装,安装在Linux服务器上环境准备,
黑马头条01,环境搭建,今日头条的介绍,今日头条的功能架构图,技术栈的说明,服务层,nacos(奶靠丝)安装,安装在Linux服务器上环境准备,
|
23天前
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
关系型数据库 MySQL Linux
MySQL 数据库linux系统下修改配置文件设置mysql是否大小写敏感实例演示
MySQL 数据库linux系统下修改配置文件设置mysql是否大小写敏感实例演示
213 0
MySQL 数据库linux系统下修改配置文件设置mysql是否大小写敏感实例演示

热门文章

最新文章