Zookeeper 从入门到精通(二)Zookeeper 下载安装及配置

1、Zookeeper 下载安装

zookeeper 官网:https://zookeeper.apache.org/

zookeeper 下载地址:https://downloads.apache.org/zookeeper/

1、下载最新的安装包

在这里插入图片描述
2、上传下载好的安装包到 /home/zookeeper/ 目录下

3、执行 tar -zxvf /home/zookeeper/apache-zookeeper-3.7.0-bin.tar.gz 解压安装包

4、进入到解压好的目录中创建 data 和 logs 文件夹

cd /home/zookeeper/apache-zookeeper-3.7.0-bin/

mkdir data

mkdir logs

5、进入 conf 文件夹,拷贝一份配置文件并进行修改

cd 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=/home/zookeeper/apache-zookeeper-3.7.0-bin/data/
dataLogDir=/home/zookeeper/apache-zookeeper-3.7.0-bin/logs
# 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
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

6、配置环境变量

vim /etc/profile

export ZOOKEEPER_HOME=/home/zookeeper/apache-zookeeper-3.7.0/
export PATH=$ZOOKEEPER_HOME/bin:$PATH

执行命令使 profile 文件生效

source /etc/profile

7、防火墙添加 zookeeper 访问端口

firewall-cmd --zone=public --add-port=2181/tcp --permanent

重启防火墙

systemctl restart friewalld.service

8、启动 zookeeper 服务并测试是否正常启动

cd /home/zookeeper/apache-zookeeper-3.7.0-bin/bin/

./zkServer.sh start

在这里插入图片描述

关闭 zookeeper

./zkServer.sh stop

在这里插入图片描述
如果 8080 端口被占用可能启动不成功,改变端口在配置文件中加入下面的配置

admin.serverPort=端口号

2、Zookeeper 配置参数

#The number of milliseconds of each tick
# 每次心跳时间间隔	2s
tickTime=2000

# The number of ticks that the initial 
# synchronization phase can take
# 初始化心跳次数:leader 和 follower 联系时长 initLimit * tickTime
initLimit=10

# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
# 发送请求到接收响应 5 次心跳
syncLimit=5

# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# 存储数据的地方
dataDir=/home/zookeeper/apache-zookeeper-3.7.0-bin/data/
dataLogDir=/home/zookeeper/apache-zookeeper-3.7.0-bin/logs

# 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
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

3、Zookeeper 分布式安装

集群模式下需要配置一个文件 myid,这个文件在 dataDir 目录下,文件中数据是 number的值,Zookeeper 启动时读取该文件,得到里面的数据与 zoo.cfg 配置文件信息比较判断哪个是 server

配置 zoo.cfg 文件,增加如下配置

# server.1=192.168.0.9:2888:3888
# number:服务器编号,与 myid 中一致
# IP:当前服务器 IP 地址
# 第一个 port 是服务器与集群中的 leader 服务器交换信息的端口
# 第二个是进行选举服务器时通信的端口
server.number=IP:port:port
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一起来搬砖呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值