Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NTP and Cron Problem

Status
Not open for further replies.

Slick629

Technical User
Sep 5, 2002
27
US
Hey all,
I have an NEC Express 120 LF server and without NTP turned on it loses time. So I turned on NTP to sync the time and keep it accurate. Well for some reason it still loses like 15 minutes a day. So I found an RH article (this is Red Hat ES3 Update 4)that says to turn cron on in /etc/cron.d/ntp with the following:
*/3 * * * * root /usr/sbin/ntpd -q > /dev/null &
This is all fine however in the /var/log/messages I get this error:
Sep 20 08:05:00 localhost ntpd[13813]: ntpd 4.1.2@1.892 Tue Feb 24 06:32:25 EST
2004 (1)
Sep 20 08:05:00 localhost ntpd[13813]: precision = 10 usec
Sep 20 08:05:00 localhost ntpd[13813]: bind() fd 4, family 2, port 123, addr 0.0
.0.0, in_classd=0 flags=1 fails: Address already in use
Sep 20 08:05:00 localhost ntpd[13813]: bind() fd 4, family 2, port 123, addr 127
.0.0.1, in_classd=0 flags=0 fails: Address already in use
Sep 20 08:05:00 localhost ntpd[13813]: bind() fd 4, family 2, port 123, addr 10.
215.204.57, in_classd=0 flags=1 fails: Address already in use
Sep 20 08:05:00 localhost ntpd[13813]: kernel time discipline status 0040
Sep 20 08:05:00 localhost ntpd[13813]: frequency initialized 0.000 from /var/lib
/ntp/drift

I don't know if this is my problem but I am still losing 15 minutes a day.

When it is setup this way then I cannot do a ntpdc -c peers I get a localhost.localdomain: timed out, nothing received
***Request timed out. However If I go into my ntp.conf file and uncomment out restrict 127.0.0.1 Then I can do the ntpdc -c peers command.

I just need to get cron to work so that this system doesn't lose time. at this point I am truly perplexed and out of ideas. Any help would greatly be appreciated. Here is my ntp.conf file.
# Prohibit general access to this service.
restrict default ignore

restrict XXX.XXX.224.4 mask 255.255.255.255 nomodify notrap noquery

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.

#restrict 127.0.0.1
# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service. Do not permit those systems to modify the
# configuration of this service. Also, do not use those
# systems as peers for synchronization.
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap
# --- OUR TIMESERVERS -----

# or remove the default restrict line
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
# restrict mytrustedtimeserverip mask 255.255.255.255 nomodify notrap noquery
# server mytrustedtimeserverip
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst
# --- NTP MULTICASTCLIENT ---
#multicastclient # listen on default 224.0.1.1
# restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap

# --- GENERAL CONFIGURATION ---
#
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. The
# default stratum is usually 3, but in this case we elect to use stratum
# 0. Since the server line does not have the prefer keyword, this driver
# is never used for synchronization, unless no other other
# synchronization source is available. In case the local host is
# controlled by some external source, such as an external oscillator or
# another protocol, the prefer keyword would cause the local host to
# disregard all other synchronization sources, unless the kernel
# modifications are in use and declare an unsynchronized condition.
#
#server XX.187.224.4
#fudge 127.127.1.0 stratum 10
#
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
#
# Authentication delay. If you use, or plan to use someday, the
# authentication facility you should make the programs in the auth_stuff
# directory and figure out what this number should be on your machine.
#
authenticate yes
#
# Keys file. If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
keys /etc/ntp/keys

The last thing is if I manually restart ntpd it will sync up.

Please Help!!!!
 
Stop the ntpd service first:

service ntpd stop
chkconfig ntpd off

The error is indicating that ntpd is already running.
 
Technically, if all you want to do is keep your local machine's time in sync, you don't need to run the ntpd daemon. ntpd is a service for other machines to query, you're simply configuring your ntpd to get the time somewhere else then to make it available to its clients.

INSTEAD, set a recurring cron job to load using 'ntpdate' which is designed to run on a spot basis - not as a daemon.

For instance
'ntpdate -s ntp.nasa.gov' is something you could put into cron as an hourly or daily task.

Typically it's polite to inquire with the NTP server you take the time from to ensure that they are cool with you hitting their server at a frequency greater than once every few hours.



D.E.R. Management - IT Project Management Consulting
 
Thanks guys I will give this a try and let you know in a couple of hours. I was under the impression that the ntp daemon was supposed to keep in sync with the server and not to just be the :source" of the clock.
 
Slick,
Yes, ntpd WILL stay in sync with its upstream source AND will offer itself as an ntpd to its downstream clients.

Your circumstance spoke to JUST needing your server to be a client.

Thus, 'ntpdate' is suitable.

D.E.R. Management - IT Project Management Consulting
 
Thats correct thedaver I just need it to sync as a client. No other machines will sync of the RH server. So I did this:

made a ntpdate.sh file
ntpdate to my ntp servers
crontab -e
0 */3 * * * ./ntpdate.sh > /var/log/messages 2>&1

I will monitor and see if it works.

Thanks for the help!
 
Uh, you'd better change
"./ntpdate.sh > /var/log/messages..."
to use ">>"
otherwise you're going to overwrite your entire /var/log/messages logfile!

D.E.R. Management - IT Project Management Consulting
 
Thanks thedaver your right I was overwriting the /var/log/messages.

I still seem to have a problem. I was trying to run the cron job every 3 hours but the clock drifts to much. I ended up having to run it every hour because the clock is drifting as much as 2 minutes in 2 hours. I know there is a larger problem/cause here.

Has anyone ever used adjtimex and could this help my problem? And if so how is it used?

Thanks in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top