原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1319520
CentOS6.4 x86_64 server-1 192.168.1.111 NTP服務器1 server-2 192.168.1.112 NTP服務器2 client 192.168.1.113 作為客戶端的某臺業務服務器 ntp-4.2.4p8-3.el6.centos.x86_64
[root@c64-ntp-1 ~]# rpm -qa|grep ntp #如果出現下面兩個就說明本機已經有了 ntpdate-4.2.4p8-3.el6.centos.x86_64 ntp-4.2.4p8-3.el6.centos.x86_64
[root@c64-ntp-1 ~]# yum install ntp -y
[root@c64-ntp-1 ~]#/bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #這樣我們就將時區設置成上海了 [root@c64-ntp-1 ~]# date Sat Nov 2 23:17:36 CST 2013 #可以看到我們的時區已經設置過來了
server 1.cn.pool.ntp.org server 3.asia.pool.ntp.org server 0.asia.pool.ntp.org
[root@c64-ntp-1 ~]# /usr/sbin/ntpdate 1.cn.pool.ntp.org 2 Nov 23:05:34 ntpdate[11560]: adjust time server 218.75.4.130 offset -0.114499 sec [root@c64-ntp-1 ~]# /usr/sbin/ntpdate 1.cn.pool.ntp.org #為了減少時延,我們最好執行兩遍 2 Nov 23:05:41 ntpdate[11561]: adjust time server 218.75.4.130 offset -0.111105 sec
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery #默認對所有client拒絕所有的操作 restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 #允許本機地址的一切操作 restrict -6 ::1
server 0.centos.pool.ntp.org server 1.centos.pool.ntp.org server 2.centos.pool.ntp.org
[root@c64-server-1 ~]# cat /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default kod nomodify notrap nopeer noquery notrust #默認對所有client拒絕所有的操作 restrict 127.0.0.1 #允許本機地址的一切操作 restrict 192.168.1.0 mask 255.255.255.0 nomodify #允許局域網內所有client連接到這臺服務器同步時間.但是拒絕讓他們修改服務器上的時間 server 1.cn.pool.ntp.org perfer #指定該上級NTP服務器為最優先 server 3.asia.pool.ntp.org #這個上級NTP服務器是在官網找到離上海最近的NTP服務器 server 0.asia.pool.ntp.org #這里我們也可以用上海交大之類提供的公益性NTP服務器 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
[root@c64-ntp-1 ~]# /etc/init.d/ntpd start Starting ntpd: [ OK ]
[root@c64-ntp-1 ~]# netstat -lntup|grep ntp udp 0 0 192.168.1.113:123 0.0.0.0:* 11992/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 11992/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 11992/ntpd udp 0 0 fe80::20c:29ff:fe06:9c22:123 :::* 11992/ntpd udp 0 0 ::1:123 :::* 11992/ntpd udp 0 0 :::123 :::* 11992/ntpd [root@c64-ntp-1 ~]# ps -ef |grep ntp|grep -v grep ntp 11992 1 0 02:17 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
[root@c64-ntp-1 ~]# echo '#ntp server boot configuration by sunsky in 20131020' >>/etc/rc.local [root@c64-ntp-1 ~]# echo '/etc/init.d/ntpd start start' >>/etc/rc.local [root@c64-ntp-1 ~]# tail -2 /etc/rc.local #檢查配置結果 #ntp server boot configuration by sunsky in 20131020 /etc/init.d/ntpd start
[root@c64-client /]# /usr/sbin/ntpdate 192.168.1.111&&hwclock -w 3 Nov 03:50:34 ntpdate[19587]: adjust time server 192.168.1.111 offset -0.046270 sec [root@c64-client /]# /usr/sbin/ntpdate 192.168.1.112&&hwclock -w 3 Nov 03:50:48 ntpdate[19589]: adjust time server 192.168.1.112 offset -0.039505 sec
[root@c64-client ~]# echo '*/5 * * * * /usr/sbin/ntpdate 192.168.1.111&&hwclock -w >/dev/null 2>&1' >>/var/spool/cron/root [root@c64-client ~]# echo '*/10 * * * * /usr/sbin/ntpdate 192.168.1.112&&hwclock -w >/dev/null 2>&1' >>/var/spool/cron/root
[root@c64-client /]# crontab -l */5 * * * * /usr/sbin/ntpdate 192.168.1.111&&hwclock -w >/dev/null 2>&1 */10 * * * * /usr/sbin/ntpdate 192.168.1.112&&hwclock -w >/dev/null 2>&1
轉自:http://nolinux.blog.51cto.com/4824967/1319520
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/2015