Centos 7,ZooKeeper教程(一)----Centos7下安装ZooKeeper(单机版)

 2023-09-25 阅读 22 评论 0

摘要:1、下载源码 官网下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/选择最新的版本进行下载 Centos 7, 这里选择3.4.10进行下载: centos7.5, wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz CentOS 7、 下载完成后

1、下载源码

 

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

Centos 7,

 

这里选择3.4.10进行下载:

 

centos7.5, 

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


 

 

CentOS 7、 

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

 

 

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. jps
  5. 其中,QuorumPeerMain是zookeeper进程,启动正常。
  6. #查看状态
  7. ./zkServer.sh status
  8. #服务器输出信息
  9. tail -500f zookeeper.out
  10. #停止zookeeper进程
  11. ./zkServer.sh stop


设置zookeeper服务开机启动

 

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



 

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

 

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

 

 

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


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

 

 

 

转载于:https://www.cnblogs.com/telwanggs/p/9513597.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/96271.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息