一、NTP
Network Time Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议***。
最简单方法,直接同步网络时间
1、/etc/init.d/ntp stop2、sudo /usr/sbin/ntpdate time.nist.gov3、/usr/sbin/ntpdate 1.cn.pool.ntp.org (这两个都可以)
二、ntp服务器配置
1、ntp的安装
我使用yum方式安装
[root@node1 ~]# yum -y install ntp |
2、修改ntp的配置文件
[root@node1 ~]# vim /etc/ntp.conf |
(1)以内网时间为准
如果想让时间与内网中的某一台主机的时间为准,就在配置文件中加入这两项
restrict 172.16.0.0 mask 255.255.255.0 nomodifyserver 172.16.0.1 |
(2)以外网时间为准
restrict 210.72.145.44 #授权国家授时中心服务器访问本地NTPrestrict 133.100.11.8 # 授权133.100.11.8访问本地NTPrestrict 172.16.0.0 mask 255.255.0.0 nomodify #授权本地网段访问server 210.72.145.44 prefer #指定上级更新时间服务器,优先使用此地址server 133.100.11.8 |
这里第1,2条必须得写上,不写客户端死活同步不成功,总是报“no server suitable for synchronization found”这个错;不知道他们不写的为什么能同步成功!
3、启动服务并查看123端口是否监听成功
[root@node1 ~]# service ntpd start |
4、查看本地ntp与上级服务器的通讯情况
[root@node1 ~]# watch ntpq -p |
(1)ntp服务器为内网时
(2)ntp服务器为外网时
5、服务器的iptables也会影响到客户端的同步!
#iptables -I INPUT -p udp --dport 123 -j ACCEPT
6、ntpd服务设为开机启动
# chkconfig ntpd on# chkconfig ntpdate on
7、也可以加入到/etc/rc.local里
三、客户端设置
在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生no server suitable for synchronization found的错误,所以稍安勿躁,客官且先歇息一会儿!
(1)手动同步设置
[root@node1 ~]# ntpdate 172.16.0.1 #ntp时间服务器IP22 Apr 19:50:35 ntpdate[13190]: adjust time server 172.16.0.1 offset 0.001279 sec |
(2)任务计划
每次手动更新多麻烦啊,那就设置一个任务计划吧,让它每30分钟自己去服务器更新一次
[root@node1 ~]# crontab -e*/30 * * * * /usr/sbin/ntpdate 172.16.0.1 |
配置一个ntp时间服务器就上面那些步骤就已经OK啦!