docker 安装zookeeper 与进入基本操作

1、查找docker镜像

# 查看本地镜像
docker images
# 检索ZooKeeper 镜像
docker search zookeeper
# 拉取ZooKeeper镜像最新版本
docker pull zookeeper:latest
# 我使用的版本
docker pull zookeeper:3.4.9

2、创建zookeeper挂载目录

mkdir -p /mydata/zookeeper/data # 数据挂载目录
mkdir -p /mydata/zookeeper/conf # 配置挂载目录
mkdir -p /mydata/zookeeper/logs # 日志挂载目录

3、添加 ZooKeeper 配置文件,在挂载配置文件目录(/mydata/zookeeper/conf)下,新增zoo.cfg 配置文件

cd /mydata/zookeeper/conf
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=/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
#metricsProvider.exportJvmInfo=true

4、启动zookeeper

docker run -d \
--name zookeeper \
--privileged=true \
-p 2181:2181 \
--restart=always \
-v /mydata/zookeeper/data:/data \
-v /mydata/zookeeper/conf:/conf \
-v /mydata/zookeeper/logs:/datalog \
zookeeper:3.4.9

5、进入zookeeper容器

docker exec -it zookeeper /bin/bash

6、启动zookeeper客服端

zkCli.sh

7、基本操作

 get /node:获取节点值

 ls /node:列出节点

 delete /node 删除节点

 stat:查看节点信息

setAct path acl:用于设置节点访问权限

getAcl path :查看节点的权限信息

你可能感兴趣的:(docker,java-zookeeper,zookeeper)