1.下载zookeeper安装包
2.集群规划
在hadoop102、hadoop103和hadoop104三个节点上部署Zookeeper。
3.解压安装
tar -zxvf zookeeper-3.5.7.tar.gz -C /opt/module/
同步/opt/module/zookeeper目录内容到hadoop103、hadoop104
mv apache-zookeeper-3.5.7-bin/ zookeeper #改个简单的名字
xsync zookeeper/
4.配置环境变量并同步
sudo vim /etc/profile.d/my_env.sh
##ZOOKEEPER_HOME export ZOOKEEPER_HOME=/opt/module/zookeeper export PATH=$PATH:$ZOOKEEPER_HOME/bin
sudo /home/atguigu/bin/xsync /etc/profile.d/my_env.sh
5.修改配置文件
将/opt/module/zookeeper/conf这个路径下的zoo_sample.cfg修改为zoo.cfg;
mv zoo_sample.cfg zoo.cfg
# The number of milliseconds of each tick tickTime=2000 #zookeeper每两秒响应一次 # The number of ticks that the initial # synchronization phase can take initLimit=10 #zookeeper数据全局一致,启动时全部节点同步,持续时间10个tick 20秒 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 #发出一个请求后,5tick内响应不算超时 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #存储zookeeper快照的位置,不要用默认的/tmp/zookeeper 做存储,这只是一个例子 dataDir=/opt/module/zookeeper/zkData # the port at which the clients will connect clientPort=2181 #连接zookeeper的端口 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 #最多连接多少个客户端 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 #zookeeper快照最多存储几个 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 #自动删除 server.2=hadoop102:2888:3888 #2888选举端口 #3888服务端口 server.3=hadoop103:2888:3888 server.4=hadoop104:2888:3888
修改dataDir=/opt/module/zookeeper/zkData
添加
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888
6.设置zookeeper集群myid配置服务器编号
在/opt/module/zookeeper/目录下创建zkData
mkdir -p zkData
在/opt/module/zookeeper/zkData目录下创建一个myid的文件
touch myid
编辑myid文件
vim myid
在文件中添加与server对应的编号:
2
7.同步zookeeper到其它节点
xsync /opt/module/zookeeper/
8.修改其它节点的myid到对应的server
hadoop103 的 myid 修改为3 echo 3 > $ZOOKEEPER_HOME/zkData/myid
hadoop104 的 myid 修改为4 echo 4 > $ZOOKEEPER_HOME/zkData/myid
9.启动zookeeper
zkServer.sh start
zookeeper群起脚本
cd /home/atguigu/bin vim myzookeeper.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start"){
for i in hadoop102 hadoop103 hadoop104
do
echo "----------启动$i zk----------"
ssh $i "/opt/module/zookeeper/bin/zkServer.sh start"
done
};;
"stop"){
for i in hadoop102 hadoop103 hadoop104
do
echo "----------关闭$i zk----------"
ssh $i "/opt/module/zookeeper/bin/zkServer.sh stop"
done
};;
"status"){
for i in hadoop102 hadoop103 hadoop104
do
echo "----------查看$i zk----------"
ssh $i "/opt/module/zookeeper/bin/zkServer.sh status"
done
};;
esac
更改权限
chmod +x myzookeeper.sh
分发脚本
xsync /home/atguigu/bin/



