今天對虛擬機的的幾台主機做了一下NTP配置。
NTP(Network Time Protocol)是用來使計算機時間同步化的一種協議,它可以使計算機對其服務器或時鍾源做同步化,它可以提供高精准度的時間校正。
確認系統是否安裝ntp服務:rmp -qa | grep ntp
[root@hadoop03 hadoop]# rpm -qa | grep ntp fontpackages-filesystem-1.41-1.1.el6.noarch ntp-4.2.4p8-3.el6.centos.x86_64 ntpdate-4.2.4p8-3.el6.centos.x86_64
如果未安裝請自行安裝。
說明:
三台主機:
192.168.153.101(NTP服務器)
192.168.153.102
192.168.153.103
操作系統:
[root@hadoop03 hadoop]# cat /etc/issue CentOS release 6.4 (Final)
NTP服務器配置:
修改ntp配置文件:vi /etc/ntp.conf 追加以下
restrict 192.168.153.1/24 mask 255.255.255.0 nomodify #限制只能192.168.153.x 網段從NTP服務器同步時間,並且客戶端主機不能修改
server time-b.nist.gov #遠程時間服務器的地址
server 127.127.1.0 # local clock 本地時間服務器
fudge 127.127.1.0 stratum 10
關閉iptable
sudo chkconfig iptables off
sudo /etc/init.d/iptables stop
如果沒有關閉:
vi /etc/sysconfig/iptables 打開防火牆配置文件。加入如下配置項:
#open port for NTP server
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
重啟防火牆 service iptables restart
相關命令:
service ntpd stop 關閉ntp服務
service ntpd start 開啟ntp服務
service ntpd restart 重啟ntp服務
ntpstat 查看同步情況:
[root@hadoop01 hadoop]# ntpstat synchronised to local net at stratum 11 time correct to within 11 ms polling server every 512 s [root@hadoop03 hadoop]# ntpstat synchronised to NTP server (192.168.153.101) at stratum 12 time correct to within 18 ms polling server every 64 s
立即同步時間:
service ntpd stop
ntpdate ntpserverip
客戶端配置:
修改ntp配置文件:vi /etc/ntp.conf 追加以下
server 192.168.153.101
重啟ntp服務 service ntpd restart