Zookeeper安装集群配置
Posted zqq_hello_world
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper安装集群配置相关的知识,希望对你有一定的参考价值。
文章目录
Zookeeper安装
官网下载地址:https://zookeeper.apache.org/releases.html
-
Linux服务器wget命令下载:
windows直接解压设置配置文件然后运行
#版本号去官网选择自己下载的版本,本地电脑下载再上传也可,随便 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9-bin.tar.gz #未安装wget,yum安装 yum install wget -y
#tar命令解压 tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz
-
编辑配置文件
到解压出来zookeeper目录下的conf目录下,创建配置文件zoo.cfg
#复制zookeeper提供的配置文件样例,改为正确的配置文件名称 cp zoo_sample.cfg zoo.cfg
配置文件中指定数据存储目录和日志目录(不指定用默认的建议指定)
#数据存储目录 dataDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/data #日志目录 dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/logs #zookeeper提供了自动清理事务日志和快照文件的功能,指定频率,单位小时,1小时 autopurge.snapRetainCount=1
-
启动zookeeper
zookkeeper安装目录bin目录下执行命令
#bin目录下执行 ./zkServer.sh start #查看zookeeper状态 ./zkServer.sh status #停止zookeeper ./zkServer.sh stop #重启zookeeper ./zkServer.sh restart
Zookeeper集群
-
添加myid配置,设置集群中每个服务器的ID
在zookeeper的data目录下创建一个myid的文件记录服务器的id,内容为1表示这个zookeeper服务器id为1(每个都创建不要重复)
# >的意思是将输出的内容不输出到控制台输出到文件,文件不存在自动创建,一个>是覆盖内容,两个>>是追加内容,每个服务唯一 echo 1 > myid
-
配置文件中添加集群结点信息
确保用到的端口打开或者关闭防火墙
#增加集群配置,最好奇数集群 #server.服务器ID=服务器IP地址:服务器之间通信端口:服务器直接投票选举端口 server.1=server.ip:server.port1:server.port2 server.2=server.ip:server.port1:server.port2
查看集群效果Leader,显示 Mode: leader
ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/apache-zookeeper-3.5.9-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: leader
Zookeeper配置文件
# 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.5.9-bin/data
dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-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
server.1=192.168.136.133:2888:3888
server.2=192.168.136.132:2888:3888
#
# 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
以上是关于Zookeeper安装集群配置的主要内容,如果未能解决你的问题,请参考以下文章
Zookeeper 2Zookeeper的安装和配置(集群模式)