\errorcontextlines=99
%% Subtopic Number = '1.111.6'
%% Title from filename: 'Maintain system time'
%% Weight: 4
%% Description:
%% Candidate should be able to properly maintain the system
%%        time and synchronize the clock over NTP. Tasks include setting the
%%        system date and time, setting the BIOS clock to the correct time in UTC,
%%        configuring the correct timezone for the system and configuring the
%%        system to correct clock drift to match NTP clock.
%% Key files, terms, and utilities include:
%%        /usr/share/zoneinfo
%%        /etc/timezone
%%        /etc/localtime
%%        /etc/ntp.conf
%%        /etc/ntp.drift
%%        date
%%        hwclock
%%        ntpd
%%        ntpdate
\documentclass[10pt,hyperref={implicit=true}]{beamer}
\title{1.111.6\\Maintain system time\\Weight 4}
\author[Andrew Eager]{Andrew Eager \texttt{andrew.eager@aes-pl.com.au}
  \and Geoffrey Robertson \texttt{ge@ffrey.com} \and Nick Urbanik
  \texttt{nicku@nicku.org}\\
  {\tiny This document Licensed under GPL---see
    section~\ref{sec:license}}}%
\subtitle{Linux Professional Institute Certification --- 102}%
\mode<article>{\chead{1.111.6}}%

\mode<presentation>
{
  %\usetheme{Warsaw}
  \usetheme[hideothersubsections]{Goettingen}
  % or ...

  \setbeamercovered{transparent=80}
  % or whatever (possibly just delete it)

  \subject{LPIC 102}
}
\mode<article>
{
  \usepackage{url}
  \renewcommand{\floatpagefraction}{0.75} % default is .5, to increase
  % density.
  \renewcommand*{\bottomfraction}{0.6} % default is 0.3
  \renewcommand*{\topfraction}{0.85} % default is 0.7
  \renewcommand*{\textfraction}{0.1} % default is 0.2
  \pagestyle{fancy}
  \fancyhf{}
  \renewcommand{\sectionmark}[1]{\markright{\thesection. #1}}
  \lhead{\nouppercase{\rightmark}}
  \rhead{\thepage}
  \chead{1.111.6}%
}


\usepackage[english]{babel}
\usepackage{alltt,booktabs,array,cols,multicol,meta,acro}

\usepackage[utf8]{inputenc}
% or whatever

\usepackage{times}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\usepackage{xcolour-names}
\usepackage[normalem]{ulem}

\date{2005 September}


\AtBeginSubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \footnotesize
    \begin{multicols}{2}
      \tableofcontents[currentsection,currentsubsection]
    \end{multicols}
  \end{frame}
}

% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}

