{"id":6714,"date":"2017-05-08T14:32:39","date_gmt":"2017-05-08T06:32:39","guid":{"rendered":"http:\/\/rmohan.com\/?p=6714"},"modified":"2017-05-08T14:32:39","modified_gmt":"2017-05-08T06:32:39","slug":"rhel-7-rhcsa-notes-configure-a-system-to-use-time-services","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6714","title":{"rendered":"RHEL 7 \u2013 RHCSA Notes : Configure a system to use time services"},"content":{"rendered":"<p>RHEL 7 has 3 command-line utilities to configure the system date and time:<br \/>\n1. date<br \/>\n2. hwclock<br \/>\n3. timedatectl<\/p>\n<p>date command<\/p>\n<p>Use the date command to display or set the system date and time. Run the date command with no arguments to display the current date and time:<\/p>\n<p># date<br \/>\nMon Sep 12 19:41:40 IST 2016<br \/>\nThe date command provides a variety of output formatting options. You can also time and date in future or past. Few examples are given below.<br \/>\n1. Display day of the week :<\/p>\n<p># date +%A<br \/>\nMonday<br \/>\n2. Display date one year from now :<\/p>\n<p># date -d &#8220;1 year&#8221;<br \/>\nMon Sep 12 19:47:49 IST 2017<br \/>\n3. Display 1 month past date :<\/p>\n<p># date -d &#8220;1 month ago&#8221;<br \/>\nMon Aug 12 19:49:07 IST 2016<br \/>\nUse the following syntax to change the current date. Replace YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.<\/p>\n<p># date +%D -s [YYYY-MM-DD]<br \/>\nUse the following syntax to change the current time. Replace HH with a two-digit hour, MM with a two-digit minute, and SS with a two-digit second. Include either AM or PM. Include the \u2013u option if your system clock is set to use UTC.<\/p>\n<p># date +%T%p -s [HH:MM:SS]AM|PM \u2013u<br \/>\nhwclock command<\/p>\n<p>Use the hwclock command to query and set the hardware clock, also known as the RTC (real-time clock). This clock runs independently of any control program running in the CPU and even when the machine is powered off. The hwclock command allows you to:<\/p>\n<p>Display the current time<br \/>\nSet the hardware clock to a specified time<br \/>\nSet the system time from the hardware clock (hwclock \u2013s)<br \/>\nSet the hardware clock to the current system time (hwclock \u2013w)<br \/>\ntimedatectl command<\/p>\n<p>\u2013 The timedatectl utility is part of the systemd system and service manager.<br \/>\n\u2013 To display local, universal, and RTC time and time zone, NTP configuration, and DST information:<\/p>\n<p># timedatectl<br \/>\n      Local time: Tue 2016-09-13 20:30:26 IST<br \/>\n  Universal time: Tue 2016-09-13 15:00:26 UTC<br \/>\n        RTC time: Tue 2016-09-13 15:00:26<br \/>\n       Time zone: Asia\/Kolkata (IST, +0530)<br \/>\n     NTP enabled: yes<br \/>\nNTP synchronized: yes<br \/>\n RTC in local TZ: no<br \/>\n      DST active: n\/a<br \/>\n\u2013 Use the following syntax to change the date and time:<\/p>\n<p># timedatectl set-time [YYYY-MM-DD]<br \/>\n# timedatectl set-time [HH:MM:SS]<br \/>\n\u2013 Use the following syntax to change the time zone:<\/p>\n<p># timedatectl set-timezone [time_zone]<br \/>\n\u2013 To list available time zones :<\/p>\n<p># timedatectl list-timezones<br \/>\nAfrica\/Abidjan<br \/>\nAfrica\/Accra<br \/>\nAfrica\/Addis_Ababa<br \/>\n\u2013 To enable clock synchronization over NTP:<\/p>\n<p># timedatectl set-ntp yes<br \/>\nUsing NTP<\/p>\n<p>NTP provides a method of verifying and correcting your computer\u2019s time by synchronizing it with another system.<br \/>\nTo install NTP :<\/p>\n<p># yum install ntp<br \/>\nBy default, there are four public server entries in the NTP configuration file, \/etc\/ntp.conf, which are specified by the server directive.<\/p>\n<p># grep server \/etc\/ntp.conf<br \/>\nserver 0.rhel.pool.ntp.org<br \/>\nserver 1.rhel.pool.ntp.org<br \/>\nserver 2.rhel.pool.ntp.org<br \/>\nserver 3.rhel.pool.ntp.org<br \/>\nInstead of using a predefined public server, you can specify a local reference server in the \/etc\/ntpd.conf file. For example:<\/p>\n<p># vi \/etc\/ntpd.conf<br \/>\nserver 192.0.2.1<br \/>\nAnother directive in the configuration file is driftfile. The default setting is as follows:<\/p>\n<p>driftfile \/var\/lib\/ntp\/drift<br \/>\nThis drift file contains one value used to adjust the system clock frequency after every system or service start.<\/p>\n<p>NTP daemon<\/p>\n<p>The ntpd program is the user space daemon that synchronizes the system clock with remote NTP time servers or local reference clocks. The daemon reads the configuration file at system start or when the service is restarted. You also need to open UDP port 123 in the firewall for NTP packets. After editing the \/etc\/ntp.conf file, use the systemctl command to start the NTP daemon:<\/p>\n<p># systemctl start ntpd<br \/>\nUse the following command to ensure the NTP daemon starts at boot time:<\/p>\n<p># systemctl enable ntpd<br \/>\nOther NTP utilities<\/p>\n<p>Use the ntpq command to query the NTP daemon operations and to determine performance. Use the \u2013p option (or peers command) to display a list of peers known to the server as well as a summary of their state. For example:<\/p>\n<p># ntpq -p<br \/>\n     remote           refid      st t when poll reach   delay   offset  jitter<br \/>\n==============================================================================<br \/>\n*10.10.0.2      192.168.2.11      2 u  911 1024  377    1.274    0.147   0.355<br \/>\n+10.10.0.3      192.168.2.11      2 u 1026 1024  377    1.161    0.073   0.852<br \/>\nThe * indicates your system is synchronized with the 10.10.0.2 server. Use the ntpstat command to show network time synchronization status.<\/p>\n<p># ntpstat<br \/>\nsynchronised to NTP server (10.10.0.2) at stratum 3<br \/>\n   time correct to within 31 ms<br \/>\n   polling server every 1024 s<br \/>\nConfiguring NTP using chrony<\/p>\n<p>Chrony is a suite of utilities that provides another implementation of NTP. Chrony is designed for mobile systems and virtual machines that are often powered down or disconnected from the network. Systems that are not permanently connected to a network take a relatively long time to adjust their system clocks with the NTP daemon, ntpd.<\/p>\n<p>Chrony consists of chronyd, a daemon that runs in user space, and chronyc, a command- line program for making adjustments to chronyd. The chronyd daemon makes adjustments to the system clock that is running in the kernel. It uses NTP to synchronize with another system when network access is available. When network access is not available, chronyd uses the last calculated drift stored in the drift file to synchronize the system time.<\/p>\n<p>For more information on chrony (installation, configuration, troubleshooting), refer the below posts :<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RHEL 7 has 3 command-line utilities to configure the system date and time: 1. date 2. hwclock 3. timedatectl<\/p>\n<p>date command<\/p>\n<p>Use the date command to display or set the system date and time. Run the date command with no arguments to display the current date and time:<\/p>\n<p># date Mon Sep 12 19:41:40 IST [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6714"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6714"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6714\/revisions"}],"predecessor-version":[{"id":6715,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6714\/revisions\/6715"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}