One place for hosting & domains

      Synchronization

      How To Set Up Time Synchronization on Ubuntu 20.04


      Introduction

      Accurate timekeeping is integral to modern software deployments. Without it, you may encounter data corruption, errors, and other issues that are difficult to debug. Time synchronization can help ensure your logs are being recorded in the correct order, and that database updates are appropriately applied.

      Fortunately, Ubuntu 20.04 has time synchronization built-in and activated by default using systemd’s timesyncd service. In this article, you will practice some general time-related commands, verify that timesyncd is active, and install an alternate network time service.

      Prerequisites

      Before starting this tutorial, you will need an Ubuntu 20.04 server with a non-root, sudo-enabled user and a firewall, as described in this Ubuntu 20.04 server setup tutorial.

      To view the time on your server, you will use the command date. Any user can run this command to print out the date and time:

      Typically, your server will generate an output with the default UTC time zone.

      Output

      Thu Aug 5 15:55:20 UTC 2021

      UTC is Coordinated Universal Time, the time at zero degrees longitude. While this may not reflect your current time zone, using Universal Time prevents confusion when your infrastructure spans multiple time zones.

      If you want to change your time zone, however, you can use the timedatectl command.

      First, run this command to generate a list of available time zones:

      • timedatectl list-timezones

      A list of time zones will print to your screen. You can press SPACE to page down, and b to page up. Once you find the correct time zone, make note of it then type q to exit the list.

      Next, you can set the time zone with timedatectl set-timezone by replacing the highlighted portion with the time zone you found in the list. You’ll need to use sudo with timedatectl to make this change:

      • sudo timedatectl set-timezone America/New_York

      You can verify your changes by running date again:

      Output

      Thu Aug 5 11:56:01 EDT 2021

      The time zone abbreviation will reflect the newly chosen value.

      Now that you’ve practiced checking the clock and setting time zones, you can confirm that your time is being synchronized properly in the next section.

      Controlling timesyncd with timedatectl

      Previously, most network time synchronization was handled by the Network Time Protocol daemon or ntpd. This service connects to a pool of other NTP servers that provide it with constant and accurate time updates.

      But now with Ubuntu’s default install, you can use timesyncd instead of ntpd. timesyncd works similarly by connecting to the same time servers, but is llightweight and more closely integrated with systemd on Ubuntu.

      You can query the status of timesyncd by running timedatectl with no arguments. You don’t need to use sudo in this case:

      Output

      Local time: Thu 2021-08-05 11:56:40 EDT Universal time: Thu 2021-08-05 15:56:40 UTC RTC time: Thu 2021-08-05 15:56:41 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no

      This command prints out the local time, universal time (which may be the same as local time, if you didn’t switch from the UTC time zone), and some network time status information. System clock synchronized: yes reflects that the time is successfully synced, and NTP service: active means that timesyncd is up and running.

      If your output shows that NTP service isn’t active, turn it on with timedatectl:

      • sudo timedatectl set-ntp on

      After this, run timedatectl again to confirm the network time status. It may take a minute for the sync to happen, but eventually System clock synchronized: will read yes and NTP service: will show as active.

      Switching to ntpd

      timesyncd will work in most circumstances. There are instances, however, when an application may be sensitive to any disturbance with time. In this case, ntpd is an alternative network time service you can use. ntpd uses sophisticated techniques to constantly and gradually keep the system time on track.

      Before installing ntpd, you need to turn off timesyncd in order to prevent the two services from conflicting with one another. You can do this by disabling network time synchronization with the following command:

      • sudo timedatectl set-ntp no

      Verify that time synchronization is disabled:

      Check that your output reads NTP service: inactive. This means timesyncd has stopped. Now you’re ready to install the ntp package with apt.

      First, run apt update to refresh your local package index:

      Then, run apt install ntp to install this package:

      ntpd will begin automatically after your installation completes. You can verify that everything is working correctly by querying ntpd for status information:

      Output

      remote refid st t when poll reach delay offset jitter ============================================================================== 0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000 +t1.time.bf1.yah 129.6.15.28 2 u 16 64 1 61.766 -20.068 1.964 +puppet.kenyonra 80.72.67.48 3 u 16 64 1 2.622 -18.407 2.407 *ntp3.your.org .GPS. 1 u 15 64 1 50.303 -17.499 2.708 +time.cloudflare 10.4.1.175 3 u 15 64 1 1.488 -18.295 2.670 +mis.wci.com 216.218.254.202 2 u 15 64 1 21.527 -18.377 2.414 +ipv4.ntp1.rbaum 69.89.207.99 2 u 12 64 1 49.741 -17.897 3.417 +time.cloudflare 10.4.1.175 3 u 15 64 1 1.039 -16.692 3.378 +108.61.73.243 129.6.15.29 2 u 14 64 1 70.060 -16.993 3.363 +ny-time.gofile. 129.6.15.28 2 u 21 64 1 75.349 -18.333 2.763 golem.canonical 17.253.34.123 2 u 28 64 1 134.482 -21.655 0.000 ntp3.junkemailf 216.218.254.202 2 u 19 64 1 2.632 -16.330 4.387 clock.xmission. .XMIS. 1 u 18 64 1 24.927 -16.712 3.415 alphyn.canonica 142.3.100.2 2 u 26 64 1 73.612 -19.371 0.000 strongbad.voice 192.5.41.209 2 u 17 64 1 70.766 -18.159 3.481 chilipepper.can 17.253.34.123 2 u 25 64 1 134.982 -19.848 0.000 pugot.canonical 145.238.203.14 2 u 28 64 1 135.694 -21.075 0.000

      ntpq is a query tool for ntpd. The -p flag requests information about the NTP servers (or peers) ntpd is connected to. Your output will be slightly different but will list the default Ubuntu pool servers plus a few others. Remember, it can take a few minutes for ntpd to establish connections.

      Conclusion

      In this article, you’ve successfully viewed the system time, changed time zones, worked with Ubuntu’s default timesyncd service, and installed ntpd. If you have advanced timekeeping needs, you can reference the official NTP documentation, and also take a look at the NTP Pool Project, a global group of volunteers providing much of the world’s NTP infrastructure.



      Source link

      How To Set Up Time Synchronization on Debian 10


      Introduction

      Accurate timekeeping has become a critical component of modern software deployments. Whether it’s making sure logs are recorded in the right order or database updates are applied correctly, out-of-sync time can cause errors, data corruption, and other difficult issues to debug.

      Debian 10 has time synchronization built in and activated by default using the standard ntpd time server, provided by the ntp package. In this article we will look at some basic time-related commands, verify that ntpd is active and connected to peers, and learn how to activate the alternate systemd-timesyncd network time service.

      Prerequisites

      Before starting this tutorial, you will need a Debian 10 server with a non-root, sudo-enabled user, as described in this Debian 10 server setup tutorial.

      Step 1 — Navigating Basic Time Commands

      The most basic command for finding out the time on your server is date. Any user can type this command to print out the date and time:

      Output

      Wed 31 Jul 2019 06:03:19 PM UTC

      Most often your server will default to the UTC time zone, as highlighted in the above output. UTC is Coordinated Universal Time, the time at zero degrees longitude. Consistently using Universal Time reduces confusion when your infrastructure spans multiple time zones.

      If you have different requirements and need to change the time zone, you can use the timedatectl command to do so.

      First, list the available time zones:

      • timedatectl list-timezones

      A list of time zones will print to your screen. You can press SPACE to page down, and b to page up. Once you find the correct time zone, make note of it then type q to exit the list.

      Now set the time zone with timedatectl set-timezone, making sure to replace the highlighted portion below with the time zone you found in the list. You'll need to use sudo with timedatectl to make this change:

      • sudo timedatectl set-timezone America/New_York

      You can verify your changes by running date again:

      Output

      Wed 31 Jul 2019 02:08:43 PM EDT

      The time zone abbreviation should reflect the newly chosen value.

      Now that we know how to check the clock and set time zones, let’s make sure our time is being synchronized properly.

      Step 2 — Checking the Status of ntpd

      By default, Debian 10 runs the standard ntpd server to keep your system time synchronized with a pool of external time servers. We can check that it's running with the systemctl command:

      • sudo systemctl status ntp

      Output

      ● ntp.service - Network Time Service Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-07-31 13:57:08 EDT; 17min ago Docs: man:ntpd(8) Main PID: 429 (ntpd) Tasks: 2 (limit: 1168) Memory: 2.1M CGroup: /system.slice/ntp.service └─429 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:112 . . .

      The active (running) status indicates that ntpd started up properly. To get more information about the status of ntpd we can use the ntpq command:

      Output

      remote refid st t when poll reach delay offset jitter ============================================================================== 0.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 1.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 2.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 3.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 +208.67.72.50 152.2.133.55 2 u 12 64 377 39.381 1.696 0.674 +198.46.223.227 204.9.54.119 2 u 6 64 377 22.671 3.536 1.818 -zinc.frizzen.ne 108.61.56.35 3 u 43 64 377 12.012 1.268 2.553 -pyramid.latt.ne 204.123.2.72 2 u 11 64 377 69.922 2.858 0.604 +nu.binary.net 128.252.19.1 2 u 10 64 377 35.362 3.148 0.587 #107.155.79.108 129.7.1.66 2 u 65 64 377 42.380 1.638 1.014 +t1.time.bf1.yah 98.139.133.62 2 u 6 64 377 11.233 3.305 1.118 *sombrero.spider 129.6.15.30 2 u 47 64 377 1.304 2.941 0.889 +hydrogen.consta 209.51.161.238 2 u 45 64 377 1.830 2.280 1.026 -4.53.160.75 142.66.101.13 2 u 42 64 377 29.077 2.997 0.789 #horp-bsd01.horp 146.186.222.14 2 u 39 64 377 16.165 4.189 0.717 -ntpool1.603.new 204.9.54.119 2 u 46 64 377 27.914 3.717 0.939

      ntpq is a query tool for ntpd. The -p flag asks for information about the NTP servers (or peers) ntpd is connected to. Your output will be slightly different, but should list the default Debian pool servers plus a few others. Bear in mind that it can take a few minutes for ntpd to establish connections.

      Step 3 — Switching to systemd-timesyncd

      It is possible to use systemd's built-in timesyncd component to replace ntpd. timesyncd is a lighter-weight alternative to ntpd that is more integrated with systemd. Note, however, that it doesn't support running as a time server, and it is slightly less sophisticated in the techniques it uses to keep your system time in sync. If you are running complex real-time distributed systems, you may want to stick with ntpd.

      To use timesyncd, we must first uninstall ntpd:

      Then, start up the timesyncd service:

      • sudo systemctl start systemd-timesyncd

      Finally, check the status of the service to make sure it's running:

      • sudo systemctl status systemd-timesyncd

      Output

      ● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Drop-In: /usr/lib/systemd/system/systemd-timesyncd.service.d └─disable-with-time-daemon.conf Active: active (running) since Wed 2019-07-31 14:21:37 EDT; 6s ago Docs: man:systemd-timesyncd.service(8) Main PID: 1681 (systemd-timesyn) Status: "Synchronized to time server for the first time 96.245.170.99:123 (0.debian.pool.ntp.org)." Tasks: 2 (limit: 1168) Memory: 1.3M CGroup: /system.slice/systemd-timesyncd.service └─1681 /lib/systemd/systemd-timesyncd

      We can use timedatectl to print out systemd's current understanding of the time:

      Output

      Local time: Wed 2019-07-31 14:22:15 EDT Universal time: Wed 2019-07-31 18:22:15 UTC RTC time: n/a Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no

      This prints out the local time, universal time (which may be the same as local time, if you didn't switch from the UTC time zone), and some network time status information. System clock synchronized: yes means that the time has been successfully synced, and NTP service: active means that timesyncd is enabled and running.

      Conclusion

      In this article we’ve shown how to view the system time, change time zones, work with ntpd, and switch to systemd's timesyncd service. If you have more sophisticated timekeeping needs than what we’ve covered here, you might refer to the offical NTP documentation, and also take a look at the NTP Pool Project, a global group of volunteers providing much of the world's NTP infrastructure.



      Source link

      How To Set Up Time Synchronization on Debian 9


      Introduction

      Accurate timekeeping has become a critical component of modern software deployments. Whether it’s making sure logs are recorded in the right order or database updates are applied correctly, out-of-sync time can cause errors, data corruption, and other hard to debug issues.

      Debian 9 has time synchronization built in and activated by default using the standard ntpd time server, provided by the ntp package. In this article we will look at some basic time-related commands, verify that ntpd is active and connected to peers, and learn how to activate the alternate systemd-timesyncd network time service.

      Prerequisites

      Before starting this tutorial, you will need a Debian 9 server with a non-root, sudo-enabled user, as described in this Debian 9 server setup tutorial.

      The most basic command for finding out the time on your server is date. Any user can type this command to print out the date and time:

      Output

      Tue Sep 4 17:51:49 UTC 2018

      Most often your server will default to the UTC time zone, as highlighted in the above output. UTC is Coordinated Universal Time, the time at zero degrees longitude. Consistently using Universal Time reduces confusion when your infrastructure spans multiple time zones.

      If you have different requirements and need to change the time zone, you can use the timedatectl command to do so.

      First, list the available time zones:

      • timedatectl list-timezones

      A list of time zones will print to your screen. You can press SPACE to page down, and b to page up. Once you find the correct time zone, make note of it then type q to exit the list.

      Now set the time zone with timedatectl set-timezone, making sure to replace the highlighted portion below with the time zone you found in the list. You'll need to use sudo with timedatectl to make this change:

      • sudo timedatectl set-timezone America/New_York

      You can verify your changes by running date again:

      Output

      Tue Sep 4 13:52:57 EDT 2018

      The time zone abbreviation should reflect the newly chosen value.

      Now that we know how to check the clock and set time zones, let’s make sure our time is being synchronized properly.

      Checking the Status of ntpd

      By default, Debian 9 runs the standard ntpd server to keep your system time synchronized with a pool of external time servers. We can check that it's running with the systemctl command:

      • sudo systemctl status ntp

      Output

      ● ntp.service - LSB: Start NTP daemon Loaded: loaded (/etc/init.d/ntp; generated; vendor preset: enabled) Active: active (running) since Tue 2018-09-04 15:07:03 EDT; 30min ago Docs: man:systemd-sysv-generator(8) Process: 876 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS) Tasks: 2 (limit: 4915) CGroup: /system.slice/ntp.service └─904 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 105:109 . . .

      The active (running) status indicates that ntpd started up properly. To get more information about the status of ntpd we can use the ntpq command:

      Output

      remote refid st t when poll reach delay offset jitter ============================================================================== 0.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 1.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 2.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 3.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000 -eterna.binary.n 204.9.54.119 2 u 240 256 377 35.392 0.142 0.211 -static-96-244-9 192.168.10.254 2 u 60 256 377 10.242 1.297 2.412 +minime.fdf.net 83.157.230.212 3 u 99 256 377 24.042 0.128 0.250 *t1.time.bf1.yah 98.139.133.62 2 u 31 256 377 11.112 0.621 0.186 +x.ns.gin.ntt.ne 249.224.99.213 2 u 108 256 377 1.290 -0.073 0.132 -ord1.m-d.net 142.66.101.13 2 u 473 512 377 19.930 -1.764 0.293

      ntpq is a query tool for ntpd. The -p flag asks for information about the NTP servers (or peers) ntpd is connected to. Your output will be slightly different, but should list the default Debian pool servers plus a few others. Bear in mind that it can take a few minutes for ntpd to establish connections.

      Switching to systemd-timesyncd

      It is possible to use systemd's built-in timesyncd component to replace ntpd. timesyncd is a lighter-weight alternative to ntpd that is more integrated with systemd. Note however that it doesn't support running as a time server, and it is slightly less sophisticated in the techniques it uses to keep your system time in sync. If you are running complex real-time distributed systems, you may want to stick with ntpd.

      To use timesyncd, we must first uninstall ntpd:

      Then, start up the timesyncd service:

      • sudo systemctl start systemd-timesyncd

      Finally, check the status of the service to make sure it's running:

      • sudo systemctl status systemd-timesyncd

      Output

      ● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/systemd-timesyncd.service.d └─disable-with-time-daemon.conf Active: active (running) since Tue 2018-09-04 16:14:23 EDT; 1s ago Docs: man:systemd-timesyncd.service(8) Main PID: 3399 (systemd-timesyn) Status: "Synchronized to time server 198.60.22.240:123 (0.debian.pool.ntp.org)." Tasks: 2 (limit: 4915) CGroup: /system.slice/systemd-timesyncd.service └─3399 /lib/systemd/systemd-timesyncd

      We can use timedatectl to print out systemd's current understanding of the time:

      Output

      Local time: Tue 2018-09-04 16:15:34 EDT Universal time: Tue 2018-09-04 20:15:34 UTC RTC time: Tue 2018-09-04 20:15:33 Time zone: America/New_York (EDT, -0400) Network time on: yes NTP synchronized: yes RTC in local TZ: no

      This prints out the local time, universal time (which may be the same as local time, if you didn't switch from the UTC time zone), and some network time status information. Network time on: yes means that timesyncd is enabled, and NTP synchronized: yes indicates that the time has been successfully synced.

      Conclusion

      In this article we’ve shown how to view the system time, change time zones, work with ntpd, and switch to systemd's timesyncd service. If you have more sophisticated timekeeping needs than what we’ve covered here, you might refer to the offical NTP documentation, and also take a look at the NTP Pool Project, a global group of volunteers providing much of the world's NTP infrastructure.



      Source link