一、编译安装ntp server
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.6.tar.gz
tar zxvf ntp-4.2.6.tar.gz
cd ntp-4.2.6
./configure --prefix=/usr/local/src/ntp --enable-all-clocks --enable-parse-clocks
make && make install服务器
二、修改ntp.conf配置文件ide
vi /etc/ntp.confui
①、第一种配置:容许任何IP的客户机均可以进行时间同步
将“restrict default kod nomodify notrap nopeer noquery”这行修改为:rest
restrict default nomodifyserver
配置文件示例:/etc/ntp.confblog
②、第二种配置:只容许192.168.18.***网段的客户机进行时间同步
在restrict default nomodify notrap noquery(表示默认拒绝全部IP的时间同步)以后增长一行:进程
restrict 192.168.18.0 mask 255.255.255.0 nomodifyci
配置文件示例:/etc/ntp.confget
三、以守护进程启动ntpd同步
/usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
四、ntpd启动后,客户机要等几分钟再与其进行时间同步,不然会提示“no server suitable for synchronization found”错误。
2、配置时间同步客户机
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/目录,而后解压:
wget http://blog.s135.com/p_w_upload/200708/ntdate.tar.gz cd /usr/sbin/ tar zxvf ntpdate.tar.gz