搭建NTP时钟服务器

服务端(172.15.8.223)

#安装软件ntpdate
yum -y install ntp ntpdate

#备份ntp服务器配置文件
cp /etc/ntp.conf /etc/ntp.conf.bak

#精简优化配置文件
egrep -v "^$|#" /etc/ntp.conf.bak >/etc/ntp.conf

修改配置文件

#修改配置文件
[root@m01 ~]# vim /etc/ntp.conf
ftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
#允许内网其他机器同步时间
restrict 172.16.1.0 mask 255.255.255.0 nomodify notr         <--内网网段
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#定义使用的上游 ntp服务器,将原来的注释
server ntp1.aliyun.com iburst
server time1.aliyun.com iburst
#允许上层时间服务器主动修改本机时间
restrict time1.aliyun.com nomodify notrap noquery
restrict ntp1.aliyun.com nomodify notrap noquery
#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

#启动NTP服务和显示节点列表
[root@m01 ~]# systemctl start ntpd
[root@m01 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 120.25.115.20   10.137.53.7      2 u    8   64    1   32.515    2.672   0.000
 203.107.6.88    10.137.38.86     2 u    7   64    1   24.061    4.179   0.000
*LOCAL(0)        .LOCL.          10 l    6   64    1    0.000    0.000   0.000

客户端

客户端有两种方式,一种是通过定时任务,一种也是通过ntp服务

#定时任务 
crontab -e

0 * * * * ntpdate 172.15.8.223

#配置ntpdate服务
##下载
yum -y install ntp ntpdate
##配置
[root@m02 ~]# vim /etc/ntp.conf
server 172.15.8.223 iburst

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值