Linux系統(tǒng)使用NTP服務(wù)器的方法
Linux系統(tǒng)下的NTP服務(wù)器指的是網(wǎng)絡(luò)時(shí)間同步協(xié)議,其作用就是同步網(wǎng)絡(luò)時(shí)間和Linux系統(tǒng)中的時(shí)間,使得Linux時(shí)間更加精確。下面就來介紹一下Linux系統(tǒng)下如何使用NTP服務(wù)器。
一、ntp配置文件
1. /etc/ntp.conf
NTP服務(wù)的主要配置文件,不同的Linux版本文件所在的目錄可能會(huì)不同。
2. /usr/share/zoneinfo
規(guī)定了各主要時(shí)區(qū)的時(shí)間設(shè)定文件。/usr/share/zoneinfo/Asia/Shanghai 為中國(guó)大陸地區(qū)的時(shí)區(qū)設(shè)定文件。
3. /etc/sysconfig/clock
時(shí)區(qū)設(shè)置文件
4. /etc/localtime
本地系統(tǒng)的時(shí)間設(shè)定文件
。踨oot@linuxidc1 ~]# grep -v “^#” /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery/pic/p>
restrict -6 default kod nomodify notrap nopeer noquery /pic/p>
restrict 127.0.0.1 /pic/p>
restrict -6 ::1
server 0.rhel.pool.ntp.org /pic/p>
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server 127.127.1.0 /pic/p>
fudge 127.127.1.0 stratum 10 /pic/p>
driftfile /var/lib/ntp/drift /pic/p>
keys /etc/ntp/keys
參數(shù):
ignore :關(guān)閉所有的 NTP 聯(lián)機(jī)服務(wù)
nomodify:客戶端不能更改服務(wù)端的時(shí)間參數(shù),但是客戶端可以通過服務(wù)端進(jìn)行網(wǎng)絡(luò)校時(shí)。
notrust :客戶端除非通過認(rèn)證,否則該客戶端來源將被視為不信任子網(wǎng)
noquery :不提供客戶端的時(shí)間查詢
二、具體配置
。踨oot@linuxidc1 ~]# vim /etc/ntp.conf
3 restrict default kod nomodify notrap nopeer noquery
4 #restrict -6 default kod nomodify notrap nopeer noquery
5 restrict default nomodify
6 restrict 192.168.8.0 mask 255.255.255.0 nomodify
11 restrict 127.0.0.1
18 #server 0.rhel.pool.ntp.org
19 #server 1.rhel.pool.ntp.org
20 #server 2.rhel.pool.ntp.org
21 server 192.168.8.70
31 server 127.127.1.0 # local clock
32 fudge 127.127.1.0 stratum 10
[root@linuxidc1 ~]# /etc/init.d/ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
客戶端測(cè)試
注:客戶端的/etc/hosts里需要加上ntp服務(wù)器的ip地址和主機(jī)名
。踨oot@linuxidc2 ~]# ntpdate 192.168.8.70
2 Mar 00:35:44 ntpdate[11181]: no server suitable for synchronization found
注:在ntp server上啟動(dòng)ntp服務(wù)后,ntp server自身或者與其server的同步的需要一個(gè)時(shí)間段,這個(gè)過程可能是5分鐘,在這個(gè)時(shí)間之內(nèi)在客戶端運(yùn)行ntpdate命令進(jìn)行同步時(shí)會(huì)產(chǎn)生 no server suitable for synchronization found的錯(cuò)誤。
查看同步的過程
[root@linuxidc1 ~]# watch ntpq -p
注:LOCAL的這個(gè)就是與自身同步的ntp server。reach這個(gè)值,在啟動(dòng)ntp server服務(wù)后,這個(gè)值就從0開始不斷增加,當(dāng)增加到17的時(shí)候,從0到17是5次的變更,每一次是poll的值的秒數(shù),是64秒*5=320秒的時(shí)間。
客戶端測(cè)試
。踨oot@linuxidc2 ~]# ntpdate 192.168.8.70
2 Mar 00:40:51 ntpdate[11184]: adjust time server 192.168.8.70 offset -0.000031 sec
。踨oot@linuxidc2 ~]# date
Sat Mar 2 01:00:13 CST 2013
服務(wù)器端
。踨oot@linuxidc1 ~]# date
Sat Mar 2 01:00:15 CST 2013
。踨oot@linuxidc1 ~]#
以上就是Linux系統(tǒng)下使用NTP服務(wù)器的方法了,使用NTP服務(wù)器同步Linux時(shí)間,也可以讓服務(wù)器下不同計(jì)算機(jī)的時(shí)間達(dá)成一致。
【Linux系統(tǒng)使用NTP服務(wù)器的方法】相關(guān)文章:
Linux系統(tǒng)top命令的使用方法介紹10-12
Linux系統(tǒng)使用附加權(quán)限的方法介紹01-26
Linux系統(tǒng)常用的網(wǎng)絡(luò)命令及使用方法02-08