mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge pull request #2139 from GOLinux/master
[Translated] 20141222 How to Sync Time Properly with NTP Server in CentOS 7.x.md
This commit is contained in:
commit
9f8ddd2df4
@ -1,74 +0,0 @@
|
||||
Translating by GOLinux!
|
||||
How to Sync Time Properly with NTP Server in CentOS 7.x
|
||||
================================================================================
|
||||
**Chrony** is an open source and free application that helps you keep the system clock in sync with a NTP server, thus allowing you to keep the exact time. It consists of two programs chronyd and chronyc. chronyd is the daemon that runs in the background and adjusts the system clock which is running in the kernel to the time on a NTP server. It determines the rate at which the computer gains or loses time, and compensates for this. chronyc provides a user interface for monitoring the performance and configuring various settings. It can do so while running on the same computer as the chronyd instance it is controlling or a different remote computer.
|
||||
|
||||
Chrony comes installed by default on RHEL based operating systems like CentOS 7.
|
||||
|
||||
### Chrony configuration ###
|
||||
|
||||
When it starts Chrony will read the settings in /etc/chrony.conf configuration file. The most important settings on a CentOS 7 operating system are:
|
||||
|
||||
**server** - This can be used multiple times to add NTP server, it should be used in the format "server ". In general you can add as many server addresses as you wish.
|
||||
|
||||
Example:
|
||||
server 0.centos.pool.ntp.org
|
||||
server 3.europe.pool.ntp.org
|
||||
|
||||
**stratumweight** - The stratumweight directive sets how much distance should be added per stratum to the synchronization distance when chronyd selects the synchronization source from available sources. By default in CentOS it's 0, to makes chronyd ignore stratum when selecting the source
|
||||
|
||||
**driftfile** - One of the main activities of the chronyd program is to work out the rate at which the system clock gains or loses time relative to real time. Each time chronyd has a new value of gain/loss rate, it is desirable to record it in a file and this will allow it to compansate the system clock at the rate it was last restarted, even before it has a chance to obtain good estimate from the NTP server.
|
||||
|
||||
**rtcsync** - The rtcsync directive will enable a kernel mode where the system time is copied to the real time clock (RTC) every 11 minutes.
|
||||
|
||||
**allow / deny** - here you can specify a host, subnet, or network from which to allow or deny NTP connections to a machine acting as NTP server.
|
||||
|
||||
Examples:
|
||||
allow 192.168.4.5
|
||||
deny 192.168/16
|
||||
|
||||
**cmdallow / cmddeny** - same as allow only that you can specifiy witch IP address or host to have control command over chronyd
|
||||
|
||||
**bindcmdaddress** - this directive allows you to restrict the network interface to which chronyd will listen for command packets (issued by chronyc). This provides an additional level of access restriction above that available through cmddeny mechanism.
|
||||
|
||||
Example:
|
||||
bindcmdaddress 127.0.0.1
|
||||
bindcmdaddress ::1
|
||||
|
||||
**makestep** - normally chronyd will cause the system to gradually correct any time offset, by slowing down or speeding up the clock as required. In certain situations, the system clock may be so far adrift that this slewing process would take a very long time to correct the system clock. This directive forces chronyd to step system clock if the adjustment is larger than a threshold value, but only if there were no more clock updates since chronyd was started than a specified limit (a negative value can be used to disable the limit).
|
||||
|
||||
### Using chronyc ###
|
||||
|
||||
You can also change settings by running the chronyc command and then use one of the following commands:
|
||||
|
||||
**accheck** - Check whether NTP access is allowed on the speicif host
|
||||
|
||||
**activity** - This will display how many NTP sources are online/offline
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2014/10/chrony-activity.jpg)
|
||||
|
||||
**add server** - Add a new NTP server manually.
|
||||
|
||||
**clients** - Report on clients that have accessed the server
|
||||
|
||||
**delete** - Manually remove an NTP server or peer
|
||||
|
||||
**settime** - Manually set the daemon time
|
||||
|
||||
**tracking** - Display system time information
|
||||
|
||||
You can see the full list of commands by using the help command:
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2014/10/commands.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/chrony-time-sync/
|
||||
|
||||
作者:[Adrian Dinu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/adriand/
|
@ -0,0 +1,73 @@
|
||||
CentOS 7.x中正确设置时间与时钟服务器同步
|
||||
================================================================================
|
||||
**Chrony**是一个开源而自由的应用,它能帮助你保持系统时钟与时钟服务器同步,因此让你的时间保持精确。它由两个程序组成,分别是chronyd和chronyc。chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机获取或丢失时间的比率,并对此进行补偿。chronyc提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上干这些事,也可以在一台不同的远程计算机上干这些事。
|
||||
|
||||
在像CentOS 7之类基于RHEL的操作系统上,已经默认安装有Chrony。
|
||||
|
||||
### Chrony配置 ###
|
||||
|
||||
当Chrony启动时,它会读取/etc/chrony.conf配置文件中的设置。CentOS 7操作系统上最重要的设置有:
|
||||
|
||||
**server** - 该参数可以多次用于添加时钟服务器,必须以"server "格式使用。一般而言,你想添加多少服务器,就可以添加多少服务器。
|
||||
|
||||
Example:
|
||||
server 0.centos.pool.ntp.org
|
||||
server 3.europe.pool.ntp.org
|
||||
|
||||
**stratumweight** - stratumweight指令设置当chronyd从可用源中选择同步源时,每个层应该添加多少距离到同步距离。默认情况下,CentOS中设置为0,让chronyd在选择源时忽略层。
|
||||
|
||||
**driftfile** - chronyd程序的主要行为之一,就是根据实际时间计算出计算机获取或丢失时间的比率,将它记录到一个文件中是最合理的,它会在重启后为系统时钟作出补偿,甚至它可能有机会从时钟服务器获得好的估值。
|
||||
|
||||
**rtcsync** - rtcsync指令将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。
|
||||
|
||||
**allow / deny** - 这里你可以指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器。
|
||||
|
||||
Examples:
|
||||
allow 192.168.4.5
|
||||
deny 192.168/16
|
||||
|
||||
**cmdallow / cmddeny** - 跟上面相类似,只是你可以指定哪个IP地址或哪台主机可以通过chronyd使用控制命令
|
||||
|
||||
**bindcmdaddress** - 该指令允许你限制chronyd监听哪个网络接口的命令包(由chronyc执行)。该指令通过cmddeny机制提供了一个除上述限制以外可用的额外的访问控制等级。
|
||||
|
||||
Example:
|
||||
bindcmdaddress 127.0.0.1
|
||||
bindcmdaddress ::1
|
||||
|
||||
**makestep** - 通常,chronyd将根据需求通过减慢或加速时钟,使得系统逐步纠正所有时间偏差。在某些特定情况下,系统时钟可能会漂移过快,导致该回转过程消耗很长的时间来纠正系统时钟。该指令强制chronyd在调整期大于某个阀值时调停系统时钟,但只有在因为chronyd启动时间超过指定限制(可使用负值来禁用限制),没有更多时钟更新时才生效。
|
||||
|
||||
### 使用chronyc ###
|
||||
|
||||
你也可以通过运行chronyc命令来修改设置,命令如下:
|
||||
|
||||
**accheck** - 检查NTP访问是否对特定主机可用
|
||||
|
||||
**activity** - 该命令会显示有多少NTP源在线/离线
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2014/10/chrony-activity.jpg)
|
||||
|
||||
**add server** - 手动添加一台新的NTP服务器。
|
||||
|
||||
**clients** - 在客户端报告已访问到服务器
|
||||
|
||||
**delete** - 手动移除NTP服务器或对等服务器
|
||||
|
||||
**settime** - 手动设置守护进程时间
|
||||
|
||||
**tracking** - 显示系统时间信息
|
||||
|
||||
你可以通过使用帮助命令查看完整的命令列表:
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2014/10/commands.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/chrony-time-sync/
|
||||
|
||||
作者:[Adrian Dinu][a]
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/adriand/
|
Loading…
Reference in New Issue
Block a user