您好,登錄后才能下訂單哦!
本篇內容主要講解“l(fā)inux下ntp服務器的搭建步驟”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“l(fā)inux下ntp服務器的搭建步驟”吧!
一、搭建時間服務器
1、在一臺linux服務器安裝ntp server
tar zxvf ntp-4.2.6.tar.gz
cd ntp-4.2.6
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
2、修改ntp.conf配置文件
vi /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
(允許任何IP的客戶機都可以進行時間同步,如果是只允許某個網(wǎng)段的客戶機進行時間同步可以這樣寫
restrict 10.58.26.0 mask 255.255.255.0 nomodify)
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool
#server 0.rhel.pool.ntp.org(默認時間服務器)
#server 1.rhel.pool.ntp.org(默認時間服務器)
#server 2.rhel.pool.ntp.org(默認時間服務器)
server 10.128.14.25 (手工設置的時間服務器)
(如果是可以直連外網(wǎng),可以使用LINUX默認提供的三組標準時間服務器,否則可以自己指定一個同步時間源)
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
3、以守護進程啟動ntpd
#/etc/rc.d/init.d/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
#/etc/rc.d/init.d/ntpd start
#ps -ef|grep ntpd
4、在ntp server上啟動ntp服務后,ntp server自身或者與其server的同步的需要一個時間段,這個過程可能是5分鐘,在這個時間之內在客戶端運行ntpdate命令進行同步時會產生no server suitable for synchronization found的錯誤。
那么如何知道何時ntp server完成了和自身同步的過程呢?
在ntp server上使用命令:
# watch ntpq -p
出現(xiàn)如下畫面:
注意LOCAL的這個就是與自身同步的ntp server。
注意reach這個值,在啟動ntp server服務后,這個值就從0開始不斷增加,當增加到17的時候,從0到17是5次的變更,每一次是poll的值的秒數(shù),是64秒*5=320秒的時間。
二、配置時間同步客戶機
vi /var/spool/cron/root(或crontab -e)
增加一行,在每天的1點10分、9點10分、17點10分與時間同步服務器進行同步并寫入BIOS
10 1 ,9,17* * * root /usr/sbin/ntpdate 10.128.14.25; /sbin/hwclock -w
* /2 * * * * root /usr/sbin/ntpdate 10.128.14.25; /sbin/hwclock -w
如果同步不正常,可以加輸出日志或看系統(tǒng)日志
輸出日志的方法:
10 1 ,9,17* * * root /usr/sbin/ntpdate 10.128.14.25>>/tmp/1.txt; /sbin/hwclock -w
在1.txt中可查看時間同步時的輸出結果。
或者看/var/mail/root系統(tǒng)日志
Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 10.128.14.25;/sbin/hwclock -w
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20121127103001.076FF2090E@tyzssq8.site>
Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST)
27 Nov 18:29:59 ntpdate[6917]: step time server 10.128.14.25 offset -1.361968 sec
可以看到同步成功了,如果未成功會報出錯誤。
三、無法同步的問題
檢查ntp server主機的防火墻??赡苁莕tp server的防火墻屏蔽了upd 123端口。
可以用命令
#service iptables stop
來關掉iptables服務后再嘗試從ntp客戶端的同步,如果成功,證明是防火墻的問題,需要更改iptables的設置。
到此,相信大家對“l(fā)inux下ntp服務器的搭建步驟”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。