安装-zookeeper

下一篇:安装-kafka(https://www.jianshu.com/p/84140419cb7b

1.需求

安装ZooKeeper

2.下载

http://zookeeper.apache.org/releases.html

当前stable版是zookeeper-3.5.1-alpha

3.解压

tar –xf zookeeper-3.5.1-alpha.tar.gz

解压文件到"/root/softwares/zookeeper-3.5.1-alpha".

4.复制conf目录下的zoo_sample.cfg,并命名为zoo.cfg

5.修改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=/datatmp/zookeeper/data
dataLogDir=/datatmp/zookeeper/logs

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 are election port

server.1=zookeeper:2888:3888

其中,2888端口号是服务之间通信的端口,而3888是;zookeeper与其他应用程序通信的端口.而zookeeper是在hosts中已映射了本机的IP.

initLimit:这个配置项是用来配置Zookeeper接受客户端(这里所说的客户端不是用户连接Zookeeper服务器的客户端,而是Zookeeper服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 52000=10 秒。
syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2
2000=4 秒。
server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

6.创建dataDir参数指定的目录(这里指的是“ /datatmp/zookeeper/data”),并在目录下创建文件,命名为“myid”。

7.编辑“myid”文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,“myid”文件内容就是1。由于本次只在单点上进行安装配置,所以只有一个server.1。若还有其他服务器,比如地址为192.168.1.102,则在zoo.cfg文件中还需加入server.2=192.168.1.102:2888:3888。那么myid文件在192.168.1.102服务器上的内容就是2。至此,如果是多服务器配置,就需要将zookeeper-3.4.3目录拷贝到其他服务器,然后按照上述的方法修改myid。

8.在/etc/profile文件中设置PATH
修改profile文件:
sudo vi /etc/profile

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; color: rgb(102, 102, 102); font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(221, 221, 221); text-decoration-style: initial; text-decoration-color: initial;">export ZOOKEEPER_HOME=/root/softwares/ZooKeeper/zookeeper-3.5.1-alpha
export PATH=ZOOKEEPER_HOME/bin:PATH
export PATH

</pre>

OH YEAH!!! 安装完毕!

安装好了,启动搞搞.

打开hosts脚本:vim /etc/hosts,添加映射 192.168.5.56 zookeeper;

1.启动

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">zookeeper-3.5.1-alpha/bin/zkServer.sh start</pre>

2.输入jps命令查看进程

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">1573 QuorumPeerMain
1654 Jps</pre>

其中,QuorumPeerMain是zookeeper进程,启动正常。

3、查看状态:zookeeper-3.5.1-alpha/bin/zkServer.sh status

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">-
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone</pre>

4、启动客户端脚本:zookeeper-3.5.1-alpha/bin/zkCli.sh -server zookeeper:2181

5、停止zookeeper进程:zookeeper-3.5.1-alpha/bin/zkServer.sh stop
参考地址:https://www.cnblogs.com/Robert-huge/p/5649246.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、安装及配置 首先,再安装前,需要安装并配置好JDK(选择Oracle Java8 SE)。 其次,需要下载Zo...
    菜心有毒阅读 4,907评论 1 1
  • 姓名:郭金 学号:17101223407 【嵌牛导读】:ZooKeeper是一个分布式的,开放源码的分布式应用程序...
    宝宝啦啦啦阅读 315评论 2 0
  • Dubbo 建议使用 Zookeeper 作为服务的注册中心。 注册中心服务器(192.168.3.71)配置,安...
    journeyIT阅读 501评论 0 0
  • 1 Zookeeper概述# ZooKeeper是一个为分布式应用所设计的分布的、开源的协调服务,它主要是用来解决...
    七寸知架构阅读 7,375评论 0 101
  • “不忘初心,方得始终”谈的是信仰与坚持,人最难便是一直坚守最初的信仰。人生有太多诱惑与挫折,想要做到不忘初心,需要...
    落青芳阅读 770评论 7 13