Zookeeper学习记录 - linux下安装部署
Zookeeper学习记录 - linux下安装部署
【单机模式】
一、下载
二、解压
tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz
三、配置
新建如下文件夹:
mkdir /tmp/zookeeper/data
mkdir /tmp/zookeeper/log
配置
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
配置以下内容
dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
四、环境变量
vim /etc/profile
export ZOOKEEPER_INSTALL=/usr/local/zk/apache-zookeeper-3.6.1-bin/ export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
source profile
五、启动
#进入bin目录
cd /usr/local/zk/apache-zookeeper-3.6.1-bin/bin
#启动服务端
./zkServer.sh start
#启动客户端 ./zkCli.sh
【集群模式】
基本步骤同 单机模式
不同点:
一、创建myid
在 dataDir 目录下创建名为 myid 的文件,在文件第一行写上对应的 Server ID。
echo 1 > /tmp/zookeeper/data/myid echo 2 > /tmp/zookeeper/data/myid echo 3 > /tmp/zookeeper/data/myid
二、配置
# zk-conf tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zookeeper/data dataLogDir=/tmp/zookeeper/log clientPort=2181 server.1=IP1:2888:3888 server.2=IP2:2888:3888 server.3=IP3:2888:3888
三、运行结果
[root@VM-32-88-centos bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zk/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: leader
[root@VM-32-32-centos bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zk/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: follower
[root@VM-32-38-centos bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zk/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: follower
【基础命令】
#启动命令: zkServer.sh start #停止命令: zkServer.sh stop #重启命令: zkServer.sh restart #查看集群节点状态: zkServer.sh status
【验证】
[root@VM-32-88-centos bin]# zkCli.sh -server localhost:2181 Connecting to localhost:2181 [zk: localhost:2181(CONNECTED) 0] get / [zk: localhost:2181(CONNECTED) 1] create /user tom Created /user [zk: localhost:2181(CONNECTED) 2] [zk: localhost:2181(CONNECTED) 2] get /user tom [zk: localhost:2181(CONNECTED) 3] [zk: localhost:2181(CONNECTED) 3] get / [zk: localhost:2181(CONNECTED) 4] get /love baby [zk: localhost:2181(CONNECTED) 5]
参考资料
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步