[ Spring ] Install ZooKeeper on Ubuntu24

Install JDK

install a jdk into system dirs, so all users can visit

bash 复制代码
sudo apt install openjdk-17-jdk -y
bash 复制代码
java -version
Configure JAVA_HOME
bash 复制代码
sudo open /etc/profile

replace with you own path, pirnt by java command above

bash 复制代码
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
bash 复制代码
source /etc/profile
Create ZooKeeper User
bash 复制代码
sudo adduser --system --no-create-home --group zookeeper
Set Home Directory for User
bash 复制代码
sudo mkdir /opt/zookeeper
sudo chown zookeeper:zookeeper /opt/zookeeper
Create Data Directory for ZooKeeper
bash 复制代码
sudo mkdir /var/lib/zookeeper
sudo chown zookeeper:zookeeper /var/lib/zookeeper
Download ZooKeeper Package
bash 复制代码
cd /tmp
wget https://downloads.apache.org/zookeeper/zookeeper-3.9.3/apache-zookeeper-3.9.3-bin.tar.gz
Extract ZooKeeper to Install Directory
bash 复制代码
sudo tar -xzf apache-zookeeper-3.9.3-bin.tar.gz -C /opt/zookeeper --strip-components=1
Configure Directory Permission
bash 复制代码
sudo chown -R zookeeper:zookeeper /opt/zookeeper
Verify Installation Files

this directory should contains folders like bin, conf, lib

bash 复制代码
ls -l /opt/zookeeper
Configure ZooKeeper
bash 复制代码
sudo cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg
bash 复制代码
sudo nano /opt/zookeeper/conf/zoo.cfg
bash 复制代码
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
maxClientCnxns=60
admin.enableServer=true
admin.serverPort=20001
Create System Service for ZooKeeper
bash 复制代码
sudo nano /etc/systemd/system/zookeeper.service
bash 复制代码
[Unit]
Description=Apache ZooKeeper service
Documentation=http://zookeeper.apache.org
Requires=network.target
After=network.target

[Service]
Type=forking
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
ExecReload=/opt/zookeeper/bin/zkServer.sh restart
WorkingDirectory=/opt/zookeeper

[Install]
WantedBy=multi-user.target
bash 复制代码
sudo systemctl enable zookeeper
bash 复制代码
sudo systemctl stop zookeeper
sudo systemctl start zookeeper
sudo systemctl status zookeeper
Test ZooKeeper Service

if successful, you will see a ZooKeeper command line prompt

bash 复制代码
/opt/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
bash 复制代码
ls /

also, you can launch the admin webpage

bash 复制代码
http://localhost:20001/commands
Check Startup Failure

if service start up failed, print log to get a check

bash 复制代码
journalctl -u zookeeper
相关推荐
ldj202024 分钟前
SpringBoot项目打war包要点
java·spring boot·spring
青灯文案12 小时前
SpringBoot 项目中配置日志系统文件 logback-spring.xml 原理和用法介绍
spring boot·spring·logback
VX_CXsjNo15 小时前
免费送源码:Java+SpringBoot+MySQL SpringBoot网上宠物领养管理系统 计算机毕业设计原创定制
java·hadoop·spring boot·mysql·zookeeper·flask·pytest
keep one's resolveY8 小时前
SpringBoot Starter 通用接口加密组件(防篡改)+ RequestBodyAdvice和ResponseBodyAdvice原理
java·spring boot·spring
m0_748251529 小时前
基于SpringBoot和PostGIS的云南与缅甸的千里边境线实战
java·spring boot·spring
web1359560970510 小时前
开源模型应用落地-工具使用篇-Spring AI-Function Call(八)
人工智能·spring·开源
m0_7482526010 小时前
开源模型应用落地-工具使用篇-Spring AI-高阶用法(九)
人工智能·spring·开源
wu_yi_min17 小时前
Spring Web MVC综合案例
前端·spring·mvc
苏-言1 天前
SpringMVC 实战指南:文件上传
java·后端·spring