ZooKeeper安装 及 分布式搭建

下载镜像地址(3.4.9):

http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz

解压

tar xzvf zookeeper-3.4.9.tar.gz

解压后移至 /usr/local 目录下

修改配置文件

${ZOOKEEPER_HOME}/conf/zoo_sample.cfg

# The number of milliseconds of each tick
# session的会话时间 时间是毫秒
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
# 服务器启动后 slave与master进行启动的时间
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
#master与slave的心跳时间
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# 保存zookeeper的数据与快照
dataDir=/tmp/zookeeper
# the port at which the clients will connect
# 服务器外部通讯端口
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60


配置伪分布式
复制 cp zoo_sample.cfg  zoo1.cfg

修改zoo1.cfg文件

server.1=master:2888:3888
server.2=master:2889:3889
server.3=master:2890:3890
创建数据存储目录并配置zoo1.cfg

dataDir=/home/hadoop/tmp/zookeeper/zk1

复制第一台机器的配置到第二台 cp zoo1.cfg  zoo2.cfg

修改配置文件(修改数据存储地址与服务器端口,不能跟第一台冲突)

# example sakes.
dataDir=/home/hadoop/tmp/zookeeper/zk2
# the port at which the clients will connect
clientPort=2182
同理复制第三台服务器的配置 cp zoo2.cfg  zoo3.cfg,修改配置

在dataDir指定的目录下,创建myid文件

cd /home/hadoop/tmp/zookeeper/zk1

cd /home/hadoop/tmp/zookeeper/zk2

cd /home/hadoop/tmp/zookeeper/zk3

echo "1" >> myid

echo "2" >> myid

echo "3" >> myid

启动zookeeper

./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo1.cfg

./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo2.cfg

./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo3.cfg

查看zookeeper

./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo1.cfg

./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo2.cfg

./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo3.cfg

停止zookeeper

./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo1.cfg

./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo2.cfg

./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo3.cfg


遇到的问题;


查看zookeeper日志 目录 /usr/local/zookeeper/bin/zookeeper.out


此时需要查看下 hostname  将cfg文件里的master给为自己的hostname主机名

server.1=kakashi:2888:3888
server.2=kakashi:2889:3889
server.3=kakashi:2890:3890
这样就可以运行了


配置真分布式

配置真分布式clientport不需要修改,只需要修改zoo.cfg下的服务器,端口都一样不动,只需要改下主机名即可。


server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888

查看启动状态 jps ,三台机器全部启动











你可能感兴趣的:(zookeeper,zookeeper)