Zookeeper 环境搭建

2019-03-29  本文已影响0人  歌哥居士
$ mkdir ~/tmps/zookeeper-tmp
$ tar -zxvf ~/doc/zookeeper-3.4.5-cdh5.7.0.tar.gz -C ~/tools/
$ ln -s ~/tools/zookeeper-3.4.5-cdh5.7.0/ ~/tools/zookeeper
$ vim ~/.bash_profile
    export ZK_HOME=/home/user000/tools/zookeeper
    export PATH=$PATH:$ZK_HOME/bin
$ source ~/.bash_profile
$ cp ~/tools/zookeeper/conf/zoo_sample.cfg ~/tools/zookeeper/conf/zoo.cfg
$ vim ~/tools/zookeeper/conf/zoo.cfg
    dataDir=/home/user000/tmps/zookeeper-tmp
$ zkServer.sh start
$ zkCli.sh

单机伪分布式

复制Zookeeper
$ cp ~/tools/zookeeper-3.4.5-cdh5.7.0/  ~/tools/zookeeper2182 -rf
$ cp ~/tools/zookeeper-3.4.5-cdh5.7.0/  ~/tools/zookeeper2183 -rf
$ cp ~/tools/zookeeper-3.4.5-cdh5.7.0/  ~/tools/zookeeper2184 -rf

修改myid文件
$ mkdir ~/tools/zookeeper2182/dataDir
$ vim ~/tools/zookeeper2182/dataDir/myid
1
$ mkdir ~/tools/zookeeper2183/dataDir
$ vim ~/tools/zookeeper2183/dataDir/myid
2
$ mkdir ~/tools/zookeeper2184/dataDir
$ vim ~/tools/zookeeper2184/dataDir/myid
3

修改zoo.cfg (server.A=B:C:D  ------  A: 第几号服务器。B: IP地址。C: 交换信息的端口。D: 选举通信的端口。)
$ vim ~/tools/zookeeper2182/conf/zoo.cfg
dataDir=/home/user000/tools/zookeeper2182/dataDir
clientPort=2182
server.1=host000:2888:3888
server.2=host000:2888:3888
server.3=host000:2888:3888

$ vim ~/tools/zookeeper2183/conf/zoo.cfg
dataDir=/home/user000/tools/zookeeper2183/dataDir
clientPort=2183
server.1=host000:2888:3888
server.2=host000:2888:3888
server.3=host000:2888:3888

$ vim ~/tools/zookeeper2184/conf/zoo.cfg
dataDir=/home/user000/tools/zookeeper2184/dataDir
clientPort=2184
server.1=host000:2888:3888
server.2=host000:2888:3888
server.3=host000:2888:3888


测试集群环境
$ ~/tools/zookeeper2182/bin/zkServer.sh start
$ ~/tools/zookeeper2183/bin/zkServer.sh start
$ ~/tools/zookeeper2184/bin/zkServer.sh start

$ ~/tools/zookeeper2182/bin/zkServer.sh status
$ ~/tools/zookeeper2183/bin/zkServer.sh status
$ ~/tools/zookeeper2184/bin/zkServer.sh status

启动客户端
$ ~/tools/zookeeper2182/bin/zkCli.sh -server host000:2182
[zk: host000:2182(CONNECTED) 0] ls /
[zookeeper]
[zk: host000:2182(CONNECTED) 1] create /baozi test
Created /baozi
[zk: host000:2182(CONNECTED) 2] ls /
[zookeeper, baozi]
[zk: host000:2182(CONNECTED) 3] quit

$ ~/tools/zookeeper2183/bin/zkCli.sh -server host000:2183
[zk: host000:2183(CONNECTED) 0] ls /
[zookeeper, baozi]
[zk: host000:2183(CONNECTED) 1] delete /baozi
[zk: host000:2183(CONNECTED) 2] ls /
[zookeeper]
[zk: host000:2183(CONNECTED) 3] quit

$  ~/tools/zookeeper2184/bin/zkCli.sh -server host000:2184
[zk: host000:2184(CONNECTED) 0] ls /
[zookeeper]
[zk: host000:2184(CONNECTED) 1] quit

停掉
$ ~/tools/zookeeper2182/bin/zkServer.sh stop
$ ~/tools/zookeeper2183/bin/zkServer.sh stop
$ ~/tools/zookeeper2184/bin/zkServer.sh stop
上一篇下一篇

猜你喜欢

热点阅读