下载地址:
在/home/dt目录下创建zookeepre文件夹,将下载好的安装包传入文件夹内并解压。
解压:
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz |
进入conf目录,将zoo_sample.cfg这个文件复制为zoo.cfg
cd apache-zookeeper-3.6.3-bin/conf cp zoo_sample.cfg zoo.cfg |
对zoo.cfg文件进行编辑
vi zoo.cfg |
按 i 进入编辑模式,修改以下内容:
dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
注意:如果想配置集群的话,请在clientPort下面添加服务器的ip。如
server.1=服务器A的ip:2888:3888
server.2=服务器B的ip:2888:3888
server.3=服务器C的ip:2888:3888
如果电脑内存比较小,zookeeper还可以设置成伪集群。也就是全部服务器采用同一个ip,但是使用不同的端口。
在tmp目录创建目录
mkdir /tmp/zookeeper mkdir /tmp/zookeeper/data mkdir /tmp/zookeeper/log |
如果是配置集群,还需要在前面配置过的dataDir路径下新增myid文件
cd /tmp/zookeeper/data touch myid vi myid |
在data目录下创建文件,文件名为“myid”, 编辑该“myid”文件,并在对应的IP的机器上输入对应的编号。
如在服务器A上,“myid”文件内容就是1。
配置环境变量
以上操作完成后,需要配置一下环境变量,配置环境变量的命令如下:
export ZOOKEEPER_INSTALL=/home/dt/zookeeper/apache-zookeeper-3.6.3-bin export PATH=$PATH:$ZOOKEEPER_INSTALL/bin |
启动zookeeper
进入bin目录,并启动zookeeper
cd /home/dt/zookeeper/apache-zookeeper-3.6.3-bin/bin ./zkServer.sh start |
启动成功效果如下:
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
zookeeper的服务端启动后,还需要启动zookeeper的客户端:
./zkCli.sh |
如果是连接多个不同的主机节点,可以使用如下命令:
./zkCli.sh -server 服务器ip:host |
启动成功效果如下:
Connecting to localhost:2181
..........
..........
..........
Welcome to ZooKeeper!
2018-10-25 21:04:54,407 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1029] - 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
2018-10-25 21:04:54,471 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
[zk: localhost:2181(CONNECTING) 0] 2018-10-25 21:04:54,501 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1303] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x10000712e6f0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
查看状态:
./zkServer.sh status |
ZooKeeper JMX enabled by default
Using config: /home/dt/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leade