centos8安装zookeeper(单机方式)

一,下载zookeeper:

     1,官网地址

http://zookeeper.apache.org/

      找到这个地址:

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.6/

    2,下载

[ liuhongdi]# cd /usr/local/source/
[ source]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6-bin.tar.gz

 说明:架构森林是一个专注架构的博客,对应的源码可以访问这里获取

          https://github.com/liuhongdi/

 说明:作者邮箱:

二,解压

[ source]# tar -zxvf apache-zookeeper-3.5.6-bin.tar.gz[ source]# mv apache-zookeeper-3.5.6-bin /usr/local/soft/

三,安装

1,创建数据目录:

[ source]# mkdir /data/data
[ source]# mkdir /data/data/zookeeper
[ source]# chmod 777 /data/data/zookeeper/

2,修改配置文件

[ soft]# cd apache-zookeeper-3.5.6-bin/
[ apache-zookeeper-3.5.6-bin]# cd conf/
[ conf]# cp zoo_sample.cfg zoo.cfg
[ conf]# vi zoo.cfg
dataDir=/data/data/zookeeper
说明:dataDir=的值:是在配置文件中,指定要使用的数据目录

3,把二进制命令的路径加入系统path

[ conf]# vi /etc/profile

说明:在末尾增加以下命令:

export ZK_HOME=/usr/local/soft/apache-zookeeper-3.5.6-bin
export PATH=$ZK_HOME/bin:$PATH

修改完成之后,使配置起作用:

[ conf]# source /etc/profile

四,启动和停止zookeeper

启动

[ conf]# zkServer.sh start

停止

[ conf]# zkServer.sh stop

五,增加systemd管理zookeeper功能

1,新建service文件

[ 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文件:

[ 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的管理:

启动

[ conf]# systemctl start zookeeper

停止

[ conf]# systemctl stop zookeeper

六,如何查看当前已安装的zookeeper的版本?

[ conf]# echo stat|nc 127.0.0.1 2181
stat is not executed because it is not in the whitelist.

说明:需要解决上面这个报错

[ 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}"

继续测试

[ conf]# systemctl stop zookeeper
[ conf]# systemctl start zookeeper
[ 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端口

[ conf]# vi /usr/local/soft/apache-zookeeper-3.5.6-bin/conf/zoo.cfg 
[ conf]# systemctl stop zookeeper
[ conf]# systemctl start zookeeper

说明:在配置文件zoo.cfg中添加如下一行:

admin.enableServer=false

八,查看本地centos的版本:

[ lib]# cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core)

相关推荐