下载

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

解压

tar –zxvf zookeeper-3.4.6.tar.gz

解压文件到"/usr/local/zookeeper-3.4.6".

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

修改zoo.cfg配置文件

# The number of milliseconds of each tick
tickTime=
# The number of ticks that the initial
# synchronization phase can take
initLimit=
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=
# 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=
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=
#
# 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=
# Purge task interval in hours
# Set to "" to disable auto purge feature
#autopurge.purgeInterval= #, are election port
server.=192.168.93.121::

配置详解

1.2888端口号是zookeeper服务之间通信的端口

2.888端口是zookeeper与其他应用程序通信的端口

3.initLimit:这个配置项是用来配置Zookeeper接受客户端(这里所说的客户端不是用户连接Zookeeper服务器的客户端,而是Zookeeper服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒。

4.syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒。

5.server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

创建dataDir参数指定的目录

配置文件zoo.cfg里的dataDir,我这里指的是“ /datatmp/zookeeper/data”,并在目录下创建文件,命名为“myid”。

编辑“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。

在/etc/profile文件中设置PATH

修改profile文件:

sudo vi /etc/profile
export ZOOKEEPER_HOME=/home/hadooptest/zookeeper-3.4.3
export PATH=$ZOOKEEPER_HOME/bin:$PATH
source /etc/profile

在防火墙中打开要用到的端口2181 2888 3888

sudo chkconfig iptables on
service iptables start

编辑 /etc/sysconfig/iptables

vi /etc/sysconfig/iptables

增加以下内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport  -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT

重启防火墙

service iptables restart

检查防火墙状态

service iptables status

OH YEAH!!! 安装完毕!

启动

进入bin目录

./zkServer.sh start

或者

sh zkServer.sh start

输入jps命令查看进程

1573 QuorumPeerMain
1654 Jps

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

查看状态

还是bin目录下

./zkServer.sh status

或者

sh zkServer.sh status
-
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone

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

5、停止zookeeper进程:

./zkServer.sh stop

或者

sh zkServer.sh stop

集群搭建

和单机的区别不大,就是配置文件zoo.cfg里把所有的机器都加上

server.=192.168.93.121::
server.=192.168.93.122::
server.=192.168.93.123::
// 如果有更多,就都加上

但是,记得集群里的server总数最好是单数,不要是双数,具体官方有解释

官方解释

The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.

Finally, note the two port numbers after each server name: " 2888" and "3888". Peers use the former port to connect to other peers. Such a connection is necessary so that peers can communicate, for example, to agree upon the order of updates. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port. Because the default leader election also uses TCP, we currently require another port for leader election. This is the second port in the server entry.

我的翻译

表单server.X的条目列出构成ZooKeeper服务的服务器。当服务器启动时,它通过查找数据目录中的文件myid来知道它是哪个服务器 。该文件包含服务器编号,以ASCII格式显示。

最后,请注意每个服务器名称后面的两个端口号:“2888”和“3888”。对等体使用前端口连接到其他对等体。这样的连接是必要的,使得对等体可以进行通信,例如,以商定更新的顺序。更具体地说,一个ZooKeeper服务器使用这个端口来连接追随者到领导者。当新的领导者出现时,追随者使用此端口打开与领导者的TCP连接。因为默认领导选举也使用TCP,所以我们目前需要另外一个端口进行领导选举。这是服务器条目中的第二个端口。

然后就是不要忘记各个Server的dataDir目录里的myid文件的数字也要对应上。

最后分别启动各个server就OK了。

121

[root@localhost zookeeper-3.4.11]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.11/bin/../conf/zoo.cfg
Mode: follower

122

[root@localhost zookeeper-3.4.11]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.11/bin/../conf/zoo.cfg
Mode: leader

123

[root@localhost zookeeper-3.4.11]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.11/bin/../conf/zoo.cfg
Mode: follower

对比单机模式启动的Mode: standalone,可以发现这边分别是Mode: leaderMode: follower,说明集群环境已经好了。

最后注意

有的时候服务器重启,导致开放的2181端口失效,需要重启下iptables,不然访问zookeeper会出现如下错误

错误 Will not attempt to authenticate using SASL (unknown error)

zookeeper(二):linux centos下安装zookeeper(单机和集群)的更多相关文章

  1. Linux系统下安装Redis和Redis集群配置

    Linux系统下安装Redis和Redis集群配置 一. 下载.安装.配置环境: 1.1.>官网下载地址: https://redis.io/download (本人下载的是3.2.8版本:re ...

  2. Linux(CentOs)下安装Phantomjs + Casperjs

    Linux(CentOs)下安装Phantomjs + Casperjs 是参照cnMiss's Blog http://ju.outofmemory.cn/entry/70691的博客进行安装的 1 ...

  3. linux/centos下安装nginx(rpm安装和源码安装)详细步骤

    Centos下安装nginx rpm包                                                                                 ...

  4. Linux CentOS下安装Tomcat9

    本文讲解在Linux CentOS下安装Tomcat9,以及Web项目的部署发布. 环境:阿里云ECS 云服务器Linux CentOS 使用XShell客户端连接服务器,进行操作实践. 1.下载To ...

  5. Rabbit安装(单机及集群,阿里云)

    Rabbit安装(单机及集群,阿里云) 前言 虽然我并不是部署人员,但是自己私人测试环境的各类东东还是得自己安装的. 尤其在规模不大的公司,基本安装部署工作都是后端的份内之事. 那么最令人痛苦的,莫过 ...

  6. [Linux]CentOS下安装和使用tmux

    前天随意点开博客园,看到了一篇关于tmux的文章 Tmux - Linux从业者必备利器,特意还点进去看了.毕竟Linux对于做游戏服务端开发的我来说,太熟悉不过了.不过我就粗略地看了一眼,就关掉了. ...

  7. linux下安装Elasticsearch(单机版和集群版)

    一.linux下安装Elasticsearch(单机) 1.软件下载 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsea ...

  8. Greenplum源码编译安装(单机及集群模式)完全攻略

    公司有个项目需要安装greenplum数据库,让我这个gp小白很是受伤,在网上各种搜,结果找到的都是TMD坑货帖子,但是经过4日苦战,总算是把greenplum的安装弄了个明白,单机及集群模式都部署成 ...

  9. Linux环境下安装zookeeper

    1. 下载安装文件zookeeper-3.4.6.tar.gz 镜像地址1: http://apache.fayea.com/zookeeper/ 镜像地址2: http://mirrors.hust ...

随机推荐

  1. Android 权限处理

    概述: 为了保护系统的完整性和用户隐私权,Android 在访问受限的沙盒中运行每款应用. 如果应用需要使用其沙盒以外的资源或信息,则必须明确请求权限. 根据应用请求的权限类型,系统可能会自动授予权限 ...

  2. __FILE__,__LINE__,FUNCTION__实现代码跟踪调试

    转:http://www.cnitblog.com/zouzheng/archive/2007/08/31/32691.aspx 先看下简单的初始代码:注意其编译运行后的结果. root@xuanfe ...

  3. nodesj中 中间件express-session的理解

    1.为什么使用session? session运行在服务器端,当客户端第一次访问服务器时,可以将客户的登录信息保存. 当客户访问其他页面时,可以判断客户的登录状态,做出提示,相当于登录拦截. sess ...

  4. \r和\n的区别

    /n  是换行/r   是回车 这是两码事,换行是指移动到下一行,回车是指移动到行首,我们通常所说的“回车”其实是这两个动作的结合.

  5. Android内存优化3 了解java GC 垃圾回收机制1

    开篇废话 如果我们想要进行内存优化的工作,还是需要了解一下,但这一块的知识属于纯理论的,有可能看起来会有点枯燥,我尽量把这一篇的内容按照一定的逻辑来走一遍.首先,我们为什么要学习垃圾回收的机制,我大概 ...

  6. iOS:分段控件UISegmentedControl的详细使用

    分段控件:UISegmentedControl   功能:分段的控制.页面的切换等.   介绍:当用户输入不仅仅是布尔值时,可使用分段控件(UISegmentedControl).分段控件提供一栏按钮 ...

  7. 又学到一个词REPL

    A read–eval–print loop (REPL), also known as an interactive toplevel or language shell 指的是 交互式解释器.

  8. 如何将redis中的数据导入到本地MongoDB和MySQL数据库

    将redis中的数据导入到本地MongoDB数据库 创建一个process_items_mongodb.py文件(文件名自定义): #!/usr/bin/env python # -*- coding ...

  9. Spring框架学习(4)spring整合hibernate

    内容源自:spring整合hibernate    spring整合注解形式的hibernate 这里和上一部分学习一样用了模板模式, 将hibernate开发流程封装在ORM层提供的模板类Hiber ...

  10. Unity命令行模式,也能「日志实时输出」

    转自自己的简书:http://www.jianshu.com/p/bd97cb8042a9 如果你使用过Unity命令行模式(batchmode),来实现Unity自动化编译构建,你肯定会遇到过这样的 ...