CentOS安装ZooKeeper

1、下载Zookeeper

    Zookeeper有两种下载方式:wget和手动下载;本文主要说下手动下载安装。

点击下载链接:https://archive.apache.org/dist/zookeeper/ ,选择要下载的版本。

2、解压文件

    找到下载文件的目录,使用tar命令加压文件

    tar -zxvf zookeeper-3.4.9.tar.gz

3、修改配置文件

    解压后会新增名为zookeeper-3.4.9的文件夹,进入conf目录

    cd zookeeper-3.4.9/conf/

    将zoo_sample.cfg文件复制一份,并命名为zoo.cfg

    cp zoo_sample.cfg zoo.cfg

    使用vim命令打开zoo.cfg配置文件

    vim zoo.cfg

# The number of milliseconds of each tick
#客户端与服务器或者服务器与服务器之间维持心跳,也就是每个tickTime时间就会发送一次心跳。通过心跳不仅能够用来监听机器的工作状态,还可以通过心跳来控制Flower跟Leader的通信时间,默认情况下FL的会话时常是心跳间隔的两倍。
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
#集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
#集群中flower服务器(F)跟leader(L)服务器之间的请求和答应最多能容忍的心跳数。
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#该属性对应的目录是用来存放myid信息跟一些版本,日志,跟服务器唯一的ID信息等。
dataDir=/tmp/zookeeper
# the port at which the clients will connect
#客户端连接zookeeper服务器的端口,zookeeper会监听这个端口,接收客户端的请求访问。
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这个属性的值,其他不用修改。

4、启动Zookeeper

    进入Zookeeper的bin目录

    cd zookeeper-3.4.9/ bin/

    运行Zookeeper

     ./zkServer.sh start

    出现以下信息说明启动成功

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

5、查询Zookeeper的状态

    ./zkServer.sh status

[root@tmc bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/tmc/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: standalone

6、客户端连接测试

    ./zkCli.sh

[root@tmc bin]# ./zkCli.sh 
Connecting to localhost:2181
2019-12-23 14:26:12,416 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2019-12-23 14:26:12,420 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=tmc
2019-12-23 14:26:12,420 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_231
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/local/java/jdk1.8.0_231/jre
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/local/tmc/zookeeper-3.4.9/bin/../build/classes:/usr/local/tmc/zookeeper-3.4.9/bin/../build/lib/*.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/usr/local/tmc/zookeeper-3.4.9/bin/../conf:.:/usr/local/java/jdk1.8.0_231/lib:/usr/local/java/jdk1.8.0_231/jre/lib
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2019-12-23 14:26:12,422 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2019-12-23 14:26:12,423 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-693.el7.x86_64
2019-12-23 14:26:12,423 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2019-12-23 14:26:12,423 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2019-12-23 14:26:12,423 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/local/tmc/zookeeper-3.4.9/bin
2019-12-23 14:26:12,462 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@25f38edc
Welcome to ZooKeeper!
2019-12-23 14:26:12,659 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-12-23 14:26:13,112 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2019-12-23 14:26:13,359 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x16f316e70a90000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 

    如上表示连接成功,我们就可以进行节点的增删改查了。

6、关闭Zookeeper

    ./zkServer.sh stop

[root@tmc bin]# ./zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/tmc/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值