Centos7 安装zookeeper

目录

单机安装

伪集群安装

集群模式


本文讲不需要集群的zk安装和配置,以下操作都是基于虚拟机centos7 上操作安装,下载地址

https://archive.apache.org/dist/zookeeper/  或者官网https://zookeeper.apache.org/releases.html

这里安装的版本是 zookeeper-3.6.1 ,需要注意 zookeeper在3.5.5之后在下载的时候应该下载带bin的文件(apache-zookeeper-3.6.1-bin.tar.gz ),而之前的普通的tar.gz的包只是源码的包无法直接使用。

单机安装

 进入centos,选择一个目录,我这里是/usr/local/soft/,如果没有soft目录,可以自行创建

#cd /usr/local/soft/
#wget http://archive.apache.org/dist/zookeeper/apache-zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
#tar zxvf zookeeper-3.3.3.tar.gz
#cd zookeeper-3.3.3
#cp conf/zoo_sample.cfg conf/zoo.cfg

进入到 apache-zookeeper-3.6.1 目录,在修改zoo.cfg之前还需要新建两个文件夹data和logs

#mkdir data
#mkdir logs

修改conf目录下的zoo.cfg文件,dataDir执行刚才自己创建的data路径

# 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/soft/apache-zookeeper-3.6.1-bin/data
# 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

 进入到zk的bin目录下,执行 sh zkServer.sh start 命令启动zk

[root@localhost bin]# sh zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/soft/apache-zookeeper-3.6.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

可以使用 ps -aux | grep 'zookeeper' 也可以查看zk是否启动。

如果启动失败,可以看是否防火墙未关闭,zoo.cfg配置错误。

伪集群安装

伪集群模式就是在同一主机上启动多个zookeeper并组成集群,假如我们要在centos上创建3个zookeeper组集群为例子。

这里先分别创建zookeeper1,zookeeper2,zookeeper3三个文件夹

假设大家已经按照上面的单机步骤已经在zookeeper1目录下安装好了,我们把这个当成第一个zk服务(后面用zk1表示),进入到conf目录对zoo.cfg配置文件添加一下内容

#server表示服务器,数字1表示第一号 
#第一个端口号,例如2888,表示服务器与集群Leader的通信端口
#第二个端口号, 例如3888,表示zookeeper的leader失效后,zk之间选举的通信端口
server.1=192.168.139.10:2888:3888
server.2=192.168.139.10:4888:5888 
server.2=192.168.139.10:6888:7888 

进入 apache-zookeeper-3.6.1/data目录,创建 myid 文件 ,内容为1。对应上面 zoo.cfgserver. 后的数字,表示为第一台。

# vim myid 

同理,这里在需要创建2个文件夹,分别问zookeeper2,zookeeper3。把刚才zookeeper1里面文件分别复制粘贴到zookeeper2,zookeeper3目录里面,

修改conf目录下的zoo.cfg文件

  1. 修改dataDir ,分别指向对用的zk2,zk3里面的data目录
  2. 修改ClientPort,zk2,zk3可以分别设置成3181,4181,只要端口号不冲突就行

 修改data目录下的myid文件里面的内容,分别对应填入数字2,3。

分别进入各自的bin目录下启动zookeeper服务

#sh zkSever.sh start

集群模式

多个服务,在不同服务器上。不担心端口号彼此冲突问题,所以ClientPort端口号不需要修改,默认就好。

假如这里有三台服务器,对应的

192.168.199.128

192.168.199.129

192.168.199.130

还是可以参考单机模式安装,然后zoo.cfg的文件添加,dataDir指向当前zk的data目录,myid文件分别写对应的数字

server.1=192.168.199.128:2888:3888

server.2=192.168.199.129:2888:3888

server.3=192.168.199.130:2888:3888

可视化工具

下载地址https://github.com/HelloKittyNII/ZooViewer 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值