Zookeeper的安装与配置

1、Zookeeper概念简介

Zookeeper是一个分布式协调服务;就是为用户的分布式应用程序提供协调服务
(1)zookeeper是为别的分布式程序服务的

(2)Zookeeper本身就是一个分布式程序(只要有半数以上节点存活,zk就能正常服务)

(3)Zookeeper所提供的服务涵盖:主从协调、服务器节点动态上下线、统一配置管理、分布式共享锁、统一名称服务

(4)虽然说可以提供各种服务,但是zookeeper在底层其实只提供了两个功能

  • 管理(存储,读取)用户程序提交的数据
  • 并为用户程序提供数据节点监听服务

(5)其他:
Zookeeper集群的角色: Leader 和 follower (Observer)
只要集群中有半数以上节点存活,集群就能提供服务

2、Zookeeper安装与配置

首先上传Zookeeper包,再解压,上传解压等命令操作,请参考我的上传解压等命令

这里只是一台Zookeeper,其他的Zookeeper操作相同

前提条件:安装好jdk

(1)删除不需要的文件

rm -rf src/ *.xml *.txt

rm -rf docs/ dist-maven/

(2)修改配置文件

[root@mini01 zookeeper-3.4.5]# cd conf/
[root@mini01 conf]# ll
total 12
-rw-r--r--. 1 501 games  535 Sep 30  2012 configuration.xsl
-rw-r--r--. 1 501 games 2161 Sep 30  2012 log4j.properties
-rw-r--r--. 1 501 games  808 Sep 30  2012 zoo_sample.cfg
[root@mini01 conf]# cp zoo_sample.cfg zoo.cfg

(3)修改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
#
# 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
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#自己配
server.1=192.168.253.21:2888:3888
server.2=192.168.253.22:2888:3888
server.3=192.168.253.23:2888:3888

(4)在/root/zkdata下创建一个myid的文件,根据自己的编号写
比如:这里的编号为1,对应的主机ip为192.168.253.21

[root@mini01 conf]# cd /root/zkdata
[root@mini01 zkdata]# echo 1 > myid

(5)启动服务

#进入目录
cd /root/apps/zookeeper-3.4.5/bin/

#开启服务
./zkServer.sh start

(6)启动时没有报错,查看转态时报错

#查看转态命令
./zkServer.sh status

#报错信息
JMX enabled by default
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

可能原因:

#1、没有关闭防火墙,影响Zookeeper之家的通信,所以先关闭防火墙
#2、各个ip与主机之间的映射
[root@mini01 bin]# cat /etc/hosts         
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.253.21 mini01
192.168.253.22 mini02
192.168.253.23 mini03
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值