ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux - 服务器 集群配置时间同步的步骤

linux - 服务器 集群配置时间同步的步骤

Linux操作系统 作者:元亨利贞 时间:2023-08-26 22:01:39 0 删除 编辑

前提

如果服务器在公网环境(能连接外网),可以不采用集群时间同步,因为服务器会定期和公网时间进行校准。

安装和配置ntp服务

如果没有ntp服务,可以使用yum install ntp或者apt-get install ntp命令来安装ntp服务。

时间服务器配置(必须root用户)

(1)查看所有节点ntpd服务状态和开机自启动状态

sudo systemctl status ntpd
sudo systemctl start ntpd
sudo systemctl is-enabled ntpd

(2)修改hadoop102的ntp.conf配置文件

sudo vim /etc/ntp.conf

(a)修改1(授权192.168.10.0-192.168.10.255网段上的所有机器可以从这台机器上查询和同步时间)

#restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
为restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

(b)修改2(集群在局域网中,不使用其他互联网上的时间)

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
为
#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

(c)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)

server 127.127.1.0
fudge 127.127.1.0 stratum 10

(3)修改服务器的/etc/sysconfig/ntpd 文件

sudo vim /etc/sysconfig/ntpd

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

SYNC_HWCLOCK=yes

(4)重新启动ntpd服务

sudo systemctl start ntpd

(5)设置ntpd服务开机启动

sudo systemctl enable ntpd

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

(1)关闭所有节点上ntp服务和自启动

sudo systemctl stop ntpd
sudo systemctl disable ntpd
sudo systemctl stop ntpd
sudo systemctl disable ntpd

(2)在其他机器配置1分钟与时间服务器同步一次

sudo crontab -e

编写定时任务如下:

*/1 * * * * /usr/sbin/ntpdate ip














来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70024433/viewspace-2978501/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: hadoop 常用端口号
请登录后发表评论 登录
全部评论

注册时间:2022-11-21

  • 博文量
    383
  • 访问量
    247965