NTP时间服务器安装与配置

1.ntp Server端的安装与配置

1.1 安装ntp服务组件

[root@fire ~]# yum install -y ntp ntpdate

1.2 先同步互联网时间

[root@fire ~]# ntpdate 0.cn.pool.ntp.org
#在启动时间服务器前先以时间客户端的身份去互联网的时间服务器进行时间同步,若时间服务器的时间实际和真正的时间差很远,互联网时间服务器是不肯和它同步时间的。

1.3 配置文件

#默认配置
[root@fire ~]# grep -Ev ‘^$|#’ /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery #<==对默认的client拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1 #<==允许本地地址的一切操作
restrict -6 ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

#修改配置
[root@fire ~]# cat /etc/ntp.conf
driftfile /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 192.168.1.0 mask 255.255.255.0 noquery
restrict 192.168.2.0 mask 255.255.255.0 noquery #<==允许局域网内所有client连接到这台服务器
restrict -6 ::1 同步时间.但是拒绝让他们修改服务器上的时间
#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
server 0.cn.pool.ntp.org #<==同步公网的时间
server 127.127.1.0 #<==如果无法连接公网,则使用自己本身的时间作为标准时间。
fudge 127.127.1.0 stratum 10 #<==设置stratum级别
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

1.4 restrict参数

ignore :关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询

1.5 启动服务

[root@fire ~]# /etc/init.d/ntpd start
[root@fire ~]# chkconfig ntpd on

1.6 查看同步情况

[root@fire log]# ntpq -p
在这里插入图片描述
各参数如下:
在这里插入图片描述

2.客户端配置

2.1 安装ntpdate包

[root@lb01 ~]# yum install -y ntpdate

2.2 同步时间,并且设置成定时任务

[root@lb01 ~]# ntpdate fire
24 Aug 09:52:20 ntpdate[1680]: step time server 192.168.2.100 offset -27932.236334 sec
[root@lb01 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate fire &>/dev/null

2.3 将系统时间同步到机器时间

[root@lb01 ~]# hwclock
Mon 24 Aug 2020 06:06:54 PM CST -0.594372 seconds
[root@lb01 ~]# date
Mon Aug 24 10:21:30 CST 2020
[root@lb01 ~]# hwclock -w
#使用hwclock –w命令将系统时间同步到机器时间

[root@lb01 ~]# hwclock
Mon 24 Aug 2020 10:21:42 AM CST -0.579479 seconds

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老哥爱学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值