Network Time Protocol (NTP) is a protocol used to sychronise a computer's system clock. To ensure your server maintains the correct time, it is a good idea to set up cron job to update you time settings nightly using ntpdate.
To do this, first check to see whether NTP is installed. On a Red Hat system you can do this by running:
rpm -qa | grep ntpdate
On a Debian/Ubuntu system you would run:
dpkg -l | grep ntpdate
If it's not installed, you can install it using your distro's package manager. On Red Hat systems run:
yum install ntpdate
On Debian/Ubuntu systems run:
apt-get install ntpdate
You can then test it works by running:
ntpdate -q uk.pool.ntp.org
The -q switch runs ntpdate in query mode, causing it to report what changes would be made, but making no actual changes. The example shown runs the query against the UK NTP server pool. Different countries have different pools, e.g. de.pool.ntp.org for Germany, fr.pool.ntp.org for France, etc.
Next, we need to set up the cron job. First type:
crontab -e
This will open the crontab program in editing mode. Press 'i' to enter insert mode and type:
0 2 * * * /usr/sbin/ntpdate -s uk.pool.ntp.org
Then save and exit.
This will update the server time at 2am every morning, from NTP servers in the UK pool. The -s switch diverts any output to the normal system logs.
Note: remember to restart cron after editing crontab using: /etc/init.d/cron restart
Friday, November 19, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment