HOGYAN NTP

A Gentoo Linux Wiki wikiből

Tartalomjegyzék

[szerkesztés] Mi az az NTP?

Az NTP (Network Time Protocol) arra használható, hogy szinkronizáld a számítógépeid rendszeridejét egy online szerverrel. Egy nagyon hasznos program, és minden gépre telepíthető.

Az NTP-t arra is használhatjuk, hogy időt szolgáltassunk egy hálózatnak. Például egy Windows és Linux gépekből álló LAN hálózat összes gépét szinkronizálhatjuk egy NTP szerverrel, ezáltal sávszélességet takaríthatunk meg, mivel nem kell mindegyik kliensnek az internetre kimennie az aktuális időárt, hanem elég az NTP szerverünkig elmennie.

Vannak alternatív programok, hogy végrehajtsák az idő szinkronizációt NTP-n keresztül, ilyen az openntpd és a chrony is.

Az ntp telepítéséhez: Az ntp telepítéséhez állítsuk be a caps USE flaget a package.use fájlban.

echo "net-misc/ntp caps" >> /etc/portage/package.use
emerge ntp

A caps támogatáshoz kernel támogatás is szükséges!

Figyelmeztetés:

FIXME - A caps támogatás segítségével elérhető, hogy az egyébként root felhasználóként futó NTP indulás után eldobja a root privilégiumokat és ntp felhasználóval fusson tovább!

[szerkesztés] A tűzfal beállítása

Az NTP az UDP 123-as portot használja. TCP-t nem használ. Ahhoz hogy szinkronizálni tudjunk egy interneten lévő külső idő szerverrel, a következő iptables szabály elegendő:

-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

[szerkesztés] Idő szerverek keresése

Az NTP-t egy vagy több időszerverrel kell szinkronizálni. Az alapértelmezett Gentoo konfiguráció pool szerverek indexét tartalmazza, így minden szinkronizáláskor más szerverhez fordul.

Alternatívaként használhatsz három nyílt hozzáférésű stratum 2 idő szervert a saját országodból. Használhatod például a /usr/sbin/tracepath ntp.demon.co.uk vagy netselect -s 3 pool.ntp.org (elérhetővé válik az "emerge netselect" után) parancsot, hogy megtaláld a legkisebb kommunikációs reakcióidőt nyújtó szervereket. Továbbá elérhető a helyi pool szerverek listája is.

[szerkesztés] Idő szerverek listája (országok szerint)

OrszágTime szerverek
Argentinatime.sinectis.com.ar
Australiaau.pool.ntp.org
Austriatime.tugraz.at
Canadaca.pool.ntp.org
Czech Republicntp.cgi.czntp.globe.czntp.cesnet.cz
Denmarkntp1.tele.dkntp2.tele.dk
Finlandtime1.mikes.fitime2.mikes.fi
Francentp.unice.fr
Germanyntps1-0.cs.tu-berlin.deptbtime1.ptb.dentp0.fau.de
Irelandntp0.esat.netntp1.esat.netntp2.esat.net
Israeltimeserver.iix.net.ilntp.ac.il
Italyntps.net4u.itntp1.ien.itntp2.ien.itntp.iriti.cnr.it
Latviatime.latnet.lv
Netherlandsnl.pool.ntp.org
Polandntp.task.gda.pl
Portugalntp02.oal.ul.pt
Romaniaro.pool.ntp.org
South Africatock.nml.csir.co.za
Swedenntp.lth.sentp1.sp.sentp.luth.sentp1.sth.netnod.sentp1.gbg.netnod.se
Switzerlandntp.metas.chswisstime.ethz.ch
UKntp.demon.co.ukntp2b.mcc.ac.ukntp2c.mcc.ac.ukuk.pool.ntp.org
USntp1.sf-bay.orgtock.cs.unlv.edurolex.usg.edutime.nist.gov

[szerkesztés] Az ntpdate használata az idő beállítására most, és az bootolásnál

