• 安装 ZooKeeper 并配置服务


    官网

    1. 访问官方下载页面
    2. 安装
    # 注意替换一下新的链接
    curl -sSLO https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
    tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt/
    cd /opt
    ln -s zookeeper-3.4.10 ./zookeeper
    
    cd zookeeper
    mkdir data
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    User

    Create a zookeeper user

    groupadd zookeeper
    useradd -g zookeeper -d /opt/zookeeper -s /sbin/nologin zookeeper
    
    • 1
    • 2

    Set the permissions:

    chown -R zookeeper:zookeeper /opt/zookeeper/*
    
    • 1

    Config

    vi /opt/zookeeper/conf/zoo.cfg
    
    • 1

    Add the following:

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/data
    clientPort=2181
    server.1=192.168.187.75:2888:3888
    server.2=192.168.187.77:2888:3888
    server.3=192.168.187.78:2888:3888
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    Test the service:

    /opt/zookeeper/bin/zkServer.sh start
    
    • 1

    Ctrl-c out of that and lets create a systemd unit file for the service.

    Systemd

    vi /usr/lib/systemd/system/zookeeper.service
    
    • 1

    Add the following:

    [Unit]
    Description=Zookeeper Service
    
    [Service]
    Type=simple
    WorkingDirectory=/opt/zookeeper/
    PIDFile=/opt/zookeeper/data/zookeeper_server.pid
    SyslogIdentifier=zookeeper
    User=zookeeper
    Group=zookeeper
    ExecStart=/opt/zookeeper/bin/zkServer.sh start
    ExecStop=/opt/zookeeper/bin/zkServer.sh stop
    Restart=always
    TimeoutSec=20
    SuccessExitStatus=130 143
    
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    Systemd 配置文件

    Systemd 的 unit 的配置文件位置 (redhat系): /usr/lib/systemd/system/

    Systemd服务主要内容为:控制单元[unit]的定义、服务[service]的定义、安装[install]部分

    1. 控制单元 [Unit]:记录unit文件的通用信息
      1. Description:单元的描述,内容可以任意书写,
    2. 服务 [Service]:记录service的信息
      1. Type:service的种类,
        1. simple (默认): 启动的程序是主体程序,这个程序退出那么一切都退出
        2. forking: 标准 Unix Daemon 使用的启动方式。启动程序后会调用 fork() 函数,把必要的通信频道都设置好之后父进程退出,留下守护精灵的子进程
        3. oneshot: 仅启动,完成,没进程
      2. ExecStart: 服务启动时执行的命令,通常是服务的主体。若服务类型不是oneshot,那么它只接受一个命令,参数不限制。如果是多个命令用分号 ; 隔开
      3. Restart: 定义服务何种情况下重启
    3. 安装 [Install]: 安装信息
      1. WantedBy: 任何情况下, 服务被启用
        2. WantedBy=multi-user.target 多用户环境下启用
    Restart

    Restart=always: 只要不是通过systemctl stop来停止服务,任何情况下都必须要重启服务,默认值为no
    RestartSec=5: 重启间隔,比如某次异常后,等待5(s)再进行启动,默认值0.1(s)
    StartLimitInterval: 无限次重启,默认是10秒内如果重启超过5次则不再重启,设置为0表示不限次数重启

    Next

    systemctl daemon-reload # 重新加载服务配置文件
    systemctl enable zookeeper.service
    systemctl start zookeeper.service
    
    • 1
    • 2
    • 3

    SystemCtl

    systemctl --help  # 查看帮助
    
    # enable 是在  /etc/systemd/system/multi-user.target.wants/  这个目录下 做 unit 配置文件的软链
    systemctl enable | disable | is-enabled | status | is-active unit
    systemctl get-default | set-default graphical.target | multi-user.target  # islate 在线切换模式  
    
    • 1
    • 2
    • 3
    • 4
    • 5

    Test

    Running the following will give a client interface to the zookeeper service:

    /opt/zookeeper/bin/zkCli.sh
    
    • 1

    There are some examples here but you can create and get info as shown below:

    在这里插入图片描述

    To check which nodes are followers and which is the leader try issuing the following commands to each node:

    echo srvr | nc localhost 2181
    
    • 1

    Troubleshooting

    • Reset the user permissions on the /opt/zookeeper directory recursively
    • Switch off firewalld and/or check a telnet connect to port 2181 on each node
    • Try switching to the zookeeper user (su – zookeeper -s /bin/bash) and run the zkServer.sh start command

    Reference

    https://zookeeper.apache.org/releases.html
    https://blog.redbranch.net/2018/04/19/zookeeper-install-on-centos-7/

  • 相关阅读:
    简历的项目经历,测试人员书写要注意的几个问题
    机器人控制器编程实践指导书旧版-实践六 LCD液晶显示(点阵)
    【MySQL】21-MySQL之增删改
    (附源码)spring boot企业网站设计与实现 毕业设计 211750
    selenium源码通读·9 |DesiredCapabilities类分析
    【IoT】从马斯克造火箭到产品开发,快速失败很重要
    Icon闪烁/设定蜂鸣器响的次数
    HTML期末大作业——游戏介绍(HTML+CSS+JavaScript) web前端开发技术 web课程设计网页规划与设计 Web大学生网页成品
    爱数SMART 2022峰会开启,分享数据战略与建设数据驱动型组织方法论
    Linux进程地址空间
  • 原文地址:https://blog.csdn.net/howeres/article/details/126647953