zookeeper安装
Posted gh-123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zookeeper安装相关的知识,希望对你有一定的参考价值。
一。介绍
1. zookeeper 是一个分布式协调服务,就是为用户的分布式应用程序提供协调服务。
2. zookeeper 是为别的分布式程序服务的。
3. zookeeper 本身就是一个分布式程序(只要有半数以上节点存活,就能正常工作)
4. zookeeper 所提供的服务包括:主从协调,服务节点动态上下线,统一配置管理,分布式共享锁,统一名称服务等。
5. zookeeper 在底层只提供了两个功能:管理(存储,读取)用户提交的数据并为用户程序提供数据节点监听服务。
二。安装
1. 官网下载地址:http://hadoop.apache.org/
[[email protected] ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
2. 解压文件
[[email protected] ~]# tar -xvf zookeeper-3.4.13.tar.gz
3. 删除运行不相关的文件
[[email protected] zookeeper-3.4.13]# rm -rf src/ *.xml *.txt dist-maven/ docs/
三。配置
1. 进入conf文件夹
[[email protected] zookeeper-3.4.13]# cd conf/ [[email protected] conf]#
2. 使配置生效(名字为 zoo.cfg 才生效)
[[email protected] conf]# cp zoo_sample.cfg zoo.cfg [[email protected] conf]#
3. 配置zoo.cfg
[[email protected] conf]# cat zoo.cfg # The number of milliseconds of each tick # 心跳周期为2000毫秒 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 # 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 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 # 默认端口 2888为主从通信端口 3888为投票选举端口 # 要在对应主机的数据目录(dataDir /root/zkData)创建名为myid的文件,里面为server.的id号 server.1=host1:2888:3888 server.2=host2:2888:3888 server.3=host3:2888:3888 [[email protected] conf]#
4. 在数据目录创建myid
[[email protected] conf]# mkdir /root/zkData [[email protected] conf]# cd /root/zkData/ [[email protected] zkData]# echo 1 > myid [[email protected] zkData]# ll 总用量 4 -rw-r--r-- 1 root root 2 9月 1 17:55 myid [[email protected] zkData]# cat myid 1 [[email protected] zkData]#
5. 拷贝zookeeper-3.4.13到其他两台
[[email protected] ~]# scp -r zookeeper-3.4.13 [email protected]:/root
[[email protected] ~]# scp -r zookeeper-3.4.13 host3:/root
6. 创建 host2 主机的myid
[[email protected] ~]# mkdir /root/zkData [[email protected] ~]# cd /root/zkData/ [[email protected] zkData]# echo 2 > myid [[email protected] zkData]# ll 总用量 4 -rw-r--r-- 1 root root 2 9月 2 02:50 myid [[email protected] zkData]# cat myid 2 [[email protected] zkData]#
7. 创建 host3 主机的myid
[[email protected] ~]# mkdir /root/zkData [[email protected] ~]# cd /root/zkData/ [[email protected] zkData]# echo 3 > myid [[email protected] zkData]# ll 总用量 4 -rw-r--r-- 1 root root 2 9月 2 02:52 myid [[email protected] zkData]# cat myid 3 [[email protected] zkData]#
四。启动zookeeper
1. 启动第一台(没过半数,不能正常工作)
[[email protected] bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [[email protected] bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Error contacting service. It is probably not running. [[email protected] bin]#
2. 启动第二台(刚开始无历史数据启动时,投票给myid大的节点)
[[email protected] bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [[email protected] bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Mode: leader [[email protected] bin]#
3. 启动第二台,有主节点了(leader),就直接为从节点(follower)
[[email protected] bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [[email protected] bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zookeeper-3.4.13/bin/../conf/zoo.cfg Mode: follower [[email protected] bin]#
以上是关于zookeeper安装的主要内容,如果未能解决你的问题,请参考以下文章
ZooKeeper伪分布集群安装及使用 RMI+ZooKeeper实现远程调用框架
在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途