个人工具

UbuntuHelp:UbuntuLTSP/InstallNTPServer

来自Ubuntu中文

跳转至: 导航, 搜索
This page is specific to Ubuntu versions 8.04

If you find this information applicable to additional versions/releases, please edit this page and modify this header to reflect that. Please also include any necessary modifications for this information to apply to the additional versions.


This page is dedicated to installing an NTP (Network Time Protocol) server on your LTSP server, to serve the correct time to your thin-clients. This writeup is a result of my efforts to Automatically shut down thin-clients via cron, and noticing that my thin-client times were randomly off, therefore not executing the cron job at the correct time. It's always a good idea to have the same time on your network, anyway.

  • On the LTSP server, install NTP:
sudo apt-get install ntp
  • Now we enter our chroot environment and create an RCFILE to run the 'ntpdate' program. This is apparently not an issue in later versions of Ubuntu (as you will see in the file by using the $TIMESERVER variable which makes it forwards-compatible with newer LTSP versions' $TIMESERVER variable available in the lts.conf file):
sudo mkdir /opt/ltsp/i386/etc/ltsp

sudo vim /opt/ltsp/i386/etc/ltsp/ntpdate

/opt/ltsp/i386/etc/ltsp/ntpdate:

    #!/bin/bash
    #
    if [ -n $TIMESERVER ]; then
       ntpdate $TIMESERVER &
    else
       ntpdate pool.ntp.org
    fi
  • Make the script executable:
sudo chmod +x /opt/ltsp/i386/etc/ltsp/ntpdate
  • Now we modify our lts.conf file to reflect the new startup script for clients to execute upon bootup (and, again, utilizing the $TIMESERVER variable for later versions):
sudo vim /var/lib/tftpboot/ltsp/i386/lts.conf

/var/lib/tftpboot/ltsp/i386/lts.conf:

TIMESERVER = ip_of_timeserver
RCFILE_01 = /etc/ltsp/ntpdate

(Substitute RCFILE_01 with a different number if you are already using it)

  • Now we update our client chroot image:
sudo ltsp-update-image
  • Reboot your thin-clients, and enjoy synchronized time between clients and server!

Update: ntpdate script using getltscfg

This ntpdate script uses the getltscfg command to extract the TIMESERVER value from lts.conf (Using the "$TIMESERVER" variable does not work in my 8.04 config).

#!/bin/bash
#
# P. Baco - Carlit.net 
# (from an original idea of Jordan Erickson)
# ntpdate script to synchronise thin client(s)
# and the NTP/LTSP server.
# 
# Use getltscfg to get "TIMERSERVER" value in
# lts.conf. 
# TIMESERVER must contain the IP address of a
# valid NTP server (LTSP Server should be one).
#
LTSP_TIMESERVER=$(getltscfg TIMESERVER)
if [ -n "$LTSP_TIMESERVER" ]; then
       ntpdate $LTSP_TIMESERVER &
    else
       ntpdate pool.ntp.org
    fi