Linux教程

linux下安装zookeeper-3.6.1并解决启动报错问题

本文主要是介绍linux下安装zookeeper-3.6.1并解决启动报错问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

linux下安装Zookeeper

单机版

①创建安装目录

mkdir -p /usr/local/zookeeper

②将tar包解决到安装目录下

tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper/

③创建数据目录data,日志目录log

mkdir -p /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/data mkdir -p /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/log

④修改配置文件(conf目录),默认启动配置文件为zoo.cfg

(复制zoo_sample.cfg一份修改名称为zoo.cfg)

# 进入配置文件
cd /user/local/zookeeper/apache-zookeeper-3.6.1-bin/conf/
# zookeeper 启动默认加载名为 zoo.cfg的配置文件,所以复制一份命名为 zoo.cfg
cp zoo_sample.cfg zoo.cfg
# 修改配置文件
vim zoo.cfg

⑤配置dataDir和dataLogdir

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/usr/local/zookeeper/apache-zookeeper-3.6.1-bin/data
dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.6.1-bin/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers

在bin目录下启动zookeeper

./zkServer.sh start

  • 可以直接通过bin目录下的zkcli.sh进行连接

    ./zkCli.sh

    下图为连接成功
    在这里插入图片描述

客户端连接成功后可以进行的操作指令

  • ls /

在这里插入图片描述

集群版

创建解压目录

①先创建一个目录

mkdir -p /usr/local/zookeeper/zk1

②将文件解压到该目录

tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper/zk1/

③创建data目录和log目录,data目录下添加myid文件,myid中只写一个1就行

mkdir /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data

mkdir /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/log

cd /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data

vim myid

  • 复制zoo_sample.cfg,并将文件重命名为zoo.cfg

    cp zoo_sample.cfg zoo.cfg
    在这里插入图片描述

  • 修改zk1配置的zoo.cfg

    vim zoo.cfg

    dataDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data
    dataLogDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/log
    
    
    # 集群配置
    # server.1中的1是myid文件中的内容,2888,2889,2890用于集群内部通信,3888,3889,3890用于选择leader
    server.1=192.168.152.100:2888:3888
    server.2=192.168.152.100:2889:3889
    server.3=192.168.152.100:2890:3890
    
    

    在这里插入图片描述

  • 将zk1文件夹复制两份为zk2/zk3

    cd /usr/local/zookeeper/

    cp -Rf zk1/ zk2

    cp -Rf zk1/ zk3

  • 修改zk2的配置文件zoo.cfg

    dataDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/data
    dataLogDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/log
    
    clientPort=2182
    

    修改zk2中data目录下的myid文件 —把1改成2

    cd /usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/data

    vim myid

    把1改成2 (同理在zk3中把myid改成3)

    • 注意:这里的myid和配置文件中有关
      在这里插入图片描述

      如果没有改可能会出现以下错误

在这里插入图片描述

  • 修改zk3的配置文件zoo.cfg(和zk2相似)

    dataDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.1-bin/data
    dataLogDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.1-bin/log
    
    clientPort=2183
    
  • 启动

    注意:这里需要把三台**全部启动,再查看状态**

      	原因:涉及到Leader(Master)选举的问题
    
    cd /usr/local/zookeeper/
    
    zk1/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
    
    zk2/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
    
    zk3/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
    

在这里插入图片描述

  • 查看状态

    cd /usr/local/zookeeper/
    
    zk1/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status
    
    zk2/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status
    
    zk3/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status
    

在这里插入图片描述

这篇关于linux下安装zookeeper-3.6.1并解决启动报错问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!