Difference between revisions of "Chrony"

From ArchWiki
Jump to: navigation, search
m (Format fixes, moved section to help user make a decision ''before'' setup.)
(Remove obsolete auth handling, as of v2.2 a domain socket is used by default)
 
(20 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 
[[Category:Networking]]
 
[[Category:Networking]]
 
[[ja:Chrony]]
 
[[ja:Chrony]]
 +
{{Related articles start}}
 +
{{Related|Time}}
 +
{{Related|Network Time Protocol daemon}}
 +
{{Related|systemd-timesyncd}}
 +
{{Related|OpenNTPD}}
 +
{{Related articles end}}
 +
 
This article describes how to set up and run Chrony, an alternative NTP client and server that is roaming friendly and designed specifically for systems that are not online all the time.
 
This article describes how to set up and run Chrony, an alternative NTP client and server that is roaming friendly and designed specifically for systems that are not online all the time.
  
 
== Installation ==
 
== Installation ==
  
{{Pkg|chrony}} is available from the [[official repositories]].
+
[[Install]] the {{Pkg|chrony}} package.
 
+
Alternatives to the Chrony, are [[NTPd]], the reference implementation of NTP, and [[OpenNTPD]], part of the OpenBSD project and currently not maintained for Linux.
+
  
 
== Configuration ==
 
== Configuration ==
 +
 +
The smallest useful configuration file (using IP addresses instead of a hostname) would look something like:
 +
 +
{{hc|/etc/chrony.conf|
 +
server 1.2.3.4 offline
 +
server 5.6.7.8 offline
 +
server 9.10.11.12 offline
 +
driftfile /etc/chrony.drift
 +
rtconutc
 +
rtcsync
 +
}}
 +
 +
=== NTP Servers ===
  
 
The first thing you define in your {{ic|/etc/chrony.conf}} is the servers your machine will synchronize to.
 
The first thing you define in your {{ic|/etc/chrony.conf}} is the servers your machine will synchronize to.
Line 18: Line 36:
 
The following lines are just an example:
 
The following lines are just an example:
  
  server 0.pool.ntp.org
+
  server 0.pool.ntp.org iburst
  server 1.pool.ntp.org
+
  server 1.pool.ntp.org iburst
  server 2.pool.ntp.org
+
  server 2.pool.ntp.org iburst
  server 3.pool.ntp.org
+
  server 3.pool.ntp.org iburst
  
 
If your computer is not connected to the internet on startup, it is recommended to use the ''offline'' option, to tell Chrony not to try and connect to the servers, until it has been given the go:
 
If your computer is not connected to the internet on startup, it is recommended to use the ''offline'' option, to tell Chrony not to try and connect to the servers, until it has been given the go:
Line 30: Line 48:
 
  server 3.pool.ntp.org offline
 
  server 3.pool.ntp.org offline
  
It may also be a good idea to either use IP addresses instead of host names, or to map the hostnames to IP addresses in your {{ic|/etc/hosts}} file, as DNS resolving won't be available until you've made a connection.
+
It may also be a good idea to either use IP addresses instead of host names, or to map the hostnames to IP addresses in your {{ic|/etc/hosts}} file, as DNS resolving will not be available until you have made a connection.
  
To tell chronyd that a connection has been established, you need to be able to log in with chronyc. You will have to configure chronyd with an administrator password to be able to do this. Setting up an administrator password is as simple as creating the file {{ic|/etc/chrony.keys}} with a single line:
+
=== Telling chronyd an internet connection has been made ===
  
{{hc|/etc/chrony.keys|1 xyzzy}}
+
If you are connected to the internet, run:
  
as well as adding the following line somewhere in {{ic|/etc/chrony.conf}}:
+
{{bc|
 
+
# chronyc
commandkey 1
+
chronyc> online
 
+
200 OK
The smallest useful configuration file (using IP addresses instead of a hostname) would look something like:
+
chronyc> exit
 
+
{{hc|/etc/chrony.conf|
+
server 1.2.3.4 offline
+
server 5.6.7.8 offline
+
server 9.10.11.12 offline
+
rtcfile /etc/chrony.rtc
+
rtconutc
+
keyfile /etc/chrony.keys
+
commandkey 1
+
driftfile /etc/chrony.drift
+
 
}}
 
}}
  
=== Telling chronyd an internet connection has been made ===
+
You may also be interested in the {{ic|activity}} option to display status:
  
For this to work, you'll need to configure the {{ic|commandkey}} option in {{ic|/etc/chrony.conf}} as shown above. If you've done this, start {{ic|chronyc}} and enter the following commands if you are connected to the internet:
 
 
{{bc|
 
{{bc|
chronyc> password xyzzy
+
# chronyc activity
 
200 OK
 
200 OK
chronyc> online
+
3 sources online
200 OK
+
0 sources offline
chronyc> exit
+
0 sources doing burst (return to online)
 +
0 sources doing burst (return to offline)
 +
0 sources with unknown address
 
}}
 
}}
  
Chrony should now connect to the configured time servers and update your clock if needed.
+
Chrony should now connect to the configured time servers and update your clock if needed. To tell chrony that you are not connected to the Internet anymore, execute the following:
  
To tell chrony that you are not connected to the internet anymore, execute the following:
 
 
{{bc|
 
{{bc|
chronyc> password xyzzy
+
# chronyc offline
 
200 OK
 
200 OK
chronyc> offline
+
 
 +
# chronyc activity
 
200 OK
 
200 OK
chronyc> exit
+
0 sources online
 +
3 sources offline
 +
0 sources doing burst (return to online)
 +
0 sources doing burst (return to offline)
 +
0 sources with unknown address
 
}}
 
}}
  
In conclusion, don't forget the user guide at {{ic|/usr/share/doc/chrony/chrony.txt}}, which is likely to answer any doubts you could still have. [http://chrony.tuxfamily.org/manual.html It is also available online.] See also the related man pages: {{ic|man <nowiki>{chrony|chronyc|chronyd|chrony.conf}</nowiki>}}).
+
The online/offline status can be automatically handled by dispatcher services for {{Pkg|networkmanager}} and {{Pkg|connman}}, see below.
 +
 
 +
In conclusion, do not forget the user guide at {{ic|/usr/share/doc/chrony/chrony.txt}}, which is likely to answer any doubts you could still have. [http://chrony.tuxfamily.org/manual.html It is also available online.] See also the related man pages: {{ic|man <nowiki>{chrony|chronyc|chronyd|chrony.conf}</nowiki>}}).
  
 
== Usage ==
 
== Usage ==
Line 90: Line 105:
  
 
{{bc|
 
{{bc|
# chronyc> password xyzzy
+
# chronyc
Password:
+
200 OK
+
 
chronyc> trimrtc
 
chronyc> trimrtc
 
200 OK
 
200 OK
Line 100: Line 113:
 
Then exit from chronyc and the RTC and system time should be within a few microseconds of each other and should then be approximately correct on boot and fully synchronise a short time later.
 
Then exit from chronyc and the RTC and system time should be within a few microseconds of each other and should then be approximately correct on boot and fully synchronise a short time later.
  
=== Using NetworkManager to let chronyd go online ===
+
== Notifying network state ==
  
''chronyd'' can be go into online/offline mode along with a network connection through the use of [[NetworkManager#Network Services with NetworkManager Dispatcher|NetworkManager's dispatcher scripts]]. You can install {{AUR|networkmanager-dispatcher-chrony}} from the AUR.
+
If you have specified your pools as offline in {{ic|chrony.conf}}, you need to tell ''chrony'' that the network status has changed.
 +
 
 +
You can either use ''chronyc'' to notify ''chrony'' that your network configuration has changed, or you can use a dispatcher for your relevant network configuration manager.
 +
 
 +
=== NetworkManager ===
 +
 
 +
''chronyd'' can be go into online/offline mode along with a network connection through the use of [[NetworkManager#Network_services_with_NetworkManager_dispatcher|NetworkManager's dispatcher scripts]]. You can install {{AUR|networkmanager-dispatcher-chrony}} from the AUR.
 +
 
 +
=== netctl ===
 +
 
 +
Install {{AUR|netctl-dispatcher-chrony}}{{Broken package link|{{aur-mirror|netctl-dispatcher-chrony}}}} from the AUR, and add the included scripts to your [[netctl]] profile:
 +
 
 +
{{bc|<nowiki>
 +
# echo "ExecUpPost='/usr/share/netctl-dispatcher-chrony/chrony-up.sh'" >> /path/to/netctl/profile
 +
# echo "ExecDownPre='/usr/share/netctl-dispatcher-chrony/chrony-down.sh'" >> /path/to/netctl/profile</nowiki>
 +
}}
  
 
== See also ==
 
== See also ==

Latest revision as of 20:53, 6 January 2016

This article describes how to set up and run Chrony, an alternative NTP client and server that is roaming friendly and designed specifically for systems that are not online all the time.

Installation

Install the chrony package.

Configuration

The smallest useful configuration file (using IP addresses instead of a hostname) would look something like:

/etc/chrony.conf
server 1.2.3.4 offline
server 5.6.7.8 offline
server 9.10.11.12 offline
driftfile /etc/chrony.drift
rtconutc
rtcsync

NTP Servers

The first thing you define in your /etc/chrony.conf is the servers your machine will synchronize to. NTP servers are classified in a hierarchical system with many levels called strata: the devices which are considered independent time sources are classified as stratum 0 sources; the servers directly connected to stratum 0 devices are classified as stratum 1 sources; servers connected to stratum 1 sources are then classified as stratum 2 sources and so on.

It has to be understood that a server's stratum cannot be taken as an indication of its accuracy or reliability. Typically, stratum 2 servers are used for general synchronization purposes: if you do not already know the servers you are going to connect to, you should use the pool.ntp.org servers (alternate link) and choose the server pool that is closest to your location.

The following lines are just an example:

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

If your computer is not connected to the internet on startup, it is recommended to use the offline option, to tell Chrony not to try and connect to the servers, until it has been given the go:

server 0.pool.ntp.org offline
server 1.pool.ntp.org offline
server 2.pool.ntp.org offline
server 3.pool.ntp.org offline

It may also be a good idea to either use IP addresses instead of host names, or to map the hostnames to IP addresses in your /etc/hosts file, as DNS resolving will not be available until you have made a connection.

Telling chronyd an internet connection has been made

If you are connected to the internet, run:

# chronyc
chronyc> online
200 OK
chronyc> exit

You may also be interested in the activity option to display status:

# chronyc activity
200 OK
3 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address

Chrony should now connect to the configured time servers and update your clock if needed. To tell chrony that you are not connected to the Internet anymore, execute the following:

# chronyc offline
200 OK

# chronyc activity
200 OK
0 sources online
3 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address

The online/offline status can be automatically handled by dispatcher services for networkmanager and connman, see below.

In conclusion, do not forget the user guide at /usr/share/doc/chrony/chrony.txt, which is likely to answer any doubts you could still have. It is also available online. See also the related man pages: man {chrony|chronyc|chronyd|chrony.conf}).

Usage

Starting chronyd

The package provides chrony.service, see systemd for details.

Synchronising chrony hardware clock from the system clock

During boot the initial time is read from the hardware clock (RTC) and the system time is then set, and synchronised over a period of minutes once the chrony daemon has been running for a while. If the hardware clock is out of sync then the initial system time can be some minutes away from the true time. If that is the case it may be necessary to reset the hardware clock.

You can use chronyc to force the current system time to be synced to hardware:

# chronyc
chronyc> trimrtc
200 OK
chronyc> quit

Then exit from chronyc and the RTC and system time should be within a few microseconds of each other and should then be approximately correct on boot and fully synchronise a short time later.

Notifying network state

If you have specified your pools as offline in chrony.conf, you need to tell chrony that the network status has changed.

You can either use chronyc to notify chrony that your network configuration has changed, or you can use a dispatcher for your relevant network configuration manager.

NetworkManager

chronyd can be go into online/offline mode along with a network connection through the use of NetworkManager's dispatcher scripts. You can install networkmanager-dispatcher-chronyAUR from the AUR.

netctl

Install netctl-dispatcher-chronyAUR[broken link: archived in aur-mirror] from the AUR, and add the included scripts to your netctl profile:

# echo "ExecUpPost='/usr/share/netctl-dispatcher-chrony/chrony-up.sh'" >> /path/to/netctl/profile
# echo "ExecDownPre='/usr/share/netctl-dispatcher-chrony/chrony-down.sh'" >> /path/to/netctl/profile

See also