Zookeeper的下载安装

 

很多服务器都不建议安装在windows上,安装在windows上容易报乱七八糟的错。

 

1、下载ZK,上传到Linux,移到/usr/local下,解压

mv apache-zookeeper-3.6.0-bin.tar.gz /usr/local/

cd /usr/local/

tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz

rm apache-zookeeper-3.6.0-bin.tar.gz

我们看到解压目录的lib下有很多jar包,zk依赖jdk,没有安装、配置jdk的需要先安装jdk,并配置jdk的环境变量。

 

 

 

 2、将conf/zoo_sample.cfg复制为zoo.cfg,并修改zk的数据存储位置

启动zk时会默认加载conf/zoo.cfg,zoo_sample.cfg是官方提供的配置模板。

#将zoo_sample.cfg复制一份,重命名为zoo.cfg
cp conf/zoo_sample.cfg conf/zoo.cfg


#在解压目录下新建目录data
mkdir data


#data下新建文件myid
touch data/myid
#编辑myid,写一个1。myid在zkServer集群中才有用,单机版zkServer可以不配置
vim data/myid


vim conf/zoo.cfg

 

 

 

 

其它使用默认配置即可。介绍一下配置项

# The number of milliseconds of each tick
tickTime=2000  #心跳间隔,每隔2000ms即2s发送一次心跳
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10  #10*2s=20s,如果连续10次即20s内没有收到某个服务节点的心跳,就认为该节点挂掉了
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5  #follower从leader同步数据时,发送同步请求后,如果5个心跳时间即10s内没有收到leader的确认应答,就认为本次同步请求失败
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#dataDir=/tmp/zookeeper
dataDir=/usr/local/apache-zookeeper-3.6.0-bin/data  #数据存储位置
# the port at which the clients will connect
clientPort=2181  #zk client与zk server通信使用的端口号
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60  #zk client的最大数量

 

 

 

3、防火墙开放指定端口给zk client连接

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

firewall
-cmd --reload

 

 

 

4、启动zk server

windows、linux的zk安装包都是同一个,bin下面的.cmd文件是windows上用的,.sh文件是linux用的。

.cmd不需要,可以删掉。执行bin/zkServer.sh启动ZK。

cd bin

rm *.cmd

./zkServer.sh start

注意zkServer的S是大写,要带上后缀.sh

 

看到started的说明zk server已经启动了

 

 

zk server常用的参数

start  #启动

stop  #停止

restart  #重启

status  #查看状态

version  #查看zk server的版本

注意:这些参数前面不带短横。

查看参数可以用文本编辑器打开脚本,查看源代码;也可以./zkServer.sh  --help,help可以带2根短横、1根短横。

 

 

 

5、连接zk server

此时启动bin/zkCli.sh可连接到zk server,zkCli.sh是zk自带的客户端

./zkCli -server 192.168.1.9:2181

因为zk server就在本地,ip写127.0.0.1也行

 看到打印的信息中有   就说明连接上了。

 

posted @ 2019-06-25 20:55  chy_18883701161  阅读(3432)  评论(0编辑  收藏  举报