zoukankan      html  css  js  c++  java
  • Centos7下安装ZooKeeper

    1、下载源码

    zookeeper 需要jdk的支持,需要先安装jdk

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

    这里选择3.4.10进行下载:

    [html] view plain copy
     
    1. wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz  


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

    [html] view plain copy
     
    1. tar -zxvf zookeeper-3.4.10.tar.gz  

    2、配置Zookeeper

     

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

    [html] view plain copy
     
    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

    [html] view plain copy
     
    1. [fendo@localhost conf]$ cp zoo_sample.cfg zoo.cfg  


    然后修改zoo.cfg文件

    [html] view plain copy
     
    1. vim zoo.cfg  

    修改成如下

    [html] view plain copy
     
    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)

    [html] view plain copy
     
    1. vim myid  

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

    [html] view plain copy
     
    1. vim /home/fendo/.bash_profile  
    [html] view plain copy
     
    1. # zookeeper env export     
    2. ZOOKEEPER_HOME=/home/fendo/zookeeper-3.4.10 export     
    3. PATH=$ZOOKEEPER_HOME/bin:$PATH    


    使配置文件生效 

    [html] view plain copy
     
    1. source /home/fendo/.bash_profile  

    关闭防火墙

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

    [html] view plain copy
     
    1. systemctl stop firewalld.service  

    3、测试Zookeeper

     

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

    [html] view plain copy
     
    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服务开机启动

    [html] view plain copy
     
    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添加到开机启动里面

    [html] view plain copy
     
    1. chkconfig zookeeper on    
    2. chkconfig --add zookeeper  


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

  • 相关阅读:
    Perl-晶晨2021届笔试题
    数字IC设计流程
    后端一些常考知识点
    sklearn: 利用TruncatedSVD做文本主题分析
    用截断奇异值分解(Truncated SVD)降维
    numpy.linalg.norm(求范数)
    岭回归和lasso回归及正则化
    什么是范数?
    MySQL三大范式和反范式
    汇编知识之EIP寄存器
  • 原文地址:https://www.cnblogs.com/lijiasnong/p/9150523.html
Copyright © 2011-2022 走看看