1、下载解压Zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/ #下载地址
apache-zookeeper-3.8.0-bin.tar.gz #一定要下载带bin的包
cd /home/hadoop/app
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz
rm -rf apache-zookeeper-3.8.0-bin.tar.gz
ln -s apache-zookeeper-3.8.0-bin.tar.gz zookeeper
2、配置Zookeeper
cd /home/hadoop/app/zookeeper/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
#数据目录需要提前创建
dataDir=/home/hadoop/data/zookeeper/zkdata
#日志目录需要提前创建
dataLogDir=/home/hadoop/data/zookeeper/zkdatalog
#server.每个节点服务编号=服务器ip地址:集群通信端口:选举端口
server.1=hadoop01:2888:3888
server.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888
3、将hadoop01的Zookeeper安装目录同步到hadoop02、hadoop03节点
cd /home/hadoop/app
scp -r apache-zookeeper-3.8.0 hadoop@hadoop02:/home/hadoop/app/
scp -r apache-zookeeper-3.8.0 hadoop@hadoop03:/home/hadoop/app/
在hadoop02、hadoop03两个节点上分别生成软连接
cd /home/hadoop/app
ln -s apache-zookeeper-3.8.0-bin.tar.gz zookeeper
4、在三个节点上分别创建Zookeeper数据和日志目录(保持和zoo.cfg配置文件一致)
#创建Zookeeper数据目录
mkdir -p /home/hadoop/data/zookeeper/zkdata
#创建Zookeeper日志目录
mkdir -p cd /home/hadoop/data/zookeeper/zkdatalog
5、为Zookeeper集群各个节点创建服务编号1、2、3
cd /home/hadoop/data/zookeeper/zkdata
touch myid
echo 1 myid
6、在三个节点启动Zookeeper集群
cd /home/hadoop/data/zookeeper/bin
zkServer.sh start #启动Zookeeper
zkServer.sh status #查看节点状态
显示一个leader(领导者)、两个follower(跟随者),说明Zookeeper集群安装部署成功。
7、Zookeeper shell 验证
cd /home/hadoop/data/zookeeper/bin
zkCli.sh -server hadoop01:2181
ls / #查看Zookeeper根节点的znode结构
create /test helloworld # 创建znode节点
get /test #查看znode节点
set /test zookeeper #修改znode节点
delte /test #删除znode节点