1、下载源码

官网下载地址: http://mirrors.hust.edu.cn/apache/zookeeper/ 选择最新的版本进行下载

这里选择3.4.10进行下载:

wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

下载完成后执行以下命令进行解压:

tar -zxvf zookeeper-3.4.10.tar.gz

2、配置Zookeeper

 

解压之后,在zookeeper目录下创建以下目录:

  1.  
    [fendo@localhost ~]$ cd zookeeper-3.4.10/
  2.  
    [fendo@localhost zookeeper-3.4.10]$ mkdir data
  3.  
    [fendo@localhost zookeeper-3.4.10]$ mkdir logs

将zookeeper-3.4.10/conf目录下的zoo_sample.cfg文件拷贝一份,命名为zoo.cfg

[fendo@localhost conf]$ cp zoo_sample.cfg zoo.cfg

然后修改zoo.cfg文件

vim zoo.cfg

修改成如下

  1.  
    # The number of milliseconds of each tick
  2.  
    tickTime=2000
  3.  
    # The number of ticks that the initial
  4.  
    # synchronization phase can take
  5.  
    initLimit=10
  6.  
    # The number of ticks that can pass between
  7.  
    # sending a request and getting an acknowledgement
  8.  
    syncLimit=5
  9.  
    # the directory where the snapshot is stored.
  10.  
    # do not use /tmp for storage, /tmp here is just
  11.  
    # example sakes.
  12.  
    dataDir=/home/fendo/zookeeper-3.4.10/data
  13.  
    dataLogDir=/home/fendo/zookeeper-3.4.10/logs
  14.  
    # the port at which the clients will connect
  15.  
    clientPort=2181
  16.  
    # the maximum number of client connections.
  17.  
    # increase this if you need to handle more clients
  18.  
    #maxClientCnxns=60
  19.  
    server.1=192.168.84.130:2888:3888

其中:
2888端口号是zookeeper服务之间通信的端口。
3888是zookeeper与其他应用程序通信的端口。

然后在dataDir=/home/fendo/zookeeper-3.4.10/data下创建myid文件(编辑myid文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,myid 文件内容就是1。如果只在单点上进行安装配置,那么只有一个server.1)

vim myid

fendo用户下修改.bash_profile,增加zookeeper配置:

vim /home/fendo/.bash_profile
  1.  
    # zookeeper env export
  2.  
    ZOOKEEPER_HOME=/home/fendo/zookeeper-3.4.10 export
  3.  
    PATH=$ZOOKEEPER_HOME/bin:$PATH

使配置文件生效

source /home/fendo/.bash_profile

关闭防火墙

切换到root用户下,执行以下命令:

systemctl stop firewalld.service

3、测试Zookeeper

 

启动并测试zookeeper(要用普通用户启动,不要用root):

  1.  
    #使用fendo用户到/home/fendo/zookeeper-3.4.10/bin目录中执行
  2.  
    ./zkServer.sh start
  3.  
     
  4.  
    #查看进程
  5.  
    jps
  6.  
     
  7.  
    其中,QuorumPeerMain是zookeeper进程,启动正常。
  8.  
     
  9.  
    #查看状态
  10.  
    ./zkServer.sh status
  11.  
     
  12.  
    #服务器输出信息
  13.  
    tail -500f zookeeper.out
  14.  
     
  15.  
    #停止zookeeper进程
  16.  
    ./zkServer.sh stop

设置zookeeper服务开机启动

  1.  
    # 切换到/etc/rc.d/init.d/目录下
  2.  
    cd /etc/rc.d/init.d
  3.  
     
  4.  
    # 创建zookeeper文件
  5.  
    touch zookeeper
  6.  
     
  7.  
    #更新权限
  8.  
    chmod +x zookeeper
  9.  
     
  10.  
    #编辑文件,在zookeeper里面输入如下内容
  11.  
    #!/bin/bash
  12.  
    #chkconfig:2345 20 90
  13.  
    #description:zookeeper
  14.  
    #processname:zookeeper
  15.  
    export JAVA_HOME=/user/local/java/jdk1.7.0_79
  16.  
    export PATH=$JAVA_HOME/bin:$PATH
  17.  
    case $1 in
  18.  
    start)su root /home/fendo/zookeeper-3.4.10/bin/zkServer.sh start;;
  19.  
    stop)su root /home/fendo/zookeeper-3.4.10/bin/zkServer.sh stop;;
  20.  
    status)su root /home/fendo/zookeeper-3.4.10/bin/zkServer.sh status;;
  21.  
    restart)su root /home/fendo/zookeeper-3.4.10/bin/zkServer.sh restart;;
  22.  
    *) echo "require start|stop|status|restart" ;;
  23.  
    esac

