zookeeper 集群搭建

该文章详细描述了如何在三台CentOS7.6系统的设备上配置Zookeeper集群,包括设置主机名、主机名与IP地址解析、SSH免密登录、配置Java环境变量、修改Zookeeper配置文件如dataDir和myid,以及创建启动、停止和检查状态的集群脚本。
摘要由CSDN通过智能技术生成

1、准备三台设备

主机名系统IP地址
worker1Centos7.6192.168.1.115
worker2Centos7.6192.168.1.116
worker3Centos7.6192.168.1.117

2、主机名配置

hostnamectl set-hostname worker1

hostnamectl set-hostname worker2

hostnamectl set-hostname worker3

3、主机名与IP地址解析

vi /etc/hosts 添加

192.168.1.115 worker1
192.168.1.116 worker2
192.168.1.117 worker3

4、配置有ssh服务,可以进行免密登录

ssh-key密钥认证

 连接

for i in 115 116 117; do ssh-copy-id 192.168.1.$i; done

 测试

ssh worker2

5、编辑环境变量

 vim /etc/profile

export JAVA_HOME=/usr/local/jdk-11.0.18
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

配置生效

source /etc/profile

6、修改zookeeper 配置文件

cd zookeeper/conf

[root@hadoop1 conf]# cp zoo_sample.cfg zoo.cfg
 

vim  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=/opt/module/zookeeper/data
dataLogDir=/opt/module/zookeeper/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.
#
# https://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
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=worker1:2888:3888
server.2=worker2:2888:3888
server.3=worker3:2888:3888
 

修改dataDir

dataDir=/opt/module/zookeeper/data
进入data目录

生成myid文件,指定myid服务号

echo "1" > myid
其他节点的同样操作

myid唯一

7、zookeeper集群的脚本

zkEnv.sh里添加JAVA_HOME

脚本 zk.sh

#!/bin/bash
case $1 in
"start"){
        for i in worker1 worker2 worker3
        do
                 echo -------------------------------- $i zookeeper 启动 ---------------------------
                ssh $i "/opt/module/zookeeper/bin/zkServer.sh start"
        done
}
;;
"stop"){
        for i in worker1 worker2 worker3
        do
                echo -------------------------------- $i zookeeper 停止 ---------------------------
                ssh $i "/opt/module/zookeeper/bin/zkServer.sh stop"
        done
}
;;
"status"){
        for i in worker1 worker2 worker3
        do
                echo -------------------------------- $i zookeeper 状态 ---------------------------
                ssh $i "/opt/module/zookeeper/bin/zkServer.sh status"
        done
}
;;
esac
 

8、启动集群

./zk.sh start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值