主要讲述在局域网中,以内部ntp服务器为数据服务器时钟的方法,可以实现对多台linux服务器的时间同步。
一、查询是否安装ntp,若没有安装的话,先进行安装。
查询方法:
[root@test241 ~]#rpm –q ntp
ntp-4.2.4p8-2.el6.x86_64
则表示已经有安装,或安装成功。
二、ntp服务器端配置(192.168.1.1)
1、设置服务器的时间:
linux查看时间和修改时间的命令:
date :查看当前时间;
date –s 2014-04-26:设置日期;
date -s 09:38:40 :设置当前时间
2、设置ntp.conf配置文件
以root用户登录,修改或增加以下配置内容
[root@test1 ~]# vi /etc/ntp.conf
restrict default ignore # 增加或修改此项配置
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 去掉原有注释,修改相应的restrict和mask地址
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap # 多个网段的同步设置
server 127.127.1.0 # local clock # 去掉原有注释
fudge 127.127.1.0 stratum 10 # 去掉原有注释
3、启动ntp服务
[root@test241 ~]# service ntpd start
服务启动后,要等一定的时间(如:五分钟)后,客户端才能正常访问。
#查看udp端口,确保该端口以udp方式开放
[root@test1 ~]# netstat -an |grep 123
三、时间客户端配置(192.168.1.2)
1、直接同步时间:
[root@test2 ~]# /usr/sbin/ntpdate 192.168.1.1
2、可以用计划任务同步的方式,来实现时间同步
[root@test2 ~]# crontab –e
0-59/10 * * * * /usr/sbin/ntpdate 192.168.1.1 #表示每隔10分钟同步一次时间