Zookeeper(一)安装

一、下载zookeeper

在apache的官网下载zookeeper,http://mirrors.cnnic.cn/apache/zookeeper/

当前stable的版本是3.4.6,安装文件zookeeper-3.4.6.tar.gz

二、安装zookeeper

如果安装文件没有执行权限,则执行

chmod +x zookeeper-3.4.6.tar.gz
执行以下命令:

tar -xzvf zookeeper-3.4.6.tar.gz
执行完,会有目录zookeeper-3.4.6

创建zookeeper的data目录,目录看个人而定的,我是创建跟zookeeper-3.4.6同级目录的,

mkdir zkdata
ls
zkdata  zookeeper-3.4.6

接着修改zookeeper的配置文件conf/zoo.cfg

cd zookeeper-3.4.6/conf/; ls
会看到有文件zoo_sample.cfg,复制份zoo.cfg文件出来

cp zoo_sample.cfg zoo.cfg
修改zoo.cfg

vim zoo.cfg
# 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=/tmp/zookeeper
dataDir=/root/zookeeper-a/zkdata

# 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
其中,

dataDir就指向zookeeper存放数据的目录,就是刚才创建的目录zkdata
clientPort=2181,是设定zookeeper的端口

启动zookeeper

cd ../bin/; ls
README.txt    zkCli.cmd  zkEnv.cmd  zkServer.cmd  zookeeper.out
zkCleanup.sh  zkCli.sh   zkEnv.sh   zkServer.sh

其中,

zkServer.sh,启动zookeeper

zkCli.sh,客户端连接zookeeper的程序,后面再讲,

./zkServer.sh start
这样zookeeper就启动了。

如果想停止zookeeper

./zkServer.sh stop
zkServer.sh有以下用法

Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

如果想连接上zookeeper,查看,操作zookeeper,可执行以下命令:

./zkCli.sh -server 127.0.0.1:2181

以上是只有一个zookeeper跑的安装情况,如果有几个zookeeper跑,即分布式部署,下面讲。

假设是安装3个zookeeper,则分别在zookeeper的conf/zoo.cfg后面加上内容:

server.1=192.168.89.100:2888:3888
server.2=192.168.89.101:2888:3888
server.3=192.168.89.102:2888:3888
其中,

server.1,server.2,server.3,中的数字1,2,3分别是100,101,102节点的zookeeper的序号,

在目录zkdata下创建文件myid,并分别设置内容为1,2,3

#100节点
[root@localhost zkdata]# more myid 
1
#101节点
[root@localhost zkdata]# more myid 
2
#102节点
[root@localhost zkdata]# more myid 
3
则分别启动100,101,102 节点就可以了。




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值