ZooKeeper集群安装(附安装报错集)

ZooKeeper集群安装(附安装报错集),第1张

ZooKeeper集群安装(附安装报错集) # ZooKeeper集群安装(附安装报错集)

文章目录

# ZooKeeper集群安装(附安装报错集)前言一、搭建虚拟机二、下载安装包三、安装ZK四、安装过程中遇到的问题随笔


前言

正处于学习中间件过程,当学习到Kafka时,涉及到ZooKeeper集群,故自行安装一遍,以下为安装过程,后续可能也会不定期更新。


一、搭建虚拟机

一般准备三台虚拟机供学习使用,这里以VMware为例。
(每台虚拟机都需安装JDK,这里以1.8为例)

二、下载安装包

https://archive.apache.org/dist/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

三、安装ZK

将安装包上传至/home目录解压

tar -zxvf zookeeper-3.4.10.tar.gz 

在/home目录下创建/data/zookeeper

mkdir -p data/zookeeper/

配置zoo.cfg

cd /home/zookeeper-3.4.10/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
# 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=/home/data/zookeeper
# 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

server.1=192.168.102.129:8880:7770
server.2=192.168.102.130:8880:7770
server.3=192.168.102.131:8880:7770

修改dataDir为/home/data/zookeeper,同时添加zk服务信息为server1、server2、server3。

配置日志目录

mkdir -p /home/zk/zookeeper-3.4.10/log
cd /home/zookeeper-3.4.10/bin
vi zkEnv.sh
#!/usr/bin/env bash
ZOO_LOG_DIR=/home/zookeeper-3.4.10/log

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at

添加ZOO_LOG_DIR=/home/zookeeper-3.4.10/log

分发文件

cd /home
scp -r zookeeper-3.4.10 192.168.102.130:'pwd'
scp -r zookeeper-3.4.10 192.168.102.131:'pwd'

配置myid

cd /home/data/zookeeper/
echo "1" > myid

其余两台服务做同样 *** 作,分别定为

echo "2" > myid
echo "3" > myid

启动zookeeper

cd /home/zookeeper-3.4.10/bin
./zkServer.sh start 或 sh zkServer.sh start

每台机器重复执行以上命令。

测试

cd /home/zookeeper-3.4.10/bin
./zkServer.sh status 或 sh zkServer.sh status

每台机器执行以上命令,若为一个leader,两个follower,则集群正常。

四、安装过程中遇到的问题

Error contacting service. It is probably not running

 该报错说明启动报错,zookeeper.out启动日志查看具体报错

java.net.NoRouteToHostException: 没有到主机的路由

 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state

Cannot open channel to 2 at election address /192.168.102.130:7770

 集群中所有zookeeper服务器zoo.cfg配置文件中dataDir路径是否正确
随笔

xshell多窗口同步 *** 作,View中勾选Compose Bar, 选择To All Sessions,即可在下面的窗口中输入命令,该命令所有窗口同时执行。

接入ZooKeeper客户端

cd /home/zookeeper-3.4.10/bin
./zkCli.sh -server 192.168.102.129:2181


出现以上对话框即为接入成功。

zoo.cfg配置参数含义

tickTime: zookeeper中使用的基本时间单位,毫秒值,比如可以设为1000,那么基本时间单位就是1000ms,也就是1sinitLimit: Follower在启动过程中,会从Leader同步所有最新数据,然后确定自己能够对外服务的起始状态。Leader允许F在 initLimit 时间内完成这个工作。通常情况下,我们不用太在意这个参数的设置。如果ZK集群的数据量确实很大了,F在启动的时候,从Leader上同步数据的时间也会相应变长,因此在这种情况下,有必要适当调大这个参数了。如果该参数设置为5,就说明时间限制为5倍tickTime,即5*1000=5000ms=5ssyncLimit: 在运行过程中,Leader负责与ZK集群中所有机器进行通信,例如通过一些心跳检测机制,来检测机器的存活状态。如果L发出心跳包在syncLimit之后,还没有从F那里收到响应,那么就认为这个F已经不在线了。如果该参数设置为2,说明时间限制为2倍tickTime,即2000msdataDir: 数据目录. 可以是任意目录,一般是节点安装目录下data目录clientPort: 监听client连接的端口号dataLogDir: log目录, 同样可以是任意目录,一般是节点安装目录下的logs目录。如果没有设置该参数,将使用和dataDir相同的设置server.X=hostname:B:C 其中X是一个数字, 表示这是第几号server,它的值和myid文件中的值对应。B是配置该server和集群中的leader交换消息所使用的端口。C配置选举leader时所使用的端口

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5709517.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存