\newcounter{program}
%\newcommand*{\program}[1]{\refstepcounter{program}\label{#1}\arabic{program}}
% \newcommand*{\program}[1]{%
%    \refstepcounter{program}\hypertarget{#1}{Program \texttt{#1}}%
% }
%\newcommand*{\program}[1]{\refstepcounter{program}\label{#1}\arabic{program}}
\newcommand*{\program}[1]{%
   \hypertarget{#1}{Program \texttt{#1}}%
}

\newcommand*{\linkto}[1]{\hyperlink{#1}{\texttt{#1}}}
\providecommand*{\bs}{\texttt{\char '134}} % Backslash, no break

\newcommand{\cmd}[1]{%
  \texttt{\$ \textbf{#1 \(\hookleftarrow\)}}
}

\newcommand{\rootcmd}[1]{%
  \texttt{\# \textbf{#1 \(\hookleftarrow\)}}
}

\newcommand{\opt}[1]{%
  {\bfseries\texttt{#1}}
}

\begin{document}
\maketitle
\mode<article>{\thispagestyle{empty}}

% \begin{frame}
%   \titlepage
% \end{frame}

\begin{frame}
  \frametitle{Outline}
  \mode<presentation>
  {%
    \footnotesize
    \begin{multicols}{2}
      \tableofcontents
    \end{multicols}
    % You might wish to add the option [pausesections]
  }%
  \mode<article>
  {%
    \tableofcontents
  }%
\end{frame}

\section{Context}
\label{sec:context}

\begin{frame}
  \frametitle{Topic 111 Administrative Tasks [21]}%
  \framesubtitle{Where we are up to}%
    \begin{description}
    \item[1.111.1] Manage users and group accounts and related system
      files [4]
    \item[1.111.2] Tune the user environment and system environment
      variables [3]
    \item[1.111.3] Configure and use system log files to meet
      administrative and security needs [3]
    \item[1.111.4] Automate system administration tasks by scheduling
      jobs to run in the future [4]
    \item[1.111.5] Maintain an effective data backup strategy [3]
    % \uline depends on \usepackage[normalem]{ulem}:
    \item[1.111.6] \textbf{\uline{Maintain system time [4]}}
    \end{description}
\end{frame}

\section{Objective}
\label{sec:objective}

\begin{frame}
  \frametitle{Description of Objective}%
  \framesubtitle{1.111.6\ \ Maintain system time}%
  \mode<presentation>{\Large}%
  Candidate should be able to properly maintain the system time and
  synchronize the clock over NTP\@. Tasks include:
  \begin{itemize}
  \item setting the system date and time,
  \item setting the BIOS clock to the correct time in UTC,
  \item configuring the correct timezone for the system and
  \item configuring the system to correct clock drift to match NTP
    clock.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Key files, terms, and utilities include:}
  \mode<presentation>{\large}%
\begin{description}
 \item[\texttt{/usr/share/zoneinfo}] --- a directory containing time
   zone information for many different regions
 \item[\texttt{/etc/timezone}] --- On Debian systems, holds the timezone
 \item[\texttt{/etc/localtime}] --- a symbolic link to the correct
   file in /path{/usr/share/zoneinfo/}
 \item[\texttt{/etc/ntp.conf}] --- configuration file for NTP
 \item[\texttt{/etc/ntp.drift}] --- where NTP stores correction for
   local clock being fast/slow
 \item[\texttt{date}] --- command for showing/setting system time
 \item[\texttt{hwclock}] --- command for setting hardware clock, or
   setting system time from hardware clock
 \item[\texttt{ntpd}] --- NTP server
 \item[\texttt{ntpdate}] --- used to set system time from a remote NTP server
\end{description}
\end{frame}

\section{Resources}
\label{sec:resources}

\begin{frame}[fragile]
  \frametitle{Maintain system time [4]}
  \framesubtitle{Resources of interest}
  \begin{description}
  \item[web] \texttt{http://www.ntp.org}
  \item[Debian ntp-doc] \texttt{/usr/share/doc/ntp-doc/index.html} on sarg.
  \item[LPI Linux Certification in a Nutshell:]
    \texttt{by Jeffrey Dean}\\
    \textsf{O'Reilly}
  \item[LPIC 1 Certification Bible:]
    \textit{Angie Nash and Jason Nash}\\
    \textsf{Hungry Minds}
  \end{description}
\end{frame}

\section{\texttt{date}}
\label{sec:date}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{\texttt{date}}%
  \framesubtitle{Display or Set System Date \& Time}%
  The date command without any options will print the current date and
  time. The date will be relative to any timezone set for the machine.
  \par%
\begin{semiverbatim}
\cmd{date}
Tue May 21 09:57:51 EST 2002
\end{semiverbatim}
\end{frame}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{\texttt{date}}%
  \framesubtitle{Options to the Date command}%
  \begin{description}
  \item[\opt{-I}] Output an ISO-8601 compliant date  (YYYY-MM-DD) 
\begin{semiverbatim}
\cmd{date -I}
2002-05-21
\end{semiverbatim}
    \par%
    % \overlay{1}
  \item[\opt{-R}] Output an RFC-822 compliant date  (Local time + GMT 0ffset)
\begin{semiverbatim}
\cmd{date -R} 
Tue, 21 May 2002 10:14:09 +1000
\end{semiverbatim}
    % \overlay{2}
  \item[\opt{-r $<$file\textgreater}] Display the last modification
    time of file
\begin{semiverbatim}
\cmd{date -r ~/ivr/va/src/va.c}
Mon May 20 12:55:48 EST 2002 
\end{semiverbatim}
  \end{description}
\end{frame}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{\texttt{date}}%
  \framesubtitle{Options to the Date command}%
  \begin{description}
  \item[\texttt{-d \textless STRING\textgreater}] Display date described
    by string instead of now
\begin{alltt}
\cmd{date -d "last Monday 4 years ago"}
Mon May 18 00:00:00 EST 1998
\end{alltt}
    \par%
    % \overlay{1}
  \item[\opt{-u}] Display UTC time \& date instead of localtime
\begin{alltt}
\cmd{date}
Tue May 21 10:55:34 EST 2002
\cmd{date -u}
Tue May 21 00:55:34 UTC 2002
\end{alltt}
  \end{description}
\end{frame}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{\texttt{date}}%
  \framesubtitle{Options to the Date command}%
  \begin{description}
  \item[\opt{-s \textless date\textgreater}] Set the system time (must
    be superuser)
\begin{semiverbatim}
\rootcmd{date -s "Tue May 21 10:03:06 EST 2002"}
Tue May 21 10:03:06 EST 2002
\end{semiverbatim}
    %\overlay{1}
  \item[\opt{+FORMAT}] Display date in user defined format 
\begin{semiverbatim}
\cmd{date +"Today is %A, %d %B, %Y"}
Today is Tuesday, 21 May, 2002
\end{semiverbatim}
  \end{description}
\end{frame}

\section{Hardware Clock and System Clock}
\label{sec:hw-clock-and-system-clock}

\begin{frame}
  % Andrew Eager, Nick
  \frametitle{Hardware (``RTC'') vs. System Clock}
  \begin{itemize}
  \item The \textit{Hardware, or Real Time Clock (RTC)}%
    \begin{itemize}
    \item hardware clock is located on the motherboard
    \item Sometimes (for \green{hysterical} reasons) called the Real
      Time Clock (RTC)
    \item keeps track of the time when the system is not powered up.
    \end{itemize}
    \pause
  \item The \textit{system clock}
    \begin{itemize}
    \item maintained in the Linux kernel and
    \item is used while the system is running.
    \end{itemize}
  \end{itemize}
\end{frame}

\section{\texttt{hwclock}}
\label{sec:hwclock}

\begin{frame}[<+->]
%Andrew Eager
\frametitle{\texttt{hwclock}}
\framesubtitle{RTC vs. System clock}
Hwclock is used to do the following:
\begin{itemize}
  \item Set the system clock from the Hardware clock
  \item Set the hardware clock from the system clock
  \item Show the time/date held by the RTC
  \item Adjust the RTC to account for clock drift
\end{itemize}

\end{frame}

\begin{frame}[<+->]
  % Andrew Eager
  \frametitle{\texttt{hwclock}}%
  \framesubtitle{Set System clock to Hardware clock}%
  \begin{itemize}
  \item To set the system time from the RTC, use the following option to hwclock:
\begin{semiverbatim}
   hwclock -s  (or hwclock --hctosys)
\end{semiverbatim}
  \item To set the RTC from the system time, use this option:
\begin{semiverbatim}
   hwclock -w  (or hwclock --systohc)
\end{semiverbatim}
  \item To display the contents of the RTC, use this option:
\begin{semiverbatim} 
   hwclock -r  (or hwclock --show)
\end{semiverbatim}
  \item To adjust the RTC for clock drift, use this option:
\begin{semiverbatim}
   hwclock -a  (or hwclock --adjust)
\end{semiverbatim}
  \end{itemize}
  Note that the file \texttt{/etc/adjtime} is used to hold information
  about the extent to which (and direction) your RTC drifts
\end{frame}

\section{NTP --- Network Time Protocol}
\label{sec:ntp}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{NTP --- Network Time Protocol}%
  % \framesubtitle{\texttt{ntp}} 
  NTP is a time protocol used to synchronise a systems clock to master
  time source.  For example, the CSIRO maintains a nationwide time
  source with atomic clock accuracy.  As a user I can synchronise my
  system to that time source by sending a request to the CSIRO's ntp
  server.
  \par%
  \pause
  Features and properties of NTP include:
  \begin{itemize}
    \pause
    % \overlay{2}
  \item NTP takes into account the time taken to send/receive NTP packets
    \pause
    % \overlay{3}
  \item Uses the UDP protocol
    \pause
    % \overlay{4}
  \item Uses Port 123 plus one other unpriveledged port (1024:65535) 
    \pause
    % \overlay{5}
  \item Can operate in both client \& server modes
    \pause
    % \overlay{6}
  \item There are 3 versions of the protocol (ntp1, ntp2 \& ntp3)
    \pause
    % \overlay{7}
  \item Available for Unix \& Windows machines.
  \end{itemize}
\end{frame}

\subsection{NTP Tools}
\label{sec:ntp-tools}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{NTP --- Network Time Protocol}
  \framesubtitle{The suite of tools}

  NTP normally comes in a package and contains the following binaries:
  \begin{itemize}
    \pause
    % \overlay{0}
  \item \texttt{ntpd}        --- Network Time Protocol (NTP) daemon 
    \pause
    % \overlay{1}
  \item \texttt{ntpq}        --- standard NTP query program 
    \pause
    % \overlay{2}
  \item \texttt{ntpdc}       --- special NTP query program 
    \pause
    % \overlay{3}
  \item \texttt{ntpdate}     --- set the date and time via NTP 
    \pause
    % \overlay{4}
  \item \texttt{ntptrace} --- trace a chain of NTP servers to the
    primary source
    % \overlay{5}
  \item \texttt{tickadj}     --- set time-related kernel variables 
    \pause
    % \overlay{6}
  \item \texttt{ntptime}     --- read kernel time variables 
    \pause
    % \overlay{7}
  \item \texttt{ntp-genkeys} --- generate public and private keys 
  \end{itemize}
\end{frame}

\subsection{NTP --- Overview of setup}
\label{sec:ntp-overview-of-setup}

\begin{frame}
  % Andrew Eager, a little from Nick
  \frametitle{NTP --- Network Time Protocol}
  \framesubtitle{Quick install guide}

  A quick guide to installing \& setting up NTP:
  
  \begin{itemize}
    % \overlay{1}
  \item Install NTP package (\texttt{yum install ntp})
    \\or\\
    \texttt{apt-get install ntp}
    % \overlay{2}
  \item Modify \texttt{/etc/ntp.conf} to reflect time servers
    % \overlay{3}
  \item Start the service:  \texttt{service ntpd start}
    % \overlay{4}
  \item Ensure service starts at boot with \texttt{chkconfig~ntp~on}
  \item Confirm operation using \texttt{ntpq -p}
  \end{itemize}
  
  % \begin{overlay}{5}
  That's all there is to it!  The hardest part is deciding which
  public time servers to use.
  % \end{overlay}
\end{frame}

\subsection{\texttt{ntpdate}}
\label{sec:ntpdate}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{NTP --- Network Time Protocol}%
  \framesubtitle{\texttt{ntpdate} --- Set system time \& date}%
  \begin{itemize}
  \item \texttt{ntpdate} is a command line utility that will set the
    local machines time \& date from the indicated remote time
    server(s).
    % \overlay{1}
  \item More than one server can be specified in order for ntp to get
    a better idea of the transit time and overall server accuracy.
    % \overlay{2}
  \item Running as a cron job is a simple way to maintain system time
  \end{itemize}
  % \overlay{3}
  Usage: \texttt{ntpdate [options] server ...}
  {\mode<presentation>{\footnotesize}%
\begin{semiverbatim}
\# ntpdate ntp.nml.csiro.au
21 May 14:01:13 ntpdate[4002]: adjust time server 10.27.1.10
offset -0.000804 sec
\end{semiverbatim}
}
    %\begin{overlay}{4}
    This will set the local machines system time using server 
    \texttt{ntp.nml.csiro.au}
%\end{overlay}
\end{frame}

\subsection{\texttt{ntpd}}
\label{sec:ntpd}

\begin{frame}[fragile]
  % Andrew Eager and Geoffrey
  \frametitle{\texttt{ntpd} --- The NTP daemon}
  \begin{itemize}
  \item \texttt{ntpd} is a better way to maintain the system time on a 
    permanent basis.
    % \overlay{1}
  \item \texttt{ntpd} acts as both a client \& server (Linux only).
    % \overlay{2}
  \item In server mode, other machines on the local network can use the
    server to set their own system clocks
    % \overlay{3}
  \item For Windows machines, automachron is available.
    % \overlay{4}
  \item \texttt{ntpd} also keeps track of drift in the hardware clock.
  \end{itemize}
  \par%
  % \begin{overlay}{4}
  The NTP daemon is normally started up by the system initialisation scripts:
  \begin{description}
  \item[Debian or Red Hat]: {\footnotesize\cmd{/etc/init.d/ntp start}} 
  \item[Red Hat]: {\footnotesize\cmd{service ntp start}}   
  \end{description}
  % \end{overlay}  
\end{frame}

\subsection{NTP configuration files}
\label{sec:configuration-files}

\begin{frame}[<+->]
  % Andrew Eager and Geoffrey
  \frametitle{\texttt{ntpd} usage \& configuration} %
  Usage:
  \texttt{ntpd [options] \&} 
  \par%
  (normally done in the \texttt{/etc/init.d} scripts)  
  \par%
  NTPD is configured using these files:  
  \begin{itemize}
    % \overlay{1}
  \item \texttt{/etc/ntp.conf}  --- Configuration file
    % \overlay{2}
  \item \texttt{/etc/ntp.drift} --- RTC drift file
    % \overlay{3}
  \item \texttt{/etc/ntp.keys}  --- Key file (for authentication mode)
  \end{itemize}
  \par%
  % \begin{overlay}{4}
  The only file of concern to the user is \texttt{ntp.conf}. The other
  files are all written to and read by the ntp applications.
  % \end{overlay}
\end{frame}

\subsection{Sample \texttt{ntp.conf}}
\label{sec:sample-ntp.conf}

\begin{frame}[fragile]
  % Andrew Eager
  \frametitle{NTP --- Network Time Protocol}%
  \framesubtitle{Sample \texttt{ntp.conf} file}%
  \mode<presentation>{\scriptsize}%
\begin{semiverbatim}
# Disable authentication mode
disable auth
restrict default ignore        # ignore all requests by default
server  ntp.cs.mu.OZ.AU        # 128.250.36.2
server  apphys16.mst.csiro.au  # 138.194.21.154
server  ntp.nml.csiro.au       # 130.155.98.1
server  127.0.0.1              # localhost
# Lift restrictions on time servers
restrict 128.250.36.2 nomodify  # time service only, no rt mods
restrict 138.194.21.154 nomodify
restrict 130.155.98.1 nomodify
# All local addresses are unrestricted
restrict 127.0.0.1
restrict 10.27.1.0 mask 255.255.255.0
# Set the default drift file
driftfile /etc/ntp/drift
\end{semiverbatim}
\end{frame}

\subsection{NTP servers in Australia}
\label{sec:servers-in-australia}

\begin{frame}[fragile]
  % Andrew Eager and Geoffrey
  \frametitle{Public Time Servers}
  A (partial) list of public time servers is shown below.  When using
  these servers, it is considered polite to advise the administrator
  of the service that you intend to use it.
  \begin{itemize}
  \item Primary NTP Time Servers
    \begin{itemize}
    \item ntp.cs.mu.OZ.AU        (128.250.36.2)
    \item apphys16.mst.csiro.au  (138.194.21.154)
    \item ntp.nml.csiro.au       (130.155.98.1)
    \end{itemize}
  \item Secondary NTP Time Servers
    \begin{itemize}
    \item ntp.saard.net          (203.21.37.18)
    \item ntp.iprolink.co.nz     (36.50.59.6) 
    \end{itemize}
  \end{itemize}
\end{frame}

\subsection{\texttt{ntpq} --- Testing NTP}
\label{sec:ntpq}

\begin{frame}[fragile]
%Andrew Eager
\frametitle{NTP --- Network Time Protocol}
\framesubtitle{Testing NTP}

Once you have the NTP daemon up \& running, the easiest way of testing
it is to use the \texttt{ntpq} utility.

\footnotesize
\begin{semiverbatim} 
$ \textbf{ntpq}
ntpq> \textbf{pe}
     remote       refid    ...       delay   offset  jitter
===========================================================
 localhost.local 0.0.0.0   ...       0.000    0.000 4000.00
xmurgon.cs.mu.OZ .GPS.     ...     526.202  -206.43 208.270
+apphys16.mst.cs .ATOM.    ...     169.956   -5.576  87.828
*tictoc.tip.CSIR .ATOM.    ...     149.988  -24.328   6.761
ntpq> q
$
\end{semiverbatim}
Or more simply:

\begin{semiverbatim} 
$ \textbf{ntpq -p}
     remote       refid    ...       delay   offset  jitter
===========================================================
 localhost.local 0.0.0.0   ...       0.000    0.000 4000.00
xmurgon.cs.mu.OZ .GPS.     ...     526.202  -206.43 208.270
+apphys16.mst.cs .ATOM.    ...     169.956   -5.576  87.828
*tictoc.tip.CSIR .ATOM.    ...     149.988  -24.328   6.761
$
\end{semiverbatim}
\end{frame}

\mode<presentation>
{%
\begin{frame}
  \frametitle{Topics Covered}
  %\footnotesize
  %\begin{multicols}{2}
    \tableofcontents[pausesections,pausesubsections]
  %\end{multicols}
  % You might wish to add the option [pausesections]
\end{frame}
}

\section{License of this Document}
\label{sec:license}

\begin{frame}
  \frametitle{License Of This Document}%
  \raggedright%
  Copyright \copyright\ 2005 2002 Andrew Eager <andrew.eager@aes-pl.com.au>,
  Geoffrey Robertson <ge@offry.com> and Nick Urbanik
  <nicku@nicku.org>.%
  \par
  Permission is granted to make and distribute verbatim copies or
  modified versions of this document provided that this copyright
  notice and this permission notice are preserved on all copies under
  the terms of the GNU General Public License as published by the Free
  Software Foundation---either version 2 of the License or (at your
  option) any later version.
\end{frame}
\end{document}
