• 模拟 Zookeeper 某节点宕机后修复工作


    说明

    不可避免的,zookeeper集群出现某个节点由于各种原因导致服务挂了,那么此时就需要进行对该节点的修复工作,那么下面开始介绍;

    本次的操作是基于前一篇的 CentOS 7 Zookeeper 介绍 及 集群安装

    模拟 leader 宕机后,恢复zookeeper服务后重新加入到集群中。

    模拟宕机

    在当前集群中,leader节点为 node03,那么直接手动停止服务后,直接删除服务的所有文件;

    [root@node03 zookeeper_cluster]# /opt/zookeeper_cluster/bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Mode: leader
    # 这里能看到当前是leader
    [root@node03 zookeeper_cluster]# /opt/zookeeper_cluster/bin/zkServer.sh stop
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
    [root@node03 zookeeper_cluster]# /opt/zookeeper_cluster/bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Error contacting service. It is probably not running.
    # 这里已经提醒不在运行
    

    下面删除服务文件

    [root@node03 ~]# ls -ld /opt/zookeeper*
    drwxr-xr-x 12 root root 4096 Mar  1 01:02 /opt/zookeeper-3.4.13
    lrwxrwxrwx  1 root root   21 Mar  1 00:50 /opt/zookeeper_cluster -> /opt/zookeeper-3.4.13
    [root@node03 ~]# rm -rf /opt/zookeeper*
    

    恢复

    服务安装

    cd /opt/soft/
    
    tar xf zookeeper-3.4.13.tar.gz 
    
    mv zookeeper-3.4.13 /opt/
    
    ln -s /opt/zookeeper-3.4.13 /opt/zookeeper_cluster
    
    ls -ld /opt/zookeeper*
    
    # drwxr-xr-x 10  501 games 4096 Jul  1  2018 /opt/zookeeper-3.4.13
    # lrwxrwxrwx  1 root root    21 Mar  1 00:50 /opt/zookeeper_cluster -> /opt/zookeeper-3.4.13
    

    服务配置

    这里只操作node03

    mkdir /opt/zookeeper_cluster/{data,logs}
    
    echo "3" > /opt/zookeeper_cluster/data/myid
    
    cd /opt/zookeeper_cluster/conf/
    
    cat > zoo.cfg <<EOF
    tickTime=2000
    initLimit=10
    syncLimit=5
    dataLogDir=/opt/zookeeper_cluster/logs
    dataDir=/opt/zookeeper_cluster/data
    clientPort=2181
    autopurge.snapRetainCount=500
    autopurge.purgeInterval=24
    server.1=172.16.1.11:2888:3888
    server.2=172.16.1.12:2888:3888
    server.3=172.16.1.13:2888:3888
    EOF
    

    启动测试

    [root@node03 conf]# /opt/zookeeper_cluster/bin/zkServer.sh start
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    [root@node03 conf]# /opt/zookeeper_cluster/bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Mode: follower
    # 这里提示,已经加入到集群中
    

    此时再次查看其它两台 状态,发现node01 现在是leader

    [root@node01 zookeeper_cluster]# /opt/zookeeper_cluster/bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper_cluster/bin/../conf/zoo.cfg
    Mode: leader
    
  • 相关阅读:
    保护模式下通过写显存在屏幕上输出字符串
    Linux0.01 引导代码分析-head.s
    OpenGL Super Bible 第四章 Transform 程序绘图部分代码解析
    Ubuntu10.04 下编译 OpenOffice DEV300 分支
    今天把博客开通了,欢迎来访!
    沟通的工具ER图
    为什么博客叫秋水?
    mysql.基础笔记
    如何阅读别人的C代码
    Github搜索与查看
  • 原文地址:https://www.cnblogs.com/winstom/p/12387687.html
Copyright © 2020-2023  润新知