Centos8安装Zookeeper3.6.1

下载zookeeper:

官网地址 http://zookeeper.apache.org/
下载直达 Zookeeper3.6.1

[root@localhost zookeeper]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
[root@localhost zookeeper]# ll
total 12148
-rw-r--r-- 1 root root 12436328 May 25 22:26 apache-zookeeper-3.6.1-bin.tar.gz
[root@localhost zookeeper]# 

解压

[root@localhost zookeeper]# tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz 
[root@localhost zookeeper]# ll
total 12148
drwxr-xr-x 6 root root      133 May 25 22:27 apache-zookeeper-3.6.1-bin
-rw-r--r-- 1 root root 12436328 May 25 22:26 apache-zookeeper-3.6.1-bin.tar.gz
[root@localhost zookeeper]# 

安装

创建数据目录:

[root@localhost zookeeper]# mkdir data
[root@localhost zookeeper]# mkdir data/zookeeper

修改配置文件

[root@localhost zookeeper]# cd apache-zookeeper-3.6.1-bin
apache-zookeeper-3.6.1-bin/        apache-zookeeper-3.6.1-bin.tar.gz  
[root@localhost zookeeper]# cd apache-zookeeper-3.6.1-bin/conf/
[root@localhost conf]# ll
total 12
-rw-r--r-- 1 1000 1000  535 Apr 21 22:59 configuration.xsl
-rw-r--r-- 1 1000 1000 3435 Apr 21 22:59 log4j.properties
-rw-r--r-- 1 1000 1000 1148 Apr 21 22:59 zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# ll
total 16
-rw-r--r-- 1 1000 1000  535 Apr 21 22:59 configuration.xsl
-rw-r--r-- 1 1000 1000 3435 Apr 21 22:59 log4j.properties
-rw-r--r-- 1 root root 1148 May 25 22:52 zoo.cfg
-rw-r--r-- 1 1000 1000 1148 Apr 21 22:59 zoo_sample.cfg
[root@localhost conf]# vi zoo.cfg 

dataDir=/home/work/zookeeper/data/zookeeper
clientPort=2181

[root@localhost conf]# 

配置系统变量

配置系统变量

把二进制命令的路径加入系统path
说明:在末尾增加以下命令

[root@localhost apache-zookeeper-3.6.1-bin]# vi /etc/profile

# zookeeper
export ZK_HOME=/home/work/zookeeper/apache-zookeeper-3.6.1-bin
export PATH=$ZK_HOME/bin:$PATH

生效

[root@localhost apache-zookeeper-3.6.1-bin]# source /etc/profile
[root@localhost apache-zookeeper-3.6.1-bin]# 

启动和停止zookeeper

  • 启动 zkServer.sh start
  • 停止 zkServer.sh stop
[root@localhost apache-zookeeper-3.6.1-bin]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/work/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost apache-zookeeper-3.6.1-bin]# zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /home/work/zookeeper/apache-zookeeper-3.6.1-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@localhost apache-zookeeper-3.6.1-bin]# 

增加systemd管理

新建service文件

创建systemd文件

[root@localhost apache-zookeeper-3.6.1-bin]# vi /etc/systemd/system/zookeeper.service
[root@localhost apache-zookeeper-3.6.1-bin]# 

插入内容

[Unit]
Description=zookeeper.service After=network.target
ConditionPathExists=/home/work/zookeeper/apache-zookeeper-3.6.1-bin/conf/zoo.cfg
[Service] Type=forking User=root Group=root
ExecStart=/home/work/zookeeper/apache-zookeeper-3.6.1-bin/bin/zkServer.sh
start
ExecStop=/home/work/zookeeper/apache-zookeeper-3.6.1-bin/bin/zkServer.sh
stop [Install] WantedBy=multi-user.target

使用systemctl启动zookeeper失败

直接使用systemctl启动zookeeper会因找不到java的路径报错

[root@localhost apache-zookeeper-3.6.1-bin]# systemctl start zookeeper
Job for zookeeper.service failed because the control process exited
with error code. See “systemctl status zookeeper.service” and
“journalctl -xe” for details.

我们需要手动修改zkEnv.sh文件:

[root@localhost apache-zookeeper-3.6.1-bin]# vi bin/zkEnv.sh 

编辑的内容:
增加在 ZOOBINDIR 前面即可

JAVA_HOME=/home/work/java/jdk1.8.0_191

ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."

测试systemctl的管理:

  • 启动 systemctl start zookeeper
  • 停止 systemctl stop zookeeper
[root@localhost apache-zookeeper-3.6.1-bin]# systemctl start zookeeper
[root@localhost apache-zookeeper-3.6.1-bin]# systemctl stop zookeeper

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

[root@localhost conf]# echo stat|nc 127.0.0.1 2181
stat is not executed because it is not in the whitelist.
说明:需要解决上面这个报错

[root@localhost 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}"
继续测试

[root@localhost conf]# systemctl stop zookeeper
[root@localhost conf]# systemctl start zookeeper
[root@localhost 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:413520

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端口
zoo.cfg中添加如下一行:

admin.enableServer=false

admin.enableServer=false

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页