Zookeeper 从入门到精通Zookeeper 下载安装及配置
Posted 思想累积
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于Zookeeper 从入门到精通Zookeeper 下载安装及配置的主要内容,如果未能解决你的问题,请参考以下文章
《黑马ZooKeeper教程(ZooKeeper框架入门到精通)》