OBJECTIVE:
The objective of this lab is to learn how to configure NTP services on the Pi by changing the NTP configuration file and change the Pi’s time sources.
REQUIRED MATERIALS:
- Raspberry Pi Micro-Controller
- 8GB SDCard with the Operating System NOOBS (Raspian – Debian Linux derivative) pre-installed.
- Power Supply, AC-DC Converter, External Plug in, Micro USB connector, 5W, 5V, 1A output.
- USB Keyboard.
- USB Mouse.
- HDMI Monitor.
- HDMI Cable.
- HDMI to DVI Adpater (if your monitor only has a DVI and not a HDMI connector).
- Two straight through Ethernet cables
- Home router\switch connected to a cable modem or DSL modem
- A personal computer
PRE-REQUISITES:
- An operating system must be installed onto the Raspberry Pi (see Pi Lab – Initial Setup)
- The Pi must have Internet connectivity.
- Ethernet networking.
- Connector types such as HDMI, DVI, USB, RJ-45 (Ethernet), etc…
- The Linux Operating System
- The Network Time Protocol (NTP) Protocol
REFERENCES:
Raspberry Pi Help
- http://www.raspberrypi.org/phpBB3
- ntpd
- ntp.conf
- ntpq
- ntpdc
- ntpdate
- ntp_mon
- ntp_acc
- ntp_clock
- ntp_misc
- http://www.pool.ntp.org/en/use.html
- http://www.ntp.org/
- http://tf.nist.gov/tf-cgi/servers.cgi
- http://www.eecis.udel.edu/~mills/ntp.html
- http://www.eecis.udel.edu/~mills/ntp/html/
- http://support.ntp.org/bin/view/Main/WebHome
PRELIMINARY READING:
To change the operating parameters of the ntp daemon, you need to make changes to the configuration file “/etc/ntp.conf”.
On a fresh install of Raspbian on a Raspberry Pi, NTP is configured to get its time from a pool of low-stratum NTP servers on the Internet. Because these servers are located all over the world, the accuracy of the time updates may not be as accurate as your needs might warrant. According to the NTP Pool Project (http://www.pool.ntp.org), you will get better results getting your time from servers located closer to home, so to speak. So they have organized server pools by continent, and even by country in some instances. Each pool named in your “ntp.conf” file points to a random set of servers that changes every hour. The closer the time servers are to you, the better. You can measure a specific server’s distance from you by using the traceroute or ping utilities.
If you happen to know of a time server run by an organization that is close to you and that is available to the public (such as your ISP, a local business, or a university perhaps), you should use that instead of the pool. You can even use a combination of local servers and pool servers. Because I live in Oklahoma, smack dab in the middle of the United States, I am going to configure my Pi to use the US Zone that is a subset of the North America Zone and some servers that are closer to where I live and not half way around the world.
PROCEDURE:
Experiment 1
Change the server pool.
1. Make a backup of the ntp.conf
2. In the GUI, right click the icon of the computer screen entitled “LXTerminal” and then left click “Open”. This opens a CLI.
3. Make a backup of the “ntp.conf” file. In the terminal window, enter the command “sudo cp /etc/ntp.conf /etc/ntp.conf.bak”.
4. Open the ntp configuration file for editing by entering the command: “sudo leafpad /etc/ntp.conf”.
The reason I opened the Leafpad text editor from the CLI using “sudo” is because by default the Pi logs you into the GUI as the user “pi” and not as “root”. If you want to save any changes made to the configuration file, you must edit it as the “root” user. If you open Leafpad by clicking on the icon and then open the configuration file, you will not be able to save any changes made to it because you doing so as the user “pi”.
5. In your “ntp.conf” file, examine the section that looks like this:
# You do need to talk to an NTP server or two (or three).6. In front of each “server” statement, type a hash symbol (#) in a manner similar to the statements above. This turns the line of text into a comment and prevents it from being executed.
#server ntp.your-provider.example
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
I copied and pasted the following text from “http://www.pool.ntp.org/zone/us” and then added the “iburst” option:
server 0.us.pool.ntp.org iburstBy adding the “iburst” option, when a time server is unreachable, the Pi will send 8 request packets to the server spaced 2 seconds apart (a burst of packets). According to the “ntp.conf” Man Page, this is a recommended option.
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst
server 3.us.pool.ntp.org iburst
7. In Leafpad, click “File”, then “Save”.
8. Restart the ntp daemon by executing the command: “sudo service ntp restart”.
9. After waiting a few minutes for the Pi to sync with the Internet servers, check to see if the Pi is synchronizing with the servers. This is done by executing the command: “ntpq –p”. The resulting display should look something like this:
pi@raspberrypi ~ $ ntpq -pUnder the “remote” column you will see listed the names or IP addresses of the servers being synched to. The “refid” is the reference ID and can be an IP address, or a name that you specifically assign to it. The “st” refers to the server’s stratum. The “when” refers to the time elapsed in seconds since the server was last heard from. The “poll” column is the polling interval in seconds. The “jitter” column refers to changes in the rate packets arrive from the same flow of data. The values under “offset” and “delay” should not be zero, and the “jitter” should be less than 100. If they all are zero, then there is a problem with NTP synching with anything.
remote refid st t when poll reach delay offset jitter
==============================================================================
*paladin.latt.ne 204.123.2.72 2 u 2 64 1 55.435 -2.688 9.286
int42.org 128.4.1.1 2 u 2 64 1 14.762 -1.008 1.069
mirror 164.244.221.197 2 u - 64 1 35.037 2.539 9.179
tock.usshc.com .GPS. 1 u 1 64 1 48.938 -0.541 1.574
pi@raspberrypi ~ $
The asterisk (*) shown in the left margins indicates the currently selected peer, in other words, the server that the Pi is synching up to at that point in time. If there is no asterisk, then the Pi is not synching with anything.
Experiment 2
Getting time from specific servers and not through a pool.
1. Edit the “ntp.conf” file by executing the command “sudo leafpad /etc/ntp.conf”.
2. Comment out the lines specifying the server pools by inserting the # symbol at the start of line.
Type the following lines into the configuration file as follows:
# This is a stratum 1 time server from NIST3. In Leafpad, click “File”, then “Save”.
# located in Carrollton, Texas.
server 96.226.242.9 iburst
# This is a time server from the U.S. Naval
# Observatory located at Oklahoma State
# University in Stillwater, Oklahoma.
server ntp.okstate.edu iburst
4. In the CLI, restart ntp by entering the commands “sudo leafpad /etc/ntp.conf”.
5. Next, check the status of NTP by executing the command “ntpq –p”. Here is the resulting output:
pi@raspberrypi ~ $ sudo leafpad /etc/ntp.conf
pi@raspberrypi ~ $ sudo service ntp restart
[ ok ] Stopping NTP server: ntpd.
[ ok ] Starting NTP server: ntpd.
pi@raspberrypi ~ $ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*static-96-226-2 .ACTS. 1 u - 64 1 86.985 -0.661 1.913
+ntp.okstate.edu .GPS. 1 u 1 64 1 44.818 -1.801 4.675
pi@raspberrypi ~ $
No comments:
Post a Comment