Time Syncronization
(16 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | The '''Vera '''units use '''rdate '''to synchronize the time. Rdate is a client program which uses the Time protocol. Rdate servers | + | [[Category:How_To]] |
+ | The '''Vera '''units use by default '''rdate '''to synchronize the time.<br> Rdate is a client program which uses the Time protocol and does one time query and synchronization. Rdate servers are running the Time service protocol on '''port 37''' which conforms to RFC 868. Clients can use either TCP or UDP.<br> The '''Time Protocol''' (RFC 858) is not related or compatible with '''Network Time Protocol''' (RFC 958) used by ntpclient/ntpd/openntp.<br> | ||
− | + | <br> | |
− | + | == <span id="Prerequisites" class="mw-headline">Prerequisites</span> == | |
− | + | *Vera hardware | |
+ | *Root acces to your OpenWRT | ||
− | < | + | <br> |
− | + | == <span id="Instructions" class="mw-headline">Instructions</span> == | |
− | + | Gain ssh access to your Vera (root) and use the password that is provided on the bottom of your vera2. More info on how to can be found here:[http://wiki.micasaverde.com/index.php/Logon_Vera_SSH [1]] | |
− | <br> | + | Time Servers are listening on port 37 and Network Time Servers on 123.<br> '''Note:''' In order for you Vera unit to successfully syncronize its time you have to allow connections from it to the time servers on '''port 37 for rdate''' and '''port 123 for ntpclient''' if you install it.<br> |
− | + | <u>Check if Vera can sync with a Time Server</u> :<br> | |
+ | <pre>rdate -p server</pre> | ||
+ | ''The -p switch prints the date and time from the server''.<br> | ||
− | + | <u>Set the time from a Time Server:</u> | |
+ | <pre>rdate -l -s server</pre> | ||
+ | ''The -l switch allows for logging results to Syslog, -s sets the system time.'' | ||
− | <br> | + | There is no worldwide list of Time servers available. Many, but not all, Network Time Protocol (NTP) servers also serve Time on port 37. There is a list of NTP servers here [http://support.ntp.org/bin/view/Servers/WebHome [2]]<br> |
− | + | The National Institute of Standards and Technology (United States Gov't) offers about a dozen Time servers to the public. Their server list is available here [http://tf.nist.gov/tf-cgi/servers.cgi# [3]]<br> | |
− | + | ||
− | <br> | + | |
+ | Here is a list of working servers (at this moment): | ||
+ | <pre>nist1.aol-va.symmetricom.com | ||
+ | nist1.columbiacountyga.gov | ||
+ | nist1-atl.ustiming.org | ||
+ | nist1-chi.ustiming.org | ||
+ | nist.expertsmi.com | ||
+ | nisttime.carsoncity.k12.mi.us | ||
+ | nist1-lnk.binary.net | ||
+ | wwv.nist.gov | ||
+ | time.nist.gov | ||
+ | utcnist.colorado.edu | ||
+ | utcnist2.colorado.edu | ||
+ | ntp-nist.ldsbc.edu | ||
+ | nist1-lv.ustiming.org | ||
+ | nist-time-server.eoni.com | ||
+ | nist1.aol-ca.symmetricom.com | ||
+ | nist1.symmetricom.com | ||
+ | nist1-sj.ustiming.org | ||
+ | nist1-la.ustiming.org | ||
+ | </pre> | ||
To test on your '''Vera '''unit which servers are working, log in by ssh and then create a new file called timeservers.txt in /tmp with this command :<br> | To test on your '''Vera '''unit which servers are working, log in by ssh and then create a new file called timeservers.txt in /tmp with this command :<br> | ||
− | + | <pre>touch /tmp/timeservers.txt | |
− | + | </pre> | |
− | + | ||
Then edit it and copy the servers from the list using vim, and then run this command at least 5 times :<br> | Then edit it and copy the servers from the list using vim, and then run this command at least 5 times :<br> | ||
− | + | <pre>while read server; do echo -n "Server $server :"; rdate -p $server && echo "OK" || echo "FAILED"; done < /tmp/timeservers.txt | |
− | + | </pre> | |
− | + | After that compare the results and pick the servers that only display OK, these will be the most reliable, and then add them to the list here /etc/config/timeserver .<br> '''Note: Please remember to keep the same format of the file when you edit it.''' | |
− | After that compare the results and pick the servers that only display OK, these will be the most reliable, and then add them to the list here /etc/config/timeserver .<br> | + | |
To sync the time use the following command :<br> | To sync the time use the following command :<br> | ||
− | + | <pre>ash -x /usr/bin/sync_time.sh | |
− | + | </pre> | |
− | + | ||
<br> | <br> | ||
− | + | == Creating a local time server<br> == | |
− | + | If you want to create a local time servers you can use '''xinetd '''and you can read more about it here [http://ecloud.org/index.php?title=Rdate_server [4]]<br> | |
− | If you want to create a local time servers you can use '''xinetd '''and you can read more about it here http://ecloud.org/index.php?title=Rdate_server <br> | + | |
Once all the settings have been made you need to restart '''xinetd '''by using this command : | Once all the settings have been made you need to restart '''xinetd '''by using this command : | ||
+ | <pre>/etc/init.d/xinetd reload | ||
+ | </pre> | ||
+ | == '''<br>''' Installing the NTP client == | ||
− | + | Optionally you can install the ntpclient also. Run the following commands to install the NTP client by ssh:<br> | |
+ | <pre>opkg update</pre> <pre>opkg install ntpclient</pre> | ||
+ | The ntp servers are define in this file : /etc/config/ntpclient | ||
− | <br> | + | To edit the file you can use '''vim '''editor: |
+ | <pre>vim /etc/config/ntpclient</pre> | ||
+ | To view the current entries in it type:<br> | ||
+ | <pre>cat /etc/config/ntpclient</pre> | ||
+ | '''''Note: Please remember to keep the same format of the file when you edit it.'''''<br> | ||
− | <br> | + | Check if Vera can connect to the default ntp servers : <br> |
+ | <pre>BASE_NTP_SRV="openwrt.pool.ntp.org"; for i in 0 1 2 3 5; do NTP_SRV="$i.$BASE_NTP_SRV"; echo -n "$NTP_SRV : "; ntpclient -c 1 -p 123 -h $NTP_SRV || echo "FAILED"; done</pre> | ||
+ | Force ntpclient to re-read the ntp servers and to do a time sync : | ||
+ | <pre>/etc/init.d/ntpclient restart</pre> | ||
+ | To check if the ntp client is running use this command : <br> | ||
+ | <pre>ps fax | grep ntp</pre> | ||
+ | If you see this message then you've successfully installed the NTP client:<br> | ||
+ | <pre>4188 root 1068 S /usr/sbin/ntpclient -i 600 -s -l -D -p 123 -h 0.openwrt.pool.ntp.org | ||
+ | 14454 root 1672 S grep ntp</pre> |
Latest revision as of 02:58, 15 June 2013
The Vera units use by default rdate to synchronize the time.
Rdate is a client program which uses the Time protocol and does one time query and synchronization. Rdate servers are running the Time service protocol on port 37 which conforms to RFC 868. Clients can use either TCP or UDP.
The Time Protocol (RFC 858) is not related or compatible with Network Time Protocol (RFC 958) used by ntpclient/ntpd/openntp.
Contents |
[edit] Prerequisites
- Vera hardware
- Root acces to your OpenWRT
[edit] Instructions
Gain ssh access to your Vera (root) and use the password that is provided on the bottom of your vera2. More info on how to can be found here:[1]
Time Servers are listening on port 37 and Network Time Servers on 123.
Note: In order for you Vera unit to successfully syncronize its time you have to allow connections from it to the time servers on port 37 for rdate and port 123 for ntpclient if you install it.
Check if Vera can sync with a Time Server :
rdate -p server
The -p switch prints the date and time from the server.
Set the time from a Time Server:
rdate -l -s server
The -l switch allows for logging results to Syslog, -s sets the system time.
There is no worldwide list of Time servers available. Many, but not all, Network Time Protocol (NTP) servers also serve Time on port 37. There is a list of NTP servers here [2]
The National Institute of Standards and Technology (United States Gov't) offers about a dozen Time servers to the public. Their server list is available here [3]
Here is a list of working servers (at this moment):
nist1.aol-va.symmetricom.com nist1.columbiacountyga.gov nist1-atl.ustiming.org nist1-chi.ustiming.org nist.expertsmi.com nisttime.carsoncity.k12.mi.us nist1-lnk.binary.net wwv.nist.gov time.nist.gov utcnist.colorado.edu utcnist2.colorado.edu ntp-nist.ldsbc.edu nist1-lv.ustiming.org nist-time-server.eoni.com nist1.aol-ca.symmetricom.com nist1.symmetricom.com nist1-sj.ustiming.org nist1-la.ustiming.org
To test on your Vera unit which servers are working, log in by ssh and then create a new file called timeservers.txt in /tmp with this command :
touch /tmp/timeservers.txt
Then edit it and copy the servers from the list using vim, and then run this command at least 5 times :
while read server; do echo -n "Server $server :"; rdate -p $server && echo "OK" || echo "FAILED"; done < /tmp/timeservers.txt
After that compare the results and pick the servers that only display OK, these will be the most reliable, and then add them to the list here /etc/config/timeserver .
Note: Please remember to keep the same format of the file when you edit it.
To sync the time use the following command :
ash -x /usr/bin/sync_time.sh
[edit] Creating a local time server
If you want to create a local time servers you can use xinetd and you can read more about it here [4]
Once all the settings have been made you need to restart xinetd by using this command :
/etc/init.d/xinetd reload
[edit]
Installing the NTP client
Optionally you can install the ntpclient also. Run the following commands to install the NTP client by ssh:
opkg update
opkg install ntpclient
The ntp servers are define in this file : /etc/config/ntpclient
To edit the file you can use vim editor:
vim /etc/config/ntpclient
To view the current entries in it type:
cat /etc/config/ntpclient
Note: Please remember to keep the same format of the file when you edit it.
Check if Vera can connect to the default ntp servers :
BASE_NTP_SRV="openwrt.pool.ntp.org"; for i in 0 1 2 3 5; do NTP_SRV="$i.$BASE_NTP_SRV"; echo -n "$NTP_SRV : "; ntpclient -c 1 -p 123 -h $NTP_SRV || echo "FAILED"; done
Force ntpclient to re-read the ntp servers and to do a time sync :
/etc/init.d/ntpclient restart
To check if the ntp client is running use this command :
ps fax | grep ntp
If you see this message then you've successfully installed the NTP client:
4188 root 1068 S /usr/sbin/ntpclient -i 600 -s -l -D -p 123 -h 0.openwrt.pool.ntp.org 14454 root 1672 S grep ntp