简介
时间服务NTP:Network Time Protocol
作用:用来给其他主机提供时间同步服务,在搭建服务器集群的时候,需要保证各个节点的时间是一致的,时间服务器不失为一个好的选择。
准备工作
- 关闭防火墙、关闭selinux
- 系统rhel6.5
- ntp服务器 192.168.1.28 客户端192.168.1.23
安装配置
服务器端操作
[root@localhost ~]# iptables -F
[root@localhost ~]# yum -y install ntp
[root@localhost ~]# cp /etc/ntp.conf{,.bak}
[root@localhost ~]# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
logfile /var/log/ntp.log #自己添加的
server 127.127.1.0 #以本机作为时间服务器
fudge 127.127.1.0 startnum 10 #设置服务器层级
restrict 127.0.0.1 #允许本机使用这个时间服务器
restrict 192.168.1.0 netmask 255.255.255.0 #允许192.168.1.0这个网段的主机使用
[root@localhost ~]# service ntpd start
状态查看
服务器或者客户端都可以查看
[root@localhost ~]# ntpstat
synchronised to local net at stratum 6
time correct to within 11 ms
polling server every 64 s
客户端安装配置
[root@localhost ~]# iptables -F
[root@localhost ~]# yum -y install ntp ntpdate
[root@localhost ~]# cp /etc/ntp.conf{,.bak}
[root@localhost ~]# vim /etc/ntp.conf
logfile /var/log/ntp.log #自己添加的
server 127.127.1.0 #以本机作为时间服务器
restrict 127.0.0.1 #允许本机使用这个时间服务器
#执行一次时间同步
[root@localhost ~]# ntpdate 192.168.1.28
14 Feb 09:58:05 ntpdate[3162]: the NTP socket is in use, exiting
#启动ntp
[root@localhost ~]# service ntpd start