Linux配置ntp时间服务器

版权声明:转载请注明出处! https://blog.csdn.net/ywd1992/article/details/82115406

一、基础环境

1、操作系统:CentOS 7.3

2、ntp:4.2.6

3、机器,服务端(192.168.0.101)客户端(192.168.0.102)

二、安装ntp

yum -y install ntp

三、服务端配置(192.168.0.101)

vim /etc/ntp.conf

restrict 192.168.0.101 nomodify notrap nopeer noquery          //当前节点IP地址
restrict 192.168.0.2 mask 255.255.255.0 nomodify notrap      //集群所在网段的网关(Gateway),子网掩码(Genmask)

# 在server部分添加以下部分,并注释掉server 0 ~ n
server 127.127.1.0
fudge 127.127.1.0 stratum 10

四、客户端配置(192.168.0.102)

vim /etc/ntp.conf

restrict 192.168.0.102 nomodify notrap nopeer noquery          //当前节点IP地址
restrict 192.168.0.2 mask 255.255.255.0 nomodify notrap      //集群所在网段的网关(Gateway),子网掩码(Genmask)

# 在server部分添加如下语句,将server指向主节点。
server 192.168.0.102
fudge 192.168.0.102 stratum 10

五、验证并配置定时任务

1、验证

分开开启服务端及客户端的ntp服务,并配置开机自启

service ntpd start
chkconfig ntpd on

客户端运行如下命令,与服务端实现同步

ntpdate -u 192.168.0.101

2、配置定时任务

我们可以在客户端配置crontab定时任务使客户端每隔一段时间自动与服务器端同步时间,如,在每星期一的晚上十点同步一次时间

crontab -e

00 22 * * 1 ntpdate -u 192.168.0.101

猜你喜欢

转载自blog.csdn.net/ywd1992/article/details/82115406