A következő utasítások szinkronizálják az órád ( amikor kézzel futtatod, és ami sokkal fontosabb, mindíg amikor a számítógéped elindul ). Hogy szinkronban maradjon a gép órája , napról napra, futtatnod kell az ntpd-t, amit majd később elmagyarázunk.

Az /etc/conf.d/ntp-client file-ban, változtasd meg ezt a sort:

File: /etc/conf.d/ntp-client
NTPCLIENT_OPTS="-b -u elsőszerver másodikszerver harmadikszerver"

Szedd ki előle a megjegyzés jelet, és add hozzá a szerver listádat ( szóközökkel elválasztva ). A kliensed most már készen áll a szerver(ekk)el való szinkronizálásra.

Most frissítsd az órádat, és futtasd az ntpdate-et. Az órád azonnali szinkronizálásához futtasd az első sort. A második sorral az alapértelmezett futási szinthez tudod hozzáadni, szóval minden induláskor le fog futni.

/etc/init.d/ntp-client start
rc-update add ntp-client default

Ha minden rossz ( ilyeneket ír hogy: "Failed to set clock" vagy "Unable vagy locate the client command" ) A /etc/conf.d/ntp-client file-ban szedd ki a megjegyzásből a következő sort, és módosítsd így:

File: /etc/conf.d/ntp-client
NTPCLIENT_CMD="ntpdate"

[szerkesztés] A szolgáltatás függőségei

Az ntp-client-nek nyilvánvalóan azután kell lefutnia, miután az Internet kapcsolat már aktív. Ha például, az Internet kapcsolatot a /etc/init.d/net.eth0 állítja be, akkor az /etc/init.d/ntp-client depend() függvényét kellene módosítani, hozzáadva a net.eth0-t az after sorhoz. Végül a függvény nézne ki:

File: /etc/init.d/ntp-client
depend() {
        before cron portmap
        need net
        after net.eth0
        use dns logger
}

Az is lehetséges, hogy az net.eth0 script befejezi a futását, az Internet kapcsolat felállása előtt, ami azt okozza, hogy az ntp-client nem fog tudni sikeresen lefutni. Ebben az esetben egy kis szünetet kellene adni az Internet beállító scripthez. Pl:

File: /etc/init.d/net.eth0
postup() {
        # Wait for connection to be ready to communicate
        sleep 4
        return 0
}

[szerkesztés] Az NTP használata, az órád szinkronban tartásához

Amíg az ntpdate hasznos, az idő azonnali megváltoztatásához, sokkal jobb hogy használd az ntpd-t az időd felhasználására, mivel ez ritkán változtatja az órádat, hogy megszüntesse az elállítódást.

[szerkesztés] Az ntp beállítása

Győződj meg róla, hogy az /etc/conf.d/ntpd fileban a következő sor ki van szedve a megjegyzésből:

File: /etc/conf.d/ntpd
NTPD_OPTS="-u ntp:ntp"

Ha 2.6 os kernelt használsz, bizonyosodj meg rőla, hogy a következő beállításokkal lett lefordítva:

Linux Kernel Beállítás: make menuconfig
Security options  --->
 [*] Enable different security models
 <*>   Default Linux Capabilities

Now edit /etc/ntp.conf as per the official docs, ntp wiki and the time servers you chose above.

File: Example /etc/ntp.conf
restrict 127.0.0.1 nomodify
# Allow ntp to automatically correct predictable clock drift
driftfile /var/lib/ntp/ntp.drift
# logfile defaults to /var/log/messages
logfile /var/log/ntp.log
# Un-comment the next line, to act as a time server to the local network
#restrict 192.168.0.1 mask 255.255.255.0 nomodify nopeer notrap

Generic server list:

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org

Good server list for machines based in the UK:

# This is the fastest, therefore preferred server
server ntp.demon.co.uk prefer
# The next two servers are DNS-chosen at random from the country-localized pool
server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org

As mentioned in the ntp wiki, be careful about defining a restrict default line. When using pool servers, these IP addresses will be handled by the default restriction, and could be blocked with a strict default policy, such as restrict default ignore.

