![]() |
|||||||||||||||||||||||||||
|
This page was last modified: July 24 2008 00:54:01 | ||||||||||||||||||||||||||
Change the timezoneIn most cases you select the appropriate timezone when installing the machine, and then live happily ever after. But recently I experinced one of those rare moments where you actually want to change the timezone on a server. The server was running UTC and I wanted it to be CEST, since the server is located in Denmark. All I did was to copy the Copenhagen zone info file to /etc/localtime: cp /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime After that, I rebooted the server. This is necessary since many applications only read the time information on startup - and it is much easier to reboot than restarting every application with the risc of missing one or two. Synchronize your clockAs time passes, the computer's clock becomes less accurate. NTP (Network Time Protocol) is one way to ensure your clock is right. NTP has two ways to accomplish time synchronization - One is ntpdate(8), and another is ntpd(8) Do not confuse NTP with NNTP ;-) ntpdate(8) only synchronizes the clock when your machine boots up. It will set the time regardless of the difference between a machine's current clock setting and the correct time. ntpd(8) runs as a daemon, and synchronizes your clock periodically. But if the time difference is more than 1 hour, it will assume that there is a problem with the timezone, and skip synchronization. You can overrule that setting if you want, as you'll see in a moment. I use both ntpdate and ntpd on my server. ntpdate synchronizes at boot time, ensuring that the difference is less than one hour. Then the ntpd daemon takes over. How to enable ntpdateOpen /etc/rc.conf in your favorite text editor, and insert these lines (replace ntp.example.tld with an ntp server of your choice):
ntpdate_enable="YES" You can test ntpdate like this:
ntpdate ntp.example.tld In the above example the clock was running 127 seconds behind and has now been synchronized. How to enable ntpdCreate /etc/ntp.conf according to this example:
server ntp.example.tld In /etc/rc.conf this line must be added, to start the ntpd daemon at boot time.
ntpd_enable="YES" In ntpd_flags I have used the -g option. This makes it possible to set the time even if the limit is exceeded. The reason I have done this, is because I want the time to be set also when it changes to Daylight Savings Time. I don't know how it works for other countries, but here in Denmark there is a general rule never to set a cronjob up at 02:00, because twice a year we go to Daylight Savings Time at that exact moment... so keep that in mind. The driftfile option specifies which file is used to store the system clock's frequency offset. The ntpd(8) program uses this to automatically compensate for the clock's natural drift, allowing it to maintain a reasonably correct setting even if it is cut off from all external time sources for a period of time. Don't create the driftfile... ntpd will take care of this by itself. Your NTP server is accessable by default. The restrict option specified in the above, denies all machines from accessing your NTP server. To start ntpd without rebooting, just execute the ntpd command: /usr/sbin/ntpd -g -p /var/run/ntpd.pid After that, ntpd should be running - To check this, have a look at your processes:
ps -ax | grep ntpd NTP serversIt is common to have 2 or 3 servers listet in ntp.conf. Your ISP may have a server available for you to use, otherwise, have a look at this page: |
|||||||||||||||||||||||||||