Zookeeper从零开始学习

2017-05-20  本文已影响0人  梦溺残沙里

[TOC]

概述


关键字

起源

目标

接口

运转流程

分治


状态机,参考Link

实战


部署伪集群

  1. 从zookeeper官网下载最新stable版本
  2. 解压并复制三份:
drwxr-xr-x 11 work work 4.0K May 20 19:37 zookeeper00
drwxr-xr-x 11 work work 4.0K May 20 19:49 zookeeper01
drwxr-xr-x 11 work work 4.0K May 20 19:49 zookeeper02
-rw-r--r--  1 work work  34M May 20 19:29 zookeeper-3.4.10.tar.gz
  1. 分别添加配置和mypid如下:
    -- zoo1
➜  tools cat zookeeper00/conf/zoo.cfg
tickTime=2000
dataDir=log
clientPort=8181
initLimit=5
syncLimit=2
server.1=127.0.0.1:8182:8183
server.2=127.0.0.1:8282:8283
server.3=127.0.0.1:8382:8383
➜  tools cat zookeeper00/log/myid
1

-- zoo2

➜  tools cat zookeeper00/conf/zoo.cfg
tickTime=2000
dataDir=log
clientPort=8281
initLimit=5
syncLimit=2
server.1=127.0.0.1:8182:8183
server.2=127.0.0.1:8282:8283
server.3=127.0.0.1:8382:8383
➜  tools cat zookeeper01/log/myid
2

-- zoo3

➜  tools cat zookeeper02/conf/zoo.cfg
tickTime=2000
dataDir=log
clientPort=8381
initLimit=5
syncLimit=2
server.1=127.0.0.1:8182:8183
server.2=127.0.0.1:8282:8283
server.3=127.0.0.1:8382:8383
➜  tools cat zookeeper02/log/myid
3
  1. 分别启动三个zookeeper
$ cd zookeeper00
$ bin/zkServer.sh start
$ cd ../zookeeper01
$ bin/zkServer.sh start
$ cd ../zookeeper02
$ bin/zkServer.sh start
  1. 检查进程


    图片.png
  2. 检查是否启动成功

$ bin/zkCli.sh -server 127.0.0.1:8181
...
Welcome to ZooKeeper!
...
[zk: 127.0.0.1:8181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
    connect host:port
    get path [watch]
    ls path [watch]
    set path data [version]
    rmr path
    delquota [-n|-b] path
    quit
    printwatches on|off
    create [-s] [-e] path data acl
    stat path [watch]
    close
    ls2 path [watch]
    history
    listquota path
    setAcl path acl
    getAcl path
    sync path
    redo cmdno
    addauth scheme auth
    delete path [version]
    setquota -n|-b val path
[zk: 127.0.0.1:8181(CONNECTED) 1] ls /
[zookeeper]

Python应用注册到此集群

  1. 编译并安装c版本的zookeeper client
$ cd zookeeper-3.4.10/src/c
# 这里指定安装目录,以便在非root权限下安装
$ ./configure --prefix=/home/work/local
$ make -j8
$ make install
# 需要修改环境变量以便能使用编译的zookeeper client
$ cat ~/.bashrc
export PATH="$HOME/local/bin:$PATH"
export LD_RUN_PATH="$HOME/local/lib:$LD_RUN_PATH"
export LD_LIBRARY_PATH="$HOME/local/lib:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$HOME/local/lib:$LD_LIBRARY_PATH"
export C_INCLUDE_PATH="$HOME/local/include/zookeeper:$C_INCLUDE_PATH"
$ source ~/.bashrc
  1. 安装zookeeper python库参考链接
$ easy_install zkpython
# 或者
$ pip install zkpython
  1. 使用zkpython写一个注册到zookeeper的例子,参考Link1Link2

Golang应用注册到此集群

其他

上一篇下一篇

猜你喜欢

热点阅读