NTP-时间同步

NTP

概述

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

  • 时间同步的原理:

    • 标准时间:由原子钟报时的国际标准时间UTC(Universal Time Coordinated,世界协调时)

在这里插入图片描述

  • NTP授时网站:http://www.ntp.org.cn/pool

时间同步设定

语法:
ntpdate NTP服务器的IP地址或域名(通过NTP授时网站获取,建议使用域名,因为ip有多个且不稳定)
查看系统时间
[root@server1 ~]# date
2021年 08月 17日 星期二 21:40:41 CST

连接NTP服务器同步时间
[root@server1 ~]# yum install -y ntp
[root@server1 ~]# ntpdate cn.ntp.org.cn
17 Aug 21:45:08 ntpdate[12593]: step time server 120.197.116.202 offset 2.239298 sec

自动同步

[root@server1 ~]# systemctl start ntpd
[root@server1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

ntp服务器搭建

通过外网进行时间同步,需要消耗一定的时间,企业中往往不可取,一般都是自建ntp服务器

设置环境
[root@server1 ~]# hostnamectl set-hostname ntp
[root@server1 ~]# su
[root@ntp ~]# systemctl stop firewall
[root@ntp ~]# systemctl disable firewalld
[root@ntp ~]# setenforce 0
[root@ntp ~]# sed -i 's/enforced/disabled/' /etc/selinux/config
[root@ntp ~]# yum clean all
[root@ntp ~]# yum makecache 

安装
[root@ntp ~]# yum install -y ntp
[root@ntp ~]# vim /etc/ntp.conf 
restrict 127.0.0.1
restrict ::1
restrict 192.168.226.0 mask 255.255.255.0 #添加192.168.226.0网段

同步时间,保证服务器时间准确
[root@ntp ~]# ntpdate cn.ntp.org.cn

启动服务,定期时间同步
[root@ntp ~]# systemctl start ntpd
[root@ntp ~]# systemctl enable ntpd

-------------------------------------------------------------------
客户端手动时间同步
[root@client ~]# ntpdate 192.168.226.10
30 Aug 00:51:21 ntpdate[11789]: step time server 192.168.226.10 offset 709941.283099 sec

定时同步
[root@client ~]# crontab -e
* * * * * /usr/sbin/ntpdate 192.168.226.10 &>/dev/null
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值