下载安装并运行
下载
sudo wget http://mirrors.hust.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
sudo tar xzvf zookeeper-3.4.12.tar.gz
sudo mv zookeeper-3.4.12.tar.gz zookeeper
cd zookeeper/conf
cp zoo_sample.cfg zoo.cfg
修改配置文件
sudo vi zoo.cfg
dataDir = /var/zookeeper 存储快照文件的目录
ClientPort = 2181 服务器对外提供服务的端口号
server.服务器id=服务器的ip地址:通信端口:选举端口
集群模式
server.1=192.168.111.111:2888:3888
server.2=192.168.111.112:2888:3888
server.3=192.168.111.113:2888:3888
伪集群模式
server.1=192.168.111.111:2888:3888
server.2=192.168.111.111:2889:3889
server.3=192.168.111.111:2890:3890
单机模式
server.1=192.168.111.111:2888:3888
保存
把zoo.cfg拷贝到其他主机
scp zoo.cfg root@192.168.111.112:/opt/zookeeper/conf
进入配置文件dataDir设置的文件夹里
创建 myid 的文件 并把server.id填写进去 例如 server.1=192.168.111.111:2888:3888 id是1
vim myid
内容为1
启动zookeeper
进入/opt/zookeeper/bin目录 执行
./zkserver.sh start
(我apt安装的启动方式是/usr/share/zookeeper/bin/zkServer.sh start)
验证是否启动
telnet 192.168.111.111 2181 (mac安装:brew install telnet)
echo stat | nc 192.168.111.111 2181
输入stat显示信息
root@xiaokang4:/usr/share/zookeeper/bin# telnet 192.168.111.113 2181
Trying 192.168.111.113...
Connected to 192.168.111.113.
Escape character is '^]'.
stat
Zookeeper version: 3.4.8-1--1, built on Fri, 26 Feb 2016 14:51:43 +0100
Clients:
/192.168.111.114:362000
Latency min/avg/max: 0/0/0
Received: 2
Sent: 1
Connections: 1
Outstanding: 0
Zxid: 0x100000000
Mode: follower
Node count: 4
Connection closed by foreign host.