Linux下安装Zookeeper教程

ZooKeeper 简介

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。


一、下载 ZooKeeper

官网地址:https://zookeeper.apache.org/releases.html

使用命令下载:

wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

百度网盘下载
提取码:byv7

二、使用步骤

1.安装包解压

将下载好的安装包放到服务器目录下(这里放到soft目录下)

执行命令解压tar -xvzf apache-zookeeper-3.4.6-bin.tar.gz,zip使用unzip命令解压

2.修改配置

执行命令cd apache-zookeeper-3.4.6-bin/conf/,进入conf目录,修改zoo.cfg配置文件如下:


配置说明

配置项说明
tickTime用于计算的时间单元,以毫秒为单位,比如session超时:N*tickTime
initLimit用于集群,允许从节点链接并同步到master节点的初始化连接时间,以tickTime的倍数来表示
syncLimit用于集群,master主节点与从节点之间发送消息,请求和应答时间长度(心跳机制)
clientPort连接服务器的端口,默认是2181
dataDir快照日志目录,存放内存数据库快照的位置,必须配置
dataLogDir事务日志目录,不配置则和dataDir共用

3.启动服务

执行命令 ./zkServer.sh start,成功启动

相关命令 zkServer.sh start|stop|restart|status

ps:安装zookeeper之前,首先确保已经安装好了jdk,因为zookeeper是需要依赖java来进行编译的。

总结

以上就是今天要讲的内容,本文仅仅简单介绍了Linux下安装Zookeeper的步骤,以上方法亲测有效,希望能给大家一个参考。

创作不易,关注💖、点赞👍、收藏🎉就是对作者最大的鼓励👏,欢迎在下方评论留言🧐

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是Linux安装Zookeeper教程: 1. 下载Zookeeper 首先,你需要从官方网站下载Zookeeper的二进制文件。你可以在这里找到最新版本的Zookeeper:https://zookeeper.apache.org/releases.html 2. 解压缩Zookeeper 下载完成后,你需要将Zookeeper解压缩到你的Linux系统中。你可以使用以下命令将Zookeeper解压缩到/opt目录下: ``` tar -zxf zookeeper-3.4.14.tar.gz -C /opt ``` 3. 配置Zookeeper 接下来,你需要配置Zookeeper。你可以在Zookeeper的conf目录下找到一个名为zoo_sample.cfg的示例配置文件。你需要将它复制一份,并将其命名为zoo.cfg: ``` cd /opt/zookeeper-3.4.14/conf cp zoo_sample.cfg zoo.cfg ``` 然后,你需要编辑zoo.cfg文件,以便将Zookeeper配置为使用单个节点模式。你可以使用以下命令打开zoo.cfg文件: ``` vi zoo.cfg ``` 在文件中,你需要找到以下行: ``` # The number of milliseconds of each tick tickTime=200 # 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=/tmp/zookeeper # the port at which the clients will connect clientPort=2181 ``` 你需要将这些行修改为以下内容: ``` # The number of milliseconds of each tick tickTime=200 # The number of ticks that the initial # synchronization phase can take initLimit=5 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=2 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/zookeeper-3.4.14/data # the directory where the transaction log is stored. dataLogDir=/opt/zookeeper-3.4.14/logs # the port at which the clients will connect clientPort=2181 # disable the per-ip limit on the number of connections since this is a single-node setup maxClientCnxns= ``` 4. 启动Zookeeper 现在,你可以启动Zookeeper了。你可以使用以下命令启动Zookeeper: ``` cd /opt/zookeeper-3.4.14/bin ./zkServer.sh start ``` 你可以使用以下命令检查Zookeeper是否已经启动: ``` ./zkServer.sh status ``` 如果一切正常,你应该会看到以下输出: ``` Mode: standalone ``` 5. 测试Zookeeper 现在,你可以测试Zookeeper是否正常工作了。你可以使用以下命令连接到Zookeeper: ``` ./zkCli.sh -server 127...1:2181 ``` 如果一切正常,你应该会看到以下输出: ``` Connecting to 127...1:2181 Welcome to ZooKeeper! JLine support is disabled WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: 127...1:2181(CONNECTED) ] ``` 现在,你可以在Zookeeper中创建一个节点。你可以使用以下命令创建一个名为/test的节点: ``` create /test mydata ``` 如果一切正常,你应该会看到以下输出: ``` Created /test ``` 现在,你可以使用以下命令获取/test节点的数据: ``` get /test ``` 如果一切正常,你应该会看到以下输出: ``` mydata cZxid = x ctime = Thu Jan 01 00:00:00 UTC 197 mZxid = x mtime = Thu Jan 01 00:00:00 UTC 197 pZxid = x1 cversion = dataVersion = aclVersion = ephemeralOwner = x dataLength = 6 numChildren = ``` 恭喜你,你已经成功安装和配置了Zookeeper

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

.猫的树

你的鼓励就是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值