zookeeper基础环境搭建及启动脚本

zookeeper功能:

(1)可以为客户端管理少量数据(数据库)
(2)可以为客户端监听节点的状态,并在数据节点发生变化时通知客户端
(3)场景:动态增加服务器

1.上传安装包

解压 tar -zxvf name -C apps/

2.改名字

cp zoo_sample.cfg zoo.cfg

3.修改conf/zoo.cfg

#The number of milliseconds of each tick
tickTime=2000
#The number of ticks that the initial
#synchronization phase can take
initLimit=10
#The number of ticks that can pass between
#sending a request and getting an acknowledgement
syncLimit=5
#the directory where the snapshot is stored.
#do not use /tmp for storage, /tmp here is just
#example sakes.
dataDir=/root/zkdata   #规划路径
 the port at which the clients will connect
clientPort=2181
#Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

server.1=hdp-1:2888:3888 #集群中有哪些机器 2888通信用  3888:投票用
server.2=hdp-2:2888:3888
server.3=hdp-3:2888:3888

4.配置文件修改完后,将安装包拷贝给hdp-2 和 hdp-3

scp -r zookeeper-3.4.6/ hdp-2:$PWD
scp -r zookeeper-3.4.6/ hdp-3:$PWD

5.接着,到hdp-1上,新建数据目录/root/zkdata,并在目录中生成一个文件myid,内容为1

mkdir zkdata
echo 1 > zkdata/myid

接着,到hdp-2上,新建数据目录/root/zkdata,并在目录中生成一个文件myid,内容为2

mkdir zkdata
echo 2 > zkdata/myid

接着,到hdp-3上,新建数据目录/root/zkdata,并在目录中生成一个文件myid,内容为3

mkdir zkdata
echo 3 > zkdata/myid

6.配置zookeeper集群启动脚本:

vi zkmanager.sh

#! /bin/bash
for host in hdp-1 hdp-2 hdp-3
do
echo “${host}:${1}ing....”
ssh $host "source /etc/profile;/root/apps/zookeeper-3.4.6/bin/zkServer.sh $1"
done

下边这个可有可无

sleep 2

for host in hdp-1 hdp-2 hdp-3
do
ssh $host  “source /etc/profile;/root/apps/zookeeper-3.4.6/bin/zkServer.sh status”
done

7.启动、查询状态、关闭

sh zkServer.sh start //启动zookeeper
sh zkServer.sh status //查询状态
sh zkServer.sh stop //关闭zookeeper

你可能感兴趣的:(大数据生态圈,zookeeper环境搭建,zookeeper启动脚本)