ntp时间同步

作者: Linux丶晨星 | 来源:发表于2019-06-18 16:29 被阅读24次

ntp时间同步

介绍
如果一个集群中,时间相差很大,那么会出现很多诡异的问题,我们也不想在一个无法解决的问题上浪费几天时间吧!总之,设置服务器之间时间同步,为了避免很多问题的发生!

1.准备工作

远程为所有服务器安装ntp服务

yum install ntp

systemctl start ntpd.service
systemctl enable ntpd.service

设置同步为中国时区

timedatectl set-timezone Asia/Shanghai

2. 设置web01为同步外网时间服务器

需要设置允许内网网段可以连接它,将它作为内网的时间同步服务器,所以需要一个简单配置。

vim /etc/ntp.conf

restrict 172.16.1.0 mask 255.255.255.0 #添加此行
表示允许此网段来同步此服务器

server 127.127.1.0
server设置127.127.1.0为其自身


重启ntpd服务,用ntpstat来检查效果
(需要几秒钟就可以看到效果)

[root@web01 ~]# systemctl restart ntpd
[root@web01 ~]# ntpstat 
synchronised to local net at stratum 6 
   time correct to within 7948 ms
   polling server every 64 s

3.在客户端节点上同步server的时间

ntpdate -u 172.16.1.7
-u ===指定使用无特权的端口发送数据包。 当在一个对特权端口的输入流量进行阻拦的防火墙后是很有益的, 并希望在防火墙之外和主机同步。防火墙是一个系统或者计算机,它控制从外网对专用网的访问。

vim /etc/ntp.conf


重启并开机自启动
systemctl start ntpd
systemctl enable ntpd

4.同步server的时间

ntpdate -u 172.16.1.7

[root@web02 ~]# ntpdate -u 172.16.1.7
18 Jun 16:20:06 ntpdate[21259]: adjust time server 172.16.1.7 offset 0.000797 sec

5.书写定时任务

crontab -e
#Ansible: sync time 
*/5 * * * * /sbin/ntpdate -u 172.16.1.7 >/dev/null 2>&1

源文链接:https://blog.csdn.net/chengqiuming/article/details/78735433

用剧本批量分发完成...

相关文章

  • 03-MongoDB集群运维-NTP时间同步

    背景 使用 NTP时间同步操作,避免出现因时间不一致导致集群间数据同步问题 NTP时间同步 测试NTP常用服务器是...

  • linux ntp 同步时间

    文章来自:linux ntp 同步时间,linux ntp时间同步的两种方法[https://blog.csdn....

  • ntp时间同步服务

    ntp时间同步服务 概念 NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各...

  • ntp时间同步

    解决的问题: 保证集群中所有的节点时间一致方案: 需要使用同步软件NTP , 并在主机上开启此服务, 其他节点的...

  • ntp时间同步

    检查是否安装ntpd 安装ntpd 配置ntpd 启动ntpd 查看 查看状态 注意: 这个状态要等上几分钟或者一...

  • ntp时间同步

  • ntp时间同步

    ntp时间同步 介绍如果一个集群中,时间相差很大,那么会出现很多诡异的问题,我们也不想在一个无法解决的问题上浪费几...

  • ntp时间同步

    ntp时间同步 介绍如果一个集群中,时间相差很大,那么会出现很多诡异的问题,我们也不想在一个无法解决的问题上浪费几...

  • ntp 同步时间

  • NTP时间同步

    NTPD服务器Network Time Protocol 作用:为网络中的主机授时,同步的时间在2min-10mi...

网友评论

    本文标题:ntp时间同步

    本文链接:https://www.haomeiwen.com/subject/babfqctx.html