ntp时间服务器搭建详解

NTP时间服务器介绍

	NTP 服务器是用于局域网服务器时间同步使用的,可以保证局域

网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时
性要求高的必须统一时间。

免费的时间服务器

	 复旦大学免费NTP:"ntp.fudan.edu.cn
	 阿里云免费NTP:"ntp1.aliyun.com

开始搭建

1.本地防火墙开启123端口
NTP 服务器监听端口为 UDP 的 123,那就需要在本地防火墙开启
运行客户端访问 123 端口,进入vi /etc/sysconfig/iptables 添加如下规则:
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

搭建ntp服务端

1.yum安装ntp
yum install ntp ntpdate -y

2.配置ntp.conf配置文件
#备份源配置文件
cp /etc/ntp.conf.bak

#编辑ntp.conf配置文件
进入:vi /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 -6 ::1
server 127.127.1.0 # local clock
server ntp3.aliyun.com #阿里云时间服务器
fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
在这里插入图片描述
启动/关闭/重启-ntp服务/查看其状态
在这里插入图片描述
(注意*: ntpd 启动后,客户机要等几分钟再与其进行时间同步,否
则会提示“no server suitable for synchronization found”错误。)

搭建ntp时间同步机(客户机)

1.安装ntp服务

yum install ntp ntpdate -y

2.测试

#查看当前时间
[root@bogon ~]# date
Tue Oct  8 01:02:05 PDT 2019
#修改机器时间
[root@bogon ~]# date -s "20120523 01:01:01"
Wed May 23 01:01:01 PDT 2012
#同步服务端时间
[root@bogon ~]# ntpdate 192.168.150.151
 8 Oct 00:33:35 ntpdate[21750]: step time server 192.168.150.151 offset 232759902.686916 sec
 #再次查看。。。

3.添加定时任务

#注意:修改192.168.150.151为自己服务端的ip
[root@bogon ~]# crontab -e
0  0   *  *  * /usr/sbin/ntpdate  192.168.150.151>>/data/logs/ntp.log 2>&1
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/tmp/crontab.APhwqJ" 1L, 75C

在这里插入图片描述

参考自:https://blog.csdn.net/qq_34672033/article/details/87821694#NTP_1

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

像夏天一样热

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

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

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

打赏作者

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

抵扣说明:

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

余额充值