然后我们就可以用service zookeeper start/stop来启动停止zookeeper服务了

使用命令把zookeeper添加到开机启动里面

  1.  
    chkconfig zookeeper on
  2.  
    chkconfig --add zookeeper

添加完成之后接这个使用chkconfig --list 来看看我们添加的zookeeper是否在里面。

ZooKeeper教程(一)----Centos7下安装ZooKeeper(单机版)的更多相关文章

  1. centos7下安装zookeeper&zookeeper集群的搭建

    一.centos7下安装zookeeper 1.zookeeper 下载地址 https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 2.安装步骤 ...

  2. Linux(Centos7)下安装 zookeeper docker版 集群

    为了省去麻烦的软件安装,现在开发环境需要的软件越来越习惯于docker安装了,先看下安装后的截图,开发环境正在启动的容器 1.首先系统需要先支持docker …… 由于之前安装几次都没有做流程记录,在 ...

  3. Centos7下安装ZooKeeper

    1.下载源码 zookeeper 需要jdk的支持,需要先安装jdk 官网下载地址: http://mirrors.hust.edu.cn/apache/zookeeper/ 选择最新的版本进行下载 ...

  4. centos7上安装zookeeper

    centos7上安装zookeeper 1 准备工作 1.准备服务器,本次安装采用 centos7系统.内存2G.存储60G的虚拟机服务器一台: 2.服务器安装java环境: 参考文章<cent ...

  5. Windows下安装ZooKeeper

    Windows下安装ZooKeeper   一.简介 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组 ...

  6. Linux下安装Zookeeper

    Zookeeper是一个协调服务,可以用它来作为配置维护.名字服务.分布式部署: 下面,我来分享一下在Linux下安装Zookeeper的整个步骤,让大家少走弯路. 一.Zookeeper下载 [ro ...

  7. 如何在Centos7上安装zookeeper 多实例

    一.如何在Centos7上安装zookeeper 多实例 cd /usr/local/src/ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zoo ...

  8. Storm(1)-centos7下安装单机版Strom

    1.所需软件: jdk8.zookeeper.storm 2.安装zookeeper单机版 下载:http://zookeeper.apache.org/releases.html#download ...

  9. Win10下安装zookeeper

    Win10下安装zookeeper 注册中心zookeeper的安装 0.去Apache官网下载zookeeper http://zookeeper.apache.org/ 2.找到解压路径的conf ...

随机推荐

  1. IOS Core Image之二

    在上篇博客IOS Core Image之一中了解了下CIImage.CIFilter.CIContext三个类的使用,这篇了解下滤镜链(多滤镜)和人脸检测(不是人脸识别). 一.多滤镜 1.有些效果不 ...

  2. io多大合适

    MySQL的cpu iowait值,<=1/(number of cores).例如,如果是8核的,io wait 应<=12%. "Monitor DB CPU IO wait ...

  3. winform从table1获取需要的数据转存储到table2中

    小技术一个,记录一下 ,以下记录的是用两种方式来实现,数据表的转移 table转存数据之前首先要明确两个函数: Add():是指在最后一行添加一行 InsertAt():可以插入到表中的指定行 需求: ...

  4. Asp.Net 之字符串和集合的使用

    一:object:所有类的基类,所有类都直接或者间接继承自object 二:string 字符串的定义:string str=””    string str=new string(new char[ ...

  5. 十五、curator recipes之DistributedQueue

    简介 curator实现了先入先出的分布式消息队列,它采用的是zookeeper的持久化有序节点. 官方文档:http://curator.apache.org/curator-recipes/dis ...

  6. Spring Boot学习笔记(二)全局捕获异常处理

    非常简单只需要创建自己的异常处理类,加上两个注解,就可以了

  7. java:模拟队列操作

    import java.util.LinkedList; public class Myqueue { private LinkedList<Object> linkedList; pub ...

  8. poj 1811 Prime Test 大数素数测试+大数因子分解

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 27129   Accepted: 6713 Case ...

  9. C/C++:判断机器是32位还是64位

    要求是不使用sizeof,一开始写了个看似可以,但是有问题的方法: long* a = NULL; ; int n = (char*)b - (char*)a; 这个方法等价于sizeof(long) ...

  10. csharp: Linq keyword example

    /// <summary> /// http://www.dotnetperls.com/linq /// </summary> public partial class Li ...