天天看點

Linux搭建時間同步伺服器

一、搭建時間同步伺服器

1、編譯安裝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

①、第一種配置:允許任何ip的客戶機都可以進行時間同步

将“restrict default kod nomodify notrap nopeer noquery”這行修改成:

restrict default nomodify

②、第二種配置:隻允許192.168.18.***網段的客戶機進行時間同步

在restrict default nomodify notrap noquery(表示預設拒絕所有ip的時間同步)之後增加一行:

restrict 192.168.18.0 mask 255.255.255.0 nomodify

3、以守護程序啟動ntpd

/usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid

4、ntpd啟動後,客戶機要等幾分鐘再與其進行時間同步,否則會提示“no server suitable for synchronization found”錯誤。

二、配置時間同步客戶機

vi /var/spool/cron/root

增加一行,在每天的5點13分、9點13分、14點13分、19點13分與時間同步伺服器進行同步

13 5,9,14,19 * * * /usr/sbin/ntpdate 192.168.18.2

備注:如果客戶機沒有ntpdate,可以下載下傳ntpdate.tar.gz到/usr/sbin/目錄,然後解壓:

cd /usr/sbin/

tar zxvf ntpdate.tar.gz

繼續閱讀