NTP / time settings
Hi all. First post. I'm using wheezy. My pi lives in a rural location that is subject to frequent short power outages. When the the pi powers back up, it does so quicker than my router can re-acquire its internet connection. So when it tries to update its time from an NTP server it fails because it has no internet access. I believe that's what is causing some mysterious time inaccuracies on my pi. (It's not off by an integral number of hours so the time zone isn't the problem.)
Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)
Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?
Many thanks
Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)
Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?
Many thanks
-
- Posts: 3
- Joined: Sun Sep 02, 2012 8:33 am
Re: NTP / time settings
I have the same problem.
My Pi is powered from a USB socket on the back of my modem and boots up much faster, if the modem restarts for any reason, and, as a result, my system time is well out from what it should be.
I'll post back, if I find a solution.
My Pi is powered from a USB socket on the back of my modem and boots up much faster, if the modem restarts for any reason, and, as a result, my system time is well out from what it should be.
I'll post back, if I find a solution.
-
- Posts: 3
- Joined: Sun Sep 02, 2012 8:33 am
Re: NTP / time settings
I (think) it's mission accomplished.
Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/qu ... ystem-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.
I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used to create a file into which I put the line .
After the date was correct, but the time was one hour slow, so I then used which, after another dose of , got the time in line with my local UK time.
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.
That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.
If anyone with more experience than myself knows an easier way, of course....
Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/qu ... ystem-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.
I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used
Code: Select all
sudo nano /etc/rc.conf
Code: Select all
DAEMONS=(!hwclock ntpd)
After
Code: Select all
sudo reboot
Code: Select all
sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
Code: Select all
sudo reboot
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.
That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.
If anyone with more experience than myself knows an easier way, of course....
Re: NTP / time settings
Great, thanks for that, I will experiment. I was on the verge of running (as a cron job on reboot) a script to wait a while (to give the router time to come up) and then try NTP. Your solution looks like much less of a botch! Thanks
Re: NTP / time settings
Hi,
I'm also using Raspbian (Wheezy)
The way I have setup my NTP time server for the Raspi to keep correct time was to edit this file
/etc/ntp.conf
Remove the hash(#) from the line below *You need to talk to an NTP server or two (or three)*
type the URL of the time server in front of server. such as ntp.timeserver.com
I also setup a rc.conf file the same as you have but found some more information on how to make it run faster, add ntpdate so your file looks this:
DAEMONS=(!hwclock ntpd ntpdate)
Source: http://raspberrypi.stackexchange.com/qu ... ystem-time
Hope that's useful
I'm also using Raspbian (Wheezy)
The way I have setup my NTP time server for the Raspi to keep correct time was to edit this file
/etc/ntp.conf
Remove the hash(#) from the line below *You need to talk to an NTP server or two (or three)*
type the URL of the time server in front of server. such as ntp.timeserver.com
I also setup a rc.conf file the same as you have but found some more information on how to make it run faster, add ntpdate so your file looks this:
DAEMONS=(!hwclock ntpd ntpdate)
Source: http://raspberrypi.stackexchange.com/qu ... ystem-time
Hope that's useful
-
- Posts: 3
- Joined: Sun Sep 02, 2012 8:33 am
Re: NTP / time settings
Okay.
Watch this space. More to come, because....
Logged into my Pi today, to find the time two hours slow again!
Modem must have rebooted overnight, for some reason, (Note to self: Get a new modem. This one started randomly rebooting two weeks ago and you've no idea why) and the Pi hasn't got the right local time now.
Hey, ho. Back to work on it.
Watch this space. More to come, because....
Logged into my Pi today, to find the time two hours slow again!
Modem must have rebooted overnight, for some reason, (Note to self: Get a new modem. This one started randomly rebooting two weeks ago and you've no idea why) and the Pi hasn't got the right local time now.
Hey, ho. Back to work on it.
Re: NTP / time settings
I can not get the system time to update. Do I need to make rc.conf executable? I thought ntpd -gq would update the time, but it doesn't seem to be working either.
-
- Posts: 16363
- Joined: Fri Mar 09, 2012 7:36 pm
- Location: Vallejo, CA (US)
Re: NTP / time settings
If you have power issues...whether it's sags and surges or outages (brief or otherwise), or even if you think your power is reliable...
Get an Uninteruptable Power Supply (UPS). Put not only your Pi and PC on it, but you networking equipment (modem, router, switches, etc.) on it as well. If you can't get everything on one UPS, get however many you need. If you want to isolate your network gear, get small UPS (<500VA) for the network and a larger one for other equipment.
Doing this will save you much grief in the long run...and not just with the Pi. There will be less wear and tear on your electronics, you won't lose work because your machine dropped, you won't be rebuilding corrupted SD cards, you'll be able to ignore brief power interruptions, and you'll be able to do an orderly shutdown in longer interruptions.
Just to give a concrete example from a few years ago... I was running convention registration when the power went out in the hotel we were using for the con. I had my crew process the registrations they were already working on and then we did a controlled shutdown of 4 PCs, two impact printers, and a Linux server, plus the associated network bits that tied it all together ....all because it was all running on two 1.5KVA UPS'. The power was out for about 3 hours. When we got power back, everything came back up smoothly with no glitches and no file corruption.
You never know when or where you'll have a power outage.
Get an Uninteruptable Power Supply (UPS). Put not only your Pi and PC on it, but you networking equipment (modem, router, switches, etc.) on it as well. If you can't get everything on one UPS, get however many you need. If you want to isolate your network gear, get small UPS (<500VA) for the network and a larger one for other equipment.
Doing this will save you much grief in the long run...and not just with the Pi. There will be less wear and tear on your electronics, you won't lose work because your machine dropped, you won't be rebuilding corrupted SD cards, you'll be able to ignore brief power interruptions, and you'll be able to do an orderly shutdown in longer interruptions.
Just to give a concrete example from a few years ago... I was running convention registration when the power went out in the hotel we were using for the con. I had my crew process the registrations they were already working on and then we did a controlled shutdown of 4 PCs, two impact printers, and a Linux server, plus the associated network bits that tied it all together ....all because it was all running on two 1.5KVA UPS'. The power was out for about 3 hours. When we got power back, everything came back up smoothly with no glitches and no file corruption.
You never know when or where you'll have a power outage.
Re: NTP / time settings
I was looking for ages for a workaround about the non real clock Pi and it seems your post gave real time to my Pi.Thanx a lot.Left_Guard wrote:I (think) it's mission accomplished.
Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/qu ... ystem-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.
I'm using Raspbian (Wheezy), meaning NTP is already installed, so I usedto create a file into which I put the lineCode: Select all
sudo nano /etc/rc.conf
.Code: Select all
DAEMONS=(!hwclock ntpd)
Afterthe date was correct, but the time was one hour slow, so I then usedCode: Select all
sudo reboot
which, after another dose ofCode: Select all
sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
, got the time in line with my local UK time.Code: Select all
sudo reboot
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.
That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.
If anyone with more experience than myself knows an easier way, of course....
-
- Posts: 31
- Joined: Fri May 17, 2013 11:58 am
Re: NTP / time settings
Hi,
I'm wondering about the successful settings.
AFAIK, Debian has not a rc.conf.
AFAIK you mix up two distros: Debian (SysV style init process) and Arch (BSD style init process). Wikipedia has a brief explanation here: http://en.wikipedia.org/wiki/Init.
Greetings
Herbert
I'm wondering about the successful settings.
AFAIK, Debian has not a rc.conf.
AFAIK you mix up two distros: Debian (SysV style init process) and Arch (BSD style init process). Wikipedia has a brief explanation here: http://en.wikipedia.org/wiki/Init.
Greetings
Herbert
Re: NTP / time settings
So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?
Thanks
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?
Thanks
- DougieLawson
- Posts: 42772
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: NTP / time settings
NTP won't normally reset the clock if it's off by more than 1000s.really wrote:So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?
Thanks
If you run 'ntpd -gq' it ignores the clock being way adrift from ntp time and will force it to be correct then close. The old ntpdate program does the same thing.
You need an active Internet connection to run NTP.
My ntp.conf (on my RPi blank lines and comments removed)
Code: Select all
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
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
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: NTP / time settings
Thanks it really helped,
turns out , the 1000s was the culprit....
Thanks again, I been cranking on this for hours...
turns out , the 1000s was the culprit....
Thanks again, I been cranking on this for hours...
Re: NTP / time settings
Tks a lot , after some hours spend to configure the ntp.conf I finally thanks to you succeeded to have the correct time settings on my raspberry pi
Re: NTP / time settings
This thread is a bit old, but for people with similar questions there is an easier way than using ntp.
If you install the chrony package (ntp will be removed aitomatically)
Then on the next boot the date will be correct. (You may need to wait a minute or 2)
Chrony uses the NTP protocol just like ntp does, only it does it better. Especially for computers not permanently attached to the internet.
If you want chrony to use a different time server edit /etc/chrony/chrony.conf
If you install the chrony package (ntp will be removed aitomatically)
Then on the next boot the date will be correct. (You may need to wait a minute or 2)
Chrony uses the NTP protocol just like ntp does, only it does it better. Especially for computers not permanently attached to the internet.
If you want chrony to use a different time server edit /etc/chrony/chrony.conf
Re: NTP / time settings
It appears that the Raspean that come with the new PI2 has almost everything working. The only thing I had to do was symlink the /etc/localtime to the correct /usr/share/zoneinfo file for my timezone. The ntpd already runs with -gq etc.
Glad this is fixed, on my old PI B+ I had to fiddle around and get ntpdate etc.
Glad this is fixed, on my old PI B+ I had to fiddle around and get ntpdate etc.
Re: NTP / time settings
Unfortunately, the Pi2 might still have that issue.
Right now I'm working with two Pi 2s, and one of them had the time perfect after setting up the timezone and location, but the other had a 10min late time, and only corrected until I reset the service.
sudo /etc/init.d/ntp restart
I leave my Pi's running alone and I need to relay on them to have the time correctly.
So, I'm going to try chrony.
Thanks
-Daniel
Right now I'm working with two Pi 2s, and one of them had the time perfect after setting up the timezone and location, but the other had a 10min late time, and only corrected until I reset the service.
sudo /etc/init.d/ntp restart
I leave my Pi's running alone and I need to relay on them to have the time correctly.
So, I'm going to try chrony.
Thanks
-Daniel
Re: NTP / time settings
Check your DHCP server, it might be issuing an ntp ip so the Pi won't use the one you specify in the config. To fix the issue I suggest You remove the ntp server entry from your dhcp server.
- DougieLawson
- Posts: 42772
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: NTP / time settings
You could also update /etc/init.d/ntp by removing it won't use any DHCP NTP server.
Code: Select all
if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"
fi
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
-
- Posts: 19
- Joined: Wed Dec 03, 2014 5:34 am
Re: NTP / time settings
colt_cc wrote:Hi all. First post. I'm using wheezy. My pi lives in a rural location that is subject to frequent short power outages. When the the pi powers back up, it does so quicker than my router can re-acquire its internet connection. So when it tries to update its time from an NTP server it fails because it has no internet access. I believe that's what is causing some mysterious time inaccuracies on my pi. (It's not off by an integral number of hours so the time zone isn't the problem.)
Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)
Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?
Many thanks
try add
Code: Select all
# Wired adapter #1
auto eth0
iface eth0 inet static
address 192.168.0.3
netmask 255.255.255.0
gateway 192.168.0.1
dns-servers 8.8.8.8,8.8.4.4
post-up /usr/sbin/ntpdate -4 1.2.3.4
- DougieLawson
- Posts: 42772
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: NTP / time settings
Don't do that on Jessie, it will break things. Use the raspi-config option to "wait for network".standin000 wrote: try addto /etc/network/interfaces, it will wait network is OK.Code: Select all
# Wired adapter #1 auto eth0 iface eth0 inet static address 192.168.0.3 netmask 255.255.255.0 gateway 192.168.0.1 dns-servers 8.8.8.8,8.8.4.4 post-up /usr/sbin/ntpdate -4 1.2.3.4
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: NTP / time settings
Just get and RTC from adafruit.
Re: NTP / time settings
Hi guys/gals.
I'm stuck on this thing too.
(Well I think I this is the right place/topic.)
I have a PI with a RTC. It kinda keeps time. Enough for what I need.
But that isn't the problem. This is:
I hope I have set it up correctly as an NTP for my network.
When I first set it up I used a laptop (M$) and it had a program to check NTP time/s.
I clicked on the program and it said my NTP was good. I was happy.
AFAIK, my NAS sees it on boot and the time is set there correctly, or as per the RTC on said PI.
"Things have changed" and I am wanting to now ask the time from other PIs on the network.
(They boot, and get their time from that NTP server.)
It isn't happening for some reason.
I log into the NTP machine and ask it the time (date command) and it returns a reasonable enough date.
In the /etc/ntp.conf of the other PIs I have edited it to point to the IP address, and tried variants - all to no avail.
They structure of the NTP server lines is vague and that isn't helping me enter the right stuff.
On Jessie, what file tells the PI to look at the NTP and get the time?
Is it /etc/ntp.conf?
Here is an extract of mine:
Now, before I am flamed: I have tried and in a line from the ORIGINAL part:
and it works, as well as without the "extra" . (dot)
My local NTP is the 192.168.0.99 one.
It is set up as second only because I left the ZERO server alone.
If it is not connected to the BIG network, and only my network, when any other pi boots, it boots to EPOC date - or what ever the default name is.
So I am suspicious that it is something on the .0.99's side of things, but all the posts seem to skim that part of it, OR: I have done what they say and am not getting any result.
The "thing" is that I can't seem to find/resolve a command to tell the PI to "ask the NTP what time it is" that works in my setup.
Weirdly though, (and as said earlier) if all is connected to the BIg internet, the times are set.
Beats me.
I'm stuck on this thing too.
(Well I think I this is the right place/topic.)
I have a PI with a RTC. It kinda keeps time. Enough for what I need.
But that isn't the problem. This is:
I hope I have set it up correctly as an NTP for my network.
When I first set it up I used a laptop (M$) and it had a program to check NTP time/s.
I clicked on the program and it said my NTP was good. I was happy.
AFAIK, my NAS sees it on boot and the time is set there correctly, or as per the RTC on said PI.
"Things have changed" and I am wanting to now ask the time from other PIs on the network.
(They boot, and get their time from that NTP server.)
It isn't happening for some reason.
I log into the NTP machine and ask it the time (date command) and it returns a reasonable enough date.
In the /etc/ntp.conf of the other PIs I have edited it to point to the IP address, and tried variants - all to no avail.
They structure of the NTP server lines is vague and that isn't helping me enter the right stuff.
On Jessie, what file tells the PI to look at the NTP and get the time?
Is it /etc/ntp.conf?
Here is an extract of mine:
Code: Select all
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# You do need to talk to an NTP server or two (or three).
#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 0 tic.net.telstra.net iburst
server 1 192.168.0.99
It isn't 0.ntp.your-provider.example...#server ntp.your-provider.example
Code: Select all
server 0.tic.net.telstra.net iburst
My local NTP is the 192.168.0.99 one.
It is set up as second only because I left the ZERO server alone.
If it is not connected to the BIG network, and only my network, when any other pi boots, it boots to EPOC date - or what ever the default name is.
So I am suspicious that it is something on the .0.99's side of things, but all the posts seem to skim that part of it, OR: I have done what they say and am not getting any result.
The "thing" is that I can't seem to find/resolve a command to tell the PI to "ask the NTP what time it is" that works in my setup.
Weirdly though, (and as said earlier) if all is connected to the BIg internet, the times are set.
Beats me.
Re: NTP / time settings
To set the time zone without adding symlinks by hand:
Code: Select all
sudo dpkg-reconfigure tzdata
Re: NTP / time settings
Hi lerner,
/etc/ntp.conf is the right configuration file. According to the ntp.conf man page, the structure of the server line is:
Also, I noticed a typo in your first server line: instead of tic.net.telstra.net, it should be tic.ntp.telstra.net. Can it be that there is an additional server line in your ntp.conf, maybe a few lines above or below the block you are editing? Otherwise, I cannot explain how this configuration can work.
Anyways, the correct server lines in the /etc/ntp.conf of your client-Pis should be in my opinion
(The option iburst after the address speeds up the synchronization after starting the client.)
Hope that helps!
Günther
/etc/ntp.conf is the right configuration file. According to the ntp.conf man page, the structure of the server line is:
That is, there is no digit 0 or 1 between server and address. The 0. in the example you quoted belongs to the address itself.server address [options ...]
Also, I noticed a typo in your first server line: instead of tic.net.telstra.net, it should be tic.ntp.telstra.net. Can it be that there is an additional server line in your ntp.conf, maybe a few lines above or below the block you are editing? Otherwise, I cannot explain how this configuration can work.
Anyways, the correct server lines in the /etc/ntp.conf of your client-Pis should be in my opinion
Code: Select all
server tic.ntp.telstra.net iburst
server 192.168.0.99 iburst
Hope that helps!
Günther