zookeeper安装

2017-09-25  本文已影响18人  米刀灵

//下载
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
//解压
tar xvf zookeeper-3.4.6.tar.gz
//文件夹重命名
mv zookeeper-3.4.6 zk
//配置环境变量
export ZOOKEEPER_HOME=/usr/local/zk
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf

cd conf/
mv zoo_sample.cfg zoo_1.cfg
mv zoo_sample.cfg zoo_2.cfg
mv zoo_sample.cfg zoo_3.cfg

zoo_1.cfg:

# 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.
dataDir=/usr/local/zk/data_1

# the port at which the clients will connect
clientPort=2181

#the location of the log file
dataLogDir=/usr/local/zk/logs_1

server.0=128.199.173.52:2287:3387
server.1=128.199.173.52:2288:3388
server.2=128.199.173.52:2289:3389

zoo_2.cfg:

# 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.
dataDir=/usr/local/zk/data_2

# the port at which the clients will connect
clientPort=2182

#the location of the log file
dataLogDir=/usr/local/zk/logs_2

server.0=128.199.173.52:2287:3387
server.1=128.199.173.52:2288:3388
server.2=128.199.173.52:2289:3389

zoo_3.cfg:

# 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.
dataDir=/usr/local/zk/data_3

# the port at which the clients will connect
clientPort=2183

#the location of the log file
dataLogDir=/usr/local/zk/logs_3

server.0=128.199.XXX.XX:2287:3387
server.1=128.199.XXX.XX:2288:3388
server.2=128.199.XXX.XX:2289:3389   

/usr/local/zk/data_x目录中分别创建myid,cfg文件中的server.X,“X”表示每个目录中的myid的值。

vi myid

在bin目录中启动zookeeper

./zkServer.sh start zoo1.cfg

在bin目录中查看zookeeper运行状态

./zkServer.sh status zoo1.cfg

通过客户端连接,进入zookeeper命令行

bin/zkCli.sh -server 128.199.XXX.XX:2181,128.199.XXX.XX:2182,128.199.XXX.XX:2183

zookeeper命令:

//查看操作
help
//查看已经存在的znode
ls /
//创建znode
create /test "test"
//获取znode
get /test
//删除znode。若删除节点存在子节点,必须先删除子节点,再删除父节点。
delete /test
//创建临时节点,创建它的客户端断开时会自动删除
create -e /test-temp "temp"
//创建顺序节点,会在节点名后添加自增长数字
create -s /test-no. ""
//更新节点
set /test "test2"
//退出
quit
上一篇 下一篇

猜你喜欢

热点阅读