linux安装zookeeper

文章详细介绍了如何下载ApacheZooKeeper3.7.1稳定版,将其上传到Linux服务器,解压并配置数据目录和端口。接着,通过修改zoo.cfg文件启动服务,并使用zkCli.sh进行客户端连接。还提到了ZooInspector作为可视化工具的使用,以及如何处理远程连接问题和设置ZooKeeper为系统服务以实现开机启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

单机版

下载

地址:Apache ZooKeeper

这里选择3.7.1稳定版本。

 上传至linux服务器并解压

tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz

目录文件。

这里的data文件夹是自己创建的,为之后的数据目录使用。

配置

打开conf文件夹,复制 zoo_sample.cfg为zoo.cfg。

copy zoo_sample.cfg zoo.cfg

修改zoo.cfg。

vim zoo.cfg

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#数据目录
dataDir=/usr/local/zookeeper/apache-zookeeper-3.7.1/data
# the port at which the clients will connect
#运行端口
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000

主要修改数据目录和运行端口,dataDir,clientPort。

启动并测试

进入bin目录,执行启动命令。

./zkServer.sh start

停止服务命令为

./zkServer.sh stop

 本地客户端连接。

./zkCli.sh

 执行quit退出。

可视化页面

这里使用ZooInspector。

下载地址:https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip​​​​​​

解压后进入build目录,打开cmd命令,使用java -jar zookeeper-dev-ZooInspector.jar运行即可

输入ip和端口连接

远程连接不上可能是因为linux虚拟机防火墙问题,关闭防火墙:systemctl stop firewalld

注册为服务并设置开机启动

打开etc/systemd/system目录,创建并修改zookeeper.service文件

vim zookeeper.service
[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment=ZOO_LOG_DIR=/usr/local/zookeeper/apache-zookeeper-3.7.1/logs
Environment=JAVA_HOME=/usr/local/jdk/jdk1.8.0_341
PIDFile=/usr/local/zookeeper/apache-zookeeper-3.7.1/data/zookeeper_server.pid
ExecStart=/usr/local/zookeeper/apache-zookeeper-3.7.1/bin/zkServer.sh start
ExecReload=/usr/local/zookeeper/apache-zookeeper-3.7.1/bin/zkServer.sh restart
ExecStop=/usr/local/zookeeper/apache-zookeeper-3.7.1/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target

执行systemctl daemon-reload刷新,然后就可以service zookeeper start命令启动了,关闭时service zookeeper stop

设置为开机自启动:systemctl enable zookeeper.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值