linux时间同步

linux两台服务器之间的时间同步(使用ntp)

安装使用这个https://blog.csdn.net/Hubert_27/article/details/130248070

同步使用这个https://blog.csdn.net/weixin_40122615/article/details/101194556

安装:

1、查询是否已安装NTP服务

rpm -qa | grep ntp

ntpdate-4.2.6p5-1.el6.centos.x86_64

ntp-4.2.6p5-1.el6.centos.x86_64

有以上两个包则证明已经安装NTP服务,如果仅有一个,建议卸载后重新安装。使用rpm -e xxx命令卸载。

2、在线安装

执行命令

yum install -y ntp

3、离线安装

对于无外网的用户,可以登录https://pkgs.org/download/ntp,下载安装包。

ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm

ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm

上传服务器后,安装,注意有先后顺序。

rpm -ivh ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm

rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm

1、参数配置

配置文件在/etc/ntp.conf

vim /etc/ntp.conf

找一台公共ntp时间服务器,如ntp.aliyun.com。或配置一台服务器作为主节点(将下面出现的ntp.aliyun.com替换为主节点IP)。

主节点配置

server 127.0.0.1

fudge 127.0.0.1 stratum 10

客户端配置

#server地址为公共NTP服务器或自己搭建的NTP主节点

server ntp.aliyun.com

#注释掉以下server

#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

2、启动

#启动ntpd服务

service ntpd start

#开机启动ntpd

chkconfig ntpd on

查看NTP状态

ntpstat

synchronised to NTP server (ntp.aliyun.com) at stratum 12

time correct to within 956 ms

polling server every 64 s

若出现以上结果,证明时间同步成功。

时钟同步的方式有两种:第一种同步方式通过网络进行时钟同步,第二种方式通过某台机器进行同步。

本文将以第二种方式介绍三台机器之间的时间同步具体的操作步骤:

本文是以centos6.5作为服务器搭建的三台机器Hadoop伪分布式的平台,解决三台机器之间的时间同步的问题,主机master的IP为192.168.141.130,从机slave01的IP为192.168.141.140,从机slave02的IP为192.168.141.150,以主机master服务器的时间为准,两台从机同步主机的时间,以达到三台机器时间同步的目的。

第四步:两台从机设置定时任务与主机时间同步
  1. crontab -e

  2. */1 * * * * /usr/sbin/ntpdate 192.168.141.130

第五步:date命令查看三台机器的时间是否同步
相关推荐
七夜zippoe21 分钟前
Nexent Linux 部署:用 deploy.sh
linux·服务器·docker·部署·ai智能体·nexent
去码头整点薯条9833 分钟前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬1 小时前
第一章 初识Linux shell
linux·运维·服务器
拂拉氏2 小时前
【知识讲解】 Linux线程中锁的认识
linux·互斥锁
无足鸟ICT2 小时前
【RHCA+】系统调优配置文件
linux·服务器
饿了吃洗衣凝珠2 小时前
DNS域名解析服务器
运维·服务器
布莱克6053 小时前
Swift 字符串详解:从基础用法到性能与最佳实践
服务器·开发语言·ssh·字符串·swift
新*3 小时前
Elasticsearch 索引别名入门:创建、路由、原子切换与几个常见误解
运维·后端·elasticsearch·索引别名
时间的拾荒人3 小时前
Shell 脚本核心语法详解(下篇):流程控制、函数、重定向与文件包含
linux·运维·服务器·bash·脚本编程
饿了吃洗衣凝珠4 小时前
SELinux
服务器·开发语言·php