一,下载zookeeper:
1,官网地址
http://zookeeper.apache.org/
找到这个地址:
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.6/
2,下载
[[email protected] liuhongdi]# cd /usr/local/source/ [[email protected] source]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6-bin.tar.gz
说明:架构森林是一个专注架构的博客,对应的源码可以访问这里获取
说明:作者邮箱: [email protected]
二,解压
[[email protected] source]# tar -zxvf apache-zookeeper-3.5.6-bin.tar.gz[[email protected] source]# mv apache-zookeeper-3.5.6-bin /usr/local/soft/
三,安装
1,创建数据目录:
[[email protected] source]# mkdir /data/data [[email protected] source]# mkdir /data/data/zookeeper [[email protected] source]# chmod 777 /data/data/zookeeper/
2,修改配置文件
[[email protected] soft]# cd apache-zookeeper-3.5.6-bin/ [[email protected] apache-zookeeper-3.5.6-bin]# cd conf/ [[email protected] conf]# cp zoo_sample.cfg zoo.cfg [[email protected] conf]# vi zoo.cfg dataDir=/data/data/zookeeper
说明:dataDir=的值:是在配置文件中,指定要使用的数据目录
3,把二进制命令的路径加入系统path
[[email protected] conf]# vi /etc/profile
说明:在末尾增加以下命令:
export ZK_HOME=/usr/local/soft/apache-zookeeper-3.5.6-bin export PATH=$ZK_HOME/bin:$PATH
修改完成之后,使配置起作用:
[[email protected] conf]# source /etc/profile
四,启动和停止zookeeper
启动
[[email protected] conf]# zkServer.sh start
停止
[[email protected] conf]# zkServer.sh stop
五,增加systemd管理zookeeper功能
1,新建service文件
[[email protected] conf]# vi /etc/systemd/system/zookeeper.service
说明:service文件的内容:
[Unit] Description=zookeeper.service After=network.target ConditionPathExists=/usr/local/soft/apache-zookeeper-3.5.6-bin/conf/zoo.cfg [Service] Type=forking User=root Group=root ExecStart=/usr/local/soft/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start ExecStop=/usr/local/soft/apache-zookeeper-3.5.6-bin/bin/zkServer.sh stop [Install] WantedBy=multi-user.target
2,直接使用systemctl启动zookeeper会因找不到java的路径报错,
我们需要手动修改zkEnv.sh文件:
[[email protected] conf]# vi /usr/local/soft/apache-zookeeper-3.5.6-bin/bin/zkEnv.sh
编辑的内容:
添加如下一行 JAVA_HOME=/usr/local/soft/jdk-13.0.2 到此两行上方即可: ZOOBINDIR="${ZOOBINDIR:-/usr/bin}" ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."
3,测试systemctl的管理:
启动
[[email protected] conf]# systemctl start zookeeper
停止
[[email protected] conf]# systemctl stop zookeeper
六,如何查看当前已安装的zookeeper的版本?
[[email protected] conf]# echo stat|nc 127.0.0.1 2181 stat is not executed because it is not in the whitelist.
说明:需要解决上面这个报错
[[email protected] conf]# vi /usr/local/soft/apache-zookeeper-3.5.6-bin/bin/zkServer.sh
编辑的内容:
找到: else echo "JMX disabled by user request" >&2 ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain" fi 在上面这行fi下面添加: ZOOMAIN="-Dzookeeper.4lw.commands.whitelist=* ${ZOOMAIN}"
继续测试
[[email protected] conf]# systemctl stop zookeeper [[email protected] conf]# systemctl start zookeeper [[email protected] conf]# echo stat|nc 127.0.0.1 2181 Zookeeper version: 3.5.6-c11b7e26bc554b8523dc929761dd28808913f091, built on 10/08/2019 20:18 GMT Clients: /127.0.0.1:41352[0](queued=0,recved=1,sent=0) Latency min/avg/max: 0/0/0 Received: 1 Sent: 0 Connections: 1 Outstanding: 0 Zxid: 0x0 Mode: standalone Node count: 5
七,关闭zookeeper内置的管理器
zookeeper内置有一个web管理器,默认使用8080端口,
但这个版本的管理器不能正常访问,
我们可以避免启动内置的管理器,也避免占用8080端口
[[email protected] conf]# vi /usr/local/soft/apache-zookeeper-3.5.6-bin/conf/zoo.cfg [[email protected] conf]# systemctl stop zookeeper [[email protected] conf]# systemctl start zookeeper
说明:在配置文件zoo.cfg中添加如下一行:
admin.enableServer=false
八,查看本地centos的版本:
[[email protected] lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)
原文地址:https://www.cnblogs.com/architectforest/p/12327533.html
时间: 2024-10-03 22:15:45