[ 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
相关推荐
我命由我1234527 分钟前
Spring Boot 自定义日志打印(日志级别、logback-spring.xml 文件、自定义日志打印解读)
java·开发语言·jvm·spring boot·spring·java-ee·logback
杉之5 小时前
常见前端GET请求以及对应的Spring后端接收接口写法
java·前端·后端·spring·vue
canonical_entropy7 小时前
Nop入门-如何通过配置扩展服务函数的返回对象
spring·mvc·graphql
东阳马生架构7 小时前
zk基础—4.zk实现分布式功能
zookeeper
小李同学_LHY8 小时前
三.微服务架构中的精妙设计:服务注册/服务发现-Eureka
java·spring boot·spring·springcloud
非ban必选8 小时前
spring-ai-alibaba第四章阿里dashscope集成百度翻译tool
java·人工智能·spring
非ban必选8 小时前
spring-ai-alibaba第五章阿里dashscope集成mcp远程天气查询tools
java·后端·spring
爱喝醋的雷达10 小时前
Spring SpringBoot 细节总结
java·spring boot·spring
阁阁下12 小时前
springcloud configClient获取configServer信息失败导致启动configClient注入失败报错解决
后端·spring·spring cloud