[szerkesztés] LAN Server

You can set up your systems hardware clock as a reference clock by using the fudge command. This will allow your system to always return a stratum 10 result. However before a Windows XP system will synchronize to this server, the server must synchronize to gain a lower stratum result (e.g. stratum 1). This will be acknowledged by /var/log/ntp.log in the following form. The synchronization can take a few minutes.

File: /var/log/ntp.log
3 May 19:46:05 ntpd[24616]: synchronized to LOCAL(1), stratum=10
3 May 19:46:06 ntpd[24616]: synchronized to 1.2.3.4, stratum=1
3 May 19:51:31 ntpd[24616]: synchronized to 2.3.4.5, stratum=1
3 May 20:21:44 ntpd[24616]: synchronized to 3.4.5.6, stratum=1

Also note the restriction on the LAN in /etc/ntp.conf. This must be done to stop your NTP server synchronizing to your LAN.

samba can also act as the time server for a Windows network, by adding time server = yes to /etc/samba/smb.conf

[szerkesztés] Clock Accuracy at Reboot

The following option sets the hardware clock during shutdown, so that the clock is accurate even before ntp-client runs during startup:

File: /etc/conf.d/clock
CLOCK_SYSTOHC="yes"

[szerkesztés] DHCP info

NOTE: If you are using dhcp to get an ip address, dhcpcd will overwrite /etc/ntp.conf by default. If your dhcp server hands out a valid ntp server this is not a problem. If it does not hand out a valid ntp server, you will want to make sure dhcpcd will not overwrite this file. You can do this by editing /etc/conf.d/net as such:

File: /etc/conf.d/net
dhcpcd_eth0="-N"

Where eth0 is the interface using dhcpcd.

[szerkesztés] Finalizing

All thats left to do is start ntpd and add it to the default runlevel.

/etc/init.d/ntpd start
rc-update add ntpd default

[szerkesztés] Checking ntp

After a few minutes, ensure that the stratum shown from the command below is less than 16. If it remains at 16, then synchronization is failing. It should settle at 3, from synchronization with stratum 2 servers.

ntpq -c rv | grep stratum

You can check what peers you are connected to (and in turn what they are connected to):

ntpq -c pe

For some more information:

ntpq -c rv

[szerkesztés] Troubleshooting

If date shows the wrong hour, then check /etc/conf.d/clock and /etc/localtime in the localization guide.

Ensure that ntp-client and ntpd are in the default runlevel, not the boot runlevel:

rc-update show | grep ntp
rc-update del ntp-client boot
rc-update del ntpd boot
rc-update add ntp-client default
rc-update add ntpd default

Client machines will refuse to synchronize from a stratum 16 time server, with the error message, no server suitable for synchronization found.

If you are seeing Bad file descriptor errors in /var/log/messages, then make sure that only one instance of ntpd is running:

/etc/init.d/ntpd stop
killall ntpd
/etc/init.d/ntpd zap
/etc/init.d/ntpd start

If you are seeing the error message Error : Servname not supported for ai_socktype, then run:

echo "ntp 123/udp" >> /etc/services
/etc/init.d/ntpd restart

If you have previously tried to set up NTP through Gnome's time & date settings, and are seeing Failed to set clock or NTP socket is in use errors, then uncheck Gnome's "Synchronize clock with Internet servers" box.

Try reading The ISC troubleshooting guide, which includes some tools for remotely querying your server, to make sure your firewall or your ISP's firewall isn't blocking TCP/UDP 123

[szerkesztés] ChangeLog

  • 9/20/2005 - /etc/conf.d/ntpd has new settings.
  • 2/12/2005 - Removed the option notrust from the config files. This allows the server to run with a non-root account. The other option is to have the service run as root. For further information see http://bugs.gentoo.org/show_bug.cgi?id=41827
A lap eredeti címe: „http://hu.gentoo-wiki.com/HOGYAN_NTP
Személyes eszközök