Ubuntu Server Guide Changes, errors and bugs
Download 1.27 Mb. Pdf ko'rish
|
ubuntu-server-guide
- Bu sahifa navigatsiya:
- Synchronizing your systems time
- Configuring timedatectl and timesyncd
- Serve the Network Time Protocol
- Installation
- Chronyd Configuration
- Example configuration for GPSD to feed Chrony
References • The dhcp3-server Ubuntu Wiki page has more information. • For more /etc/dhcp/dhcpd.conf options see the dhcpd.conf man page. • ISC dhcp-server Time Synchronization NTP is a TCP/IP protocol for synchronizing time over a network. Basically a client requests the current time from a server, and uses it to set its own clock. Behind this simple description, there is a lot of complexity - there are tiers of NTP servers, with the tier one NTP servers connected to atomic clocks, and tier two and three servers spreading the load of actually handling requests across the Internet. Also the client software is a lot more complex than you might think - it has to factor out communication delays, and adjust the time in a way that does not upset all the other processes that run on the server. But luckily all that complexity is hidden from you! Ubuntu by default uses timedatectl / timesyncd to synchronize time and users can optionally use chrony to serve the Network Time Protocol. Synchronizing your systems time Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. timesyncd is available by default and replaces not only ntpdate, but also the client portion of chrony (or formerly ntpd). So on top of the one-shot action that ntpdate provided on boot and network activation, now timesyncd by default regularly checks and keeps your local time in sync. It also stores time updates locally, so that after reboots monotonically advances if applicable. If chrony is installed timedatectl steps back to let chrony do the time keeping. That shall ensure that no two time syncing services are fighting. While no more recommended to be used, this still also applies to ntpd being installed to retain any kind of old behavior/config that you had through an upgrade. But it also implies that on an upgrade from a former release ntp/ntpdate might still be installed and therefore renders the new systemd based services disabled. ntpdate is considered deprecated in favor of timedatectl (or chrony) and thereby no more installed by default. timesyncd will generally do the right thing keeping your time in sync, and chrony will help with more complex cases. But if you had one of a few known special ntpdate use cases, consider the following: • If you require a one-shot sync use: chronyd −q • If you require a one-shot time check, without setting the time use: chronyd −Q Configuring timedatectl and timesyncd The current status of time and time configuration via timedatectl and timesyncd can be checked with timedatectl status. $ t i m e d a t e c t l s t a t u s L o c a l time : Fr 2018−02−23 0 8 : 4 7 : 1 3 UTC U n i v e r s a l time : Fr 2018−02−23 0 8 : 4 7 : 1 3 UTC RTC time : Fr 2018−02−23 0 8 : 4 7 : 1 3 Time zone : Etc /UTC (UTC, +0000) System c l o c k s y n c h r o n i z e d : y e s 59 systemd−timesyncd . s e r v i c e a c t i v e : y e s RTC i n l o c a l TZ : no If chrony is running it will automatically switch to: [ . . . ] systemd−timesyncd . s e r v i c e a c t i v e : no Via timedatectl an admin can control the timezone, how the system clock should relate to the hwclock and if permanent synronization should be enabled or not. See man timedatectl for more details. timesyncd itself is still a normal service, so you can check its status also more in detail via. $ s y s t e m c t l s t a t u s systemd−timesyncd systemd−timesyncd . s e r v i c e − Network Time S y n c h r o n i z a t i o n Loaded : l o a d e d ( / l i b / systemd / system / systemd−timesyncd . s e r v i c e ; e n a b l e d ; vendor p r e s e t : e n a b l e d ) A c t i v e : a c t i v e ( r u n ni n g ) s i n c e F r i 2018−02−23 0 8 : 5 5 : 4 6 UTC; 10 s ago Docs : man : systemd−timesyncd . s e r v i c e ( 8 ) Main PID : 3744 ( systemd−timesyn ) S t a t u s : ” S y n c h r o n i z e d t o time s e r v e r 9 1 . 1 8 9 . 8 9 . 1 9 8 : 1 2 3 ( ntp . ubuntu . com ) . ” Tasks : 2 ( l i m i t : 4 9 1 5 ) CGroup : / system . s l i c e / systemd−timesyncd . s e r v i c e | −3744 / l i b / systemd / systemd−timesyncd Feb 23 0 8 : 5 5 : 4 6 b i o n i c −t e s t systemd [ 1 ] : S t a r t i n g Network Time S y n c h r o n i z a t i o n . . . Feb 23 0 8 : 5 5 : 4 6 b i o n i c −t e s t systemd [ 1 ] : S t a r t e d Network Time S y n c h r o n i z a t i o n . Feb 23 0 8 : 5 5 : 4 6 b i o n i c −t e s t systemd−timesyncd [ 3 7 4 4 ] : S y n c h r o n i z e d t o time s e r v e r 9 1 . 1 8 9 . 8 9 . 1 9 8 : 1 2 3 ( ntp . ubuntu . com ) . The nameserver to fetch time for timedatectl and timesyncd from can be specified in /etc/systemd/timesyncd .conf and additional config files can be stored in /etc/systemd/timesyncd.conf.d/. The entries for NTP= and FallbackNTP= are space separated lists. See man timesyncd.conf for more. Serve the Network Time Protocol If in addition to synchronizing your system you also want to serve NTP information you need an NTP server. There are several options with chrony, ntpd and open-ntp. The recommended solution is chrony. chrony(d) The NTP daemon chronyd calculates the drift and offset of your system clock and continuously adjusts it, so there are no large corrections that could lead to inconsistent logs for instance. The cost is a little processing power and memory, but for a modern server this is usually negligible. Installation To install chrony, from a terminal prompt enter: sudo apt i n s t a l l chrony This will provide two binaries: 60 • chronyd - the actual daemon to sync and serve via the NTP protocol • chronyc - command-line interface for chrony daemon Chronyd Configuration Edit /etc/chrony/chrony.conf to add/remove server lines. By default these servers are configured: # Use s e r v e r s from t h e NTP Pool P r o j e c t . Approved by Ubuntu T e c h n i c a l Board # on 2011−02−08 (LP : #104525) . See h t t p : / /www. p o o l . ntp . o r g / j o i n . html f o r # more i n f o r m a t i o n . p o o l 0 . ubuntu . p o o l . ntp . o r g i b u r s t p o o l 1 . ubuntu . p o o l . ntp . o r g i b u r s t p o o l 2 . ubuntu . p o o l . ntp . o r g i b u r s t p o o l 3 . ubuntu . p o o l . ntp . o r g i b u r s t See man chrony.conf for more details on the configuration options. After changing the any of the config file you have to restart chrony: sudo s y s t e m c t l r e s t a r t chrony . s e r v i c e Of the pool 2.ubuntu.pool.ntp.org as well as ntp.ubuntu.com also support ipv6 if needed. If one needs to force ipv6 there also is ipv6.ntp.ubuntu.com which is not configured by default. View status Use chronyc to see query the status of the chrony daemon. For example to get an overview of the currently available and selected time sources. chronyc s o u r c e s MS Name/ IP a d d r e s s Stratum P o l l Reach LastRx Last sample =============================================================================== ^+ gamma . r u e c k g r . a t 2 8 377 135 −1048 us [ −1048 us ] +/− 29 ms ^− 2b . ncomputers . o r g 2 8 377 204 −1141 us [ −1124 us ] +/− 50 ms ^+ www. k a s h r a . com 2 8 377 139 +3483 us [+3483 us ] +/− 18 ms ^+ stratum2 −4.NTP. TechFak . U> 2 8 377 143 −2090 us [ −2073 us ] +/− 19 ms ^− z e p t o . mcl . gg 2 7 377 9 −774 us [ −774 us ] +/− 29 ms ^− m i r r o r h o s t . pw 2 7 377 78 −660 us [ −660 us ] +/− 53 ms ^− a t t o . mcl . gg 2 7 377 8 −823 us [ −823 us ] +/− 50 ms ^− s t a t i c . 1 4 0 . 1 0 7 . 4 6 . 7 8 . c l i > 2 8 377 9 −1503 us [ −1503 us ] +/− 45 ms ^− 4 . 5 3 . 1 6 0 . 7 5 2 8 377 137 −11ms [ −11ms ] +/− 117 ms ^− 3 7 . 4 4 . 1 8 5 . 4 2 3 7 377 10 −3274 us [ −3274 us ] +/− 70 ms 61 ^− b a g n i k i t a . com 2 7 377 74 +3131 us [+3131 us ] +/− 71 ms ^− europa . e l l i p s e . n e t 2 8 377 204 −790 us [ −773 us ] +/− 97 ms ^− t e t h y s . hot− c h i l l i . n e t 2 8 377 141 −797 us [ −797 us ] +/− 59 ms ^− 66−232−97−8. s t a t i c . hvvc .> 2 7 377 206 +1669 us [+1686 us ] +/− 133 ms ^+ 8 5 . 1 9 9 . 2 1 4 . 1 0 2 1 8 377 205 +175 us [ +192 us ] +/− 12 ms ^* 46−243−26−34. t a n g o s . n l 1 8 377 141 −123 us [ −106 us ] +/− 10 ms ^− pugot . c a n o n i c a l . com 2 8 377 21 −95us [ −95us ] +/− 57 ms ^− alphyn . c a n o n i c a l . com 2 6 377 23 −1569 us [ −1569 us ] +/− 79 ms ^− golem . c a n o n i c a l . com 2 7 377 92 −1018 us [ −1018 us ] +/− 31 ms ^− c h i l i p e p p e r . c a n o n i c a l . com 2 8 377 21 −1106 us [ −1106 us ] +/− 27 ms chronyc s o u r c e s t a t s 210 Number o f s o u r c e s = 20 Name/ IP Address NP NR Span Frequency Freq Skew O f f s e t Std Dev ============================================================================== gamma . r u e c k g r . a t 25 15 32m −0.007 0 . 1 4 2 −878 us 106 us 2b . ncomputers . o r g 26 16 35m −0.132 0 . 2 8 3 −1169 us 256 us www. k a s h r a . com 25 15 32m −0.092 0 . 2 5 9 +3426 us 195 us stratum2 −4.NTP. TechFak . U> 25 14 32m −0.018 0 . 1 3 0 −2056 us 96 us z e p t o . mcl . gg 13 11 21m +0.148 0 . 1 9 6 −683 us 66 us m i r r o r h o s t . pw 6 5 645 +0.117 0 . 4 4 5 −591 us 19 us a t t o . mcl . gg 21 13 25m −0.069 0 . 1 9 9 −904 us 103 us s t a t i c . 1 4 0 . 1 0 7 . 4 6 . 7 8 . c l i > 25 18 34m −0.005 0 . 0 9 4 −1526 us 78 us 4 . 5 3 . 1 6 0 . 7 5 25 10 32m +0.412 0 . 1 1 0 −11ms 84 us 3 7 . 4 4 . 1 8 5 . 4 2 24 12 30m −0.983 0 . 1 7 3 −3718 us 122 us b a g n i k i t a . com 17 7 31m −0.132 0 . 2 1 7 +3527 us 139 us europa . e l l i p s e . n e t 26 15 35m +0.038 0 . 5 5 3 −473 us 424 us t e t h y s . hot− c h i l l i . n e t 25 11 32m −0.094 0 . 1 1 0 −864 us 88 us 66−232−97−8. s t a t i c . hvvc .> 20 11 35m −0.116 0 . 1 6 5 +1561 us 109 us 8 5 . 1 9 9 . 2 1 4 . 1 0 2 26 11 35m −0.054 0 . 3 9 0 +129 us 343 us 46−243−26−34. t a n g o s . n l 25 16 32m +0.129 0 . 2 9 7 −307 us 198 us pugot . c a n o n i c a l . com 25 14 34m −0.271 0 . 1 7 6 −143 us 135 us alphyn . c a n o n i c a l . com 17 11 1100 −0.087 0 . 3 6 0 −1749 us 114 us golem . c a n o n i c a l . com 23 12 30m +0.057 0 . 3 7 0 −988 us 229 us c h i l i p e p p e r . c a n o n i c a l . com 25 18 34m −0.084 0 . 2 2 4 −1116 us 169 us Certain chronyc commands are privileged and can not be run via the network without explicitly allowing them. See section Command and monitoring access in man chrony.conf for more details. A local admin can use sudo as usually as this will grant him access to the local admin socket /var/run/chrony/chronyd.sock. 62 PPS Support Chrony supports various PPS types natively. It can use kernel PPS API as well as PTP hardware clock. Most general GPS receivers can be leveraged via GPSD. The latter (and potentially more) can be accessed via SHM or via a socket (recommended). All of the above can be used to augment chrony with additional high quality time sources for better accuracy, jitter, drift, longer-or-short term accuracy (Usually each kind of clock type is good at one of those, but non-perfect at the others). For more details on configuration see some of the external PPS/GPSD resource listed below. Note: at the release of 20.04 there was a bug which until fixed you might want to add this content to your /etc/apparmor.d/local/usr.sbin.gpsd. Example configuration for GPSD to feed Chrony For the setup you need $ sudo apt install gpsd chrony But you will want to test/debug your setup and especially the GPS reception, therefore also install $ sudo apt install pps−tools gpsd−clients GPS devices usually will communicate via serial interfaces, yet the most common type these days are USB GPS devices which have a serial converter behind USB. If you want to use this for PPS please be aware that the majority does not signal PPS via USB. Check the GPSD hardware list for details. The examples below were run with a Navisys GR701-W. When plugging in such a device (or at boot time) dmesg should report serial connection of some sorts, example: [ 5 2 . 4 4 2 1 9 9 ] usb 1 −1.1: new f u l l −s p e e d USB d e v i c e number 3 u s i n g xhci_hcd [ 5 2 . 5 4 6 6 3 9 ] usb 1 −1.1: New USB d e v i c e found , idVendor =067b , i d P r o d u c t =2303 , bcdDevice= 4 . 0 0 [ 5 2 . 5 4 6 6 5 4 ] usb 1 −1.1: New USB d e v i c e s t r i n g s : Mfr=1, Product =2, SerialNumber=0 [ 5 2 . 5 4 6 6 6 5 ] usb 1 −1.1: Product : USB−S e r i a l C o n t r o l l e r D [ 5 2 . 5 4 6 6 7 5 ] usb 1 −1.1: Manufacturer : P r o l i f i c Technology I n c . [ 5 2 . 6 0 2 1 0 3 ] u s b c o r e : r e g i s t e r e d new i n t e r f a c e d r i v e r u s b s e r i a l _ g e n e r i c [ 5 2 . 6 0 2 2 4 4 ] u s b s e r i a l : USB S e r i a l s u p p o r t r e g i s t e r e d f o r g e n e r i c [ 5 2 . 6 0 9 4 7 1 ] u s b c o r e : r e g i s t e r e d new i n t e r f a c e d r i v e r p l 2 3 0 3 [ 5 2 . 6 0 9 5 0 3 ] u s b s e r i a l : USB S e r i a l s u p p o r t r e g i s t e r e d f o r p l 2 3 0 3 [ 5 2 . 6 0 9 5 6 4 ] p l 2 3 0 3 1 − 1 . 1 : 1 . 0 : p l 2 3 0 3 c o n v e r t e r d e t e c t e d [ 5 2 . 6 1 8 3 6 6 ] usb 1 −1.1: p l 2 3 0 3 c o n v e r t e r now a t t a c h e d t o ttyUSB0 We see above that it appeared as ttyUSB0. To later on have chrony accept being feeded time information by that we have to set it up in /etc/chrony/chrony.conf (Please replace USB0 to whatever applies to your setup): r e f c l o c k SHM 0 r e f i d GPS p r e c i s i o n 1 e−1 o f f s e t 0 . 9 9 9 9 d e l a y 0 . 2 r e f c l o c k SOCK / var / run / chrony . ttyUSB0 . s o c k r e f i d PPS Then restart chrony to make the socket available and waiting. sudo systemctl restart chrony Next one needs to tell gpsd which device to manager, therefore in /etc/default/gpsd we set: DEVICES=”/ dev/ttyUSB0” Furthermore the default use-case of gpsd is, well for gps position tracking. Therefore it will normally not consume any cpu since it is not running the service but waiting on a socket for clients. Furthermore the client will then tell gpsd what it requests and gpsd will only do that. For the use case of gpsd as PPS-providing- daemon you want to set the option to: 63 • immediately start even without a client connected, this can be set in GPSD_OPTIONS of /etc/default /gpsd: – GPSD_OPTIONS=”−n” • enable the service itself and not wait for a client to reach the socket in the future: – sudo systemctl enable /lib/systemd/system/gpsd.service Restarting gpsd will now initialize the PPS from GPS and in dmesg you will see p p s _ l d i s c : PPS l i n e d i s c i p l i n e r e g i s t e r e d pps pps0 : new PPS s o u r c e u s b s e r i a l 0 pps pps0 : s o u r c e ”/ dev /ttyUSB0 ” added In case you have multiple PPS the tool ppsfind might be useful to identify which PPS belongs to which GPS. You could check that with: $ sudo p p s f i n d / dev /ttyUSB0 pps0 : name=u s b s e r i a l 0 path=/dev /ttyUSB0 To get any further you need your GPS to get a lock. Tools like cgps or gpsmon need to report a 3D Fix for the data being any good. Then you’d want to check to really have PPS data reported on that with ppstest $ c g p s . . . � S t a t u s : 3D FIX ( 7 s e c s ) . . . Next one might want to ensure that the pps device really submits PPS data, to do so run ppstest: $ sudo p p s t e s t / dev / pps0 t r y i n g PPS s o u r c e ”/ dev / pps0 ” found PPS s o u r c e ”/ dev / pps0 ” ok , found 1 s o u r c e ( s ) , now s t a r t f e t c h i n g data . . . s o u r c e 0 − a s s e r t 1 5 8 8 1 4 0 7 3 9 . 0 9 9 5 2 6 2 4 6 , s e q u e n c e : 69 − c l e a r 1 5 8 8 1 4 0 7 3 9 . 9 9 9 6 6 3 7 2 1 , s e q u e n c e : 70 s o u r c e 0 − a s s e r t 1 5 8 8 1 4 0 7 4 0 . 0 9 9 6 6 1 4 8 5 , s e q u e n c e : 70 − c l e a r 1 5 8 8 1 4 0 7 3 9 . 9 9 9 6 6 3 7 2 1 , s e q u e n c e : 70 s o u r c e 0 − a s s e r t 1 5 8 8 1 4 0 7 4 0 . 0 9 9 6 6 1 4 8 5 , s e q u e n c e : 70 − c l e a r 1 5 8 8 1 4 0 7 4 0 . 9 9 9 7 8 6 6 6 4 , s e q u e n c e : 71 s o u r c e 0 − a s s e r t 1 5 8 8 1 4 0 7 4 1 . 0 9 9 7 9 2 4 4 7 , s e q u e n c e : 71 − c l e a r 1 5 8 8 1 4 0 7 4 0 . 9 9 9 7 8 6 6 6 4 , s e q u e n c e : 71 Ok, gpsd is now running, the GPS reception has found a fix and this is fed into chrony. Now lets check that from the point of view of chrony. Initially (e.g. before gpsd has started or before it has a lock) those will be new and “untrusted” sources marked with an “?”. If your devices stay in the “?” state and won’t leave it even after quite some time then gpsd seems not to feed any data to chrony and you’d need to debug why. chronyc> s o u r c e s 210 Number o f s o u r c e s = 10 MS Name/ IP a d d r e s s Stratum P o l l Reach LastRx Last sample =============================================================================== #? GPS 0 4 0 − +0ns [ +0ns ] +/− 0 ns #? PPS 0 4 0 − +0ns [ +0ns ] +/− 0 ns Over time chrony will classify them as good or bad. In the example case the raw GPS had too much deviation but PPS is good. 64 chronyc> s o u r c e s 210 Number o f s o u r c e s = 10 MS Name/ IP a d d r e s s Stratum P o l l Reach LastRx Last sample =============================================================================== #x GPS 0 4 177 24 −876ms [ −876ms ] +/− 200ms #− PPS 0 4 177 21 +916 us [ +916 us ] +/− 63 us ^− c h i l i p e p p e r . c a n o n i c a l . com 2 6 37 53 +33us [ +33us ] +/− 33ms And finally after a while it used the hardware PPS input as it was better: chronyc> s o u r c e s 210 Number o f s o u r c e s = 10 MS Name/ IP a d d r e s s Stratum P o l l Reach LastRx Last sample =============================================================================== #x GPS 0 4 377 20 −884ms [ −884ms ] +/− 200 ms #* PPS 0 4 377 18 +6677 ns [ +52us ] +/− 58 us ^− alphyn . c a n o n i c a l . com 2 6 377 20 −1303 us [ −1258 us ] +/− 114 ms The PPS might also be ok but used in a combined way with e.g. the selected server. See man chronyc for more details about how all these combinations will look like. chronyc> s o u r c e s 210 Number o f s o u r c e s = 11 MS Name/ IP a d d r e s s Stratum P o l l Reach LastRx Last sample =============================================================================== #? GPS 0 4 0 − +0ns [ +0ns ] +/− 0 ns #+ PPS 0 4 377 22 +154 us [ +154 us ] +/− 8561 us ^* c h i l i p e p p e r . c a n o n i c a l . com 2 6 377 50 −353 us [ −300 us ] +/− 44 ms And if you wonder if your shm based GPS data is any good, you can check for that as well. First of all chrony will not only tell you if it classified it as good or bad. Via sourcestats you can also check the details chronyc> s o u r c e s t a t s 210 Number o f s o u r c e s = 10 Name/ IP Address NP NR Span Frequency Freq Skew O f f s e t Std Dev ============================================================================== GPS 20 9 302 +1.993 1 1 . 5 0 1 −868ms 1208 us PPS 6 3 78 +0.324 5 . 0 0 9 +3365 ns 41 us golem . c a n o n i c a l . com 15 10 783 +0.859 0 . 5 0 9 −750 us 108 us You can also track the raw data that gpsd or other ntpd compliant refclocks are sending via shared memory by using ntpshmmon: $ sudo ntpshmmon −o ntpshmmon : v e r s i o n 3 . 2 0 # Name O f f s e t Clock Real L Prc 65 sample NTP1 0 . 0 0 0 2 2 3 8 5 4 1 5 8 8 2 6 5 8 0 5 . 0 0 0 2 2 3 8 5 4 1 5 8 8 2 6 5 8 0 5 . 0 0 0 0 0 0 0 0 0 0 −10 sample NTP0 0 . 1 2 5 6 9 1 7 8 3 1 5 8 8 2 6 5 8 0 5 . 1 2 5 9 9 9 8 5 1 1 5 8 8 2 6 5 8 0 5 . 0 0 0 3 0 8 0 6 8 0 −20 sample NTP1 0 . 0 0 0 3 4 9 3 4 1 1 5 8 8 2 6 5 8 0 6 . 0 0 0 3 4 9 3 4 1 1 5 8 8 2 6 5 8 0 6 . 0 0 0 0 0 0 0 0 0 0 −10 sample NTP0 0 . 1 3 0 3 2 6 6 3 6 1 5 8 8 2 6 5 8 0 6 . 1 3 0 6 3 4 9 4 5 1 5 8 8 2 6 5 8 0 6 . 0 0 0 3 0 8 3 0 9 0 −20 sample NTP1 0 . 0 0 0 4 8 5 2 1 6 1 5 8 8 2 6 5 8 0 7 . 0 0 0 4 8 5 2 1 6 1 5 8 8 2 6 5 8 0 7 . 0 0 0 0 0 0 0 0 0 0 −10 References • Chrony FAQ • ntp.org: home of the Network Time Protocol project • pool.ntp.org: project of virtual cluster of timeservers • Freedesktop.org info on timedatectl • Freedesktop.org info on systemd-timesyncd service • Feeding chrony from GPSD • See the Ubuntu Time wiki page for more information. Download 1.27 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling