Linux 多服务器时间同步设置

目录

一、配置时间服务器具体步骤

二、其他机器配置(必须root用户)

找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,比如,每隔十分钟,同步一次时间。

一、配置时间服务器具体步骤



【1】检查 ntpNTP是网络时间同步协议,就是用来同步网络中各个计算机的时间的协议) 是否安装,时间服务器配置必须使用 root 用户。如果与下面展示的结果不同,则使用 yum install ntp 进行安装。或者 yum install fontpackages-filesystem.noarch,所以需要同步的服务器都需要进行安装检查

[root@hadoop1 hadoop-2.7.2]# rpm -qa|grep ntp
ntpdate-4.2.6p5-29.el7.centos.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
ntp-4.2.6p5-29.el7.centos.x86_64

【2】修改 ntp 配置文件

[root@hadoop1 hadoop-2.7.2]# vim /etc/ntp.conf 

【3】将下面代码前的注释去掉。表示授权 192.168.x.0-192.168.x.255 网段上的所有机器可以从这台机器上查询和同步时间。

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

【4】集群在局域网中,不使用其他互联网上的时间,所以注释掉如下配置。

#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

【5】当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步。

server 127.127.1.0
fudge 127.127.1.0 stratum 10

【6】修改 /etc/sysconfig/ntpd 文件

[root@hadoop1 hadoop-2.7.2]# vim /etc/sysconfig/ntpd

【7】增加内容如下(让硬件时间与系统时间一起同步)

SYNC_HWCLOCK=yes

【8】重新启动 ntpd服务

#查看服务状态
service ntpd status
#启动
service ntpd start
#停止
service ntpd stop

【9】设置 ntpd服务开机启动

chkconfig ntpd on

二、其他机器配置(必须root用户)


【1】在其他机器配置 10分钟与时间服务器同步一次。使用定时任务crontab

crontab 命令选项基本只有对用户操作的选项:
-u 指定一个用户
-l 列出某个用户的任务计划
-r 删除某个用户的任务
-e 编辑某个用户的任务

[root@localhost hadoop-2.7.2]# crontab -e

【2】编写定时任务类容如下:分 时 天 月 星期

*/10 * * * * /usr/sbin/ntpdate hadoop1

【3】修改任意机器时间

[root@localhost hadoop-2.7.2]# date -s "2019-9-11 12:12:11"

【4】十分钟后查看机器是否与时间服务器同步

[root@localhost hadoop-2.7.2]# date


----架构师资料,观众公众号获取----

猜你喜欢

转载自blog.csdn.net/zhengzhaoyang122/article/details/106902967