CentOS7 部署 NTP 服务器进行时间同步

一、简介

NTP 是网络时间协议(Network Time Protocol)的简称,就是用来同步网络中各个计算机的时间的协议。

二、安装步骤

1、永久修改主机名称

hostnamectl set-hostname woniu

 2、关闭防火墙

关闭防火墙
systemctl stop firewalld.service
 
禁止开机启动
systemctl disable firewalld.service

3、安装ntp

yum install -y ntp

 4、编辑ntp配置文件

#编辑文件
vi /etc/ntp.conf

#日志配置
logfile /var/log/ntpd.log

#允许网段内客户端连接此服务器同步时间,但是拒绝让他们修改服务器上的时间
restrict 10.0.7.0 mask 10.0.7.255 nomodify notrap

#配置时间服务器(阿里云)
https://www.ntppool.org/zone/asia

server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com

#在 /ntp.conf 中定义的 server 都不可用时,将使用 local 时间作为 ntp 服务提供给 ntp 客户端。
#建议配置,否则 ntp 服务器无法与公网 ntp 服务器同步时,其客户端也会无法同步
server 127.0.0.1
fudge 127.0.0.1 stratum 10

5、同步时间

ntpdate -u ntp1.aliyun.com

6、启动ntp

systemctl start ntpd

7、查看ntp状态

systemctl status ntpd

8、开机自动启动ntp

systemctl enable ntpd

9、客户端配置

#编辑文件
vi /etc/ntp.conf

#日志配置
logfile /var/log/ntpd.log

#配置时间服务器
server 10.0.7.62

#启动ntp
systemctl start ntpd

#开机自动启动
systemctl enable ntpd

三、 检查

1、设置服务器时间

date -s "2018-08-08 08:08:08"

2、把当前系统时间写入到CMOS中

clock -w

3、查看同步状态

ntpstat

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值