下载
搜索apache ,进入apache官网(https://www.apache.org/)下载
选择downloads 下的distribution
点击archive site
找到zookeeper目录
找到3.5.6目录
选择二进制 包 下载 apache-zookeeper-3.5.6-bin.tar.gz
注:下面那个非二进制包,安装后无法启动会报错: 找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain
基础环境:
三台centos7机器 :BigData01、BigData02、BigData03
java :JDK 1.8
二进制(源码包编译之后的)安装包:apache-zookeeper-3.5.6-bin.tar.gz
安装包存放路径 : /opt/software
解压路径 : /opt/modules/
部署:在bigdata01、bigdata02、bigdata03三台机器上都安装zookeeper集群
安装
在bigdata01上解压
cd /opt/sofeware tar -zxf apache-zookeeper-3.5.6-bin.tar.gz -C /opt/modules/
重命名
cd /opt/modules/mv apache-zookeeper-3.5.6-bin zookeeper-3.5.6
修改配置文件
复制/opt/modules/zookeeper-3.5.6/conf/zoo_sample.cfg为zoo.cfg
cd /opt/modules/zookeeper-3.5.6/conf cp zoo_sample.cfg zoo.cfg
修改zoo.cfg
设置zookeeper文件存放目录
dataDir=/opt/modules/ zookeeper-3.5.6/data/zData
指定zookeeper集群中各个机器的信息
server后面的数字范围是1到255,一个zookeeper集群最多有255个机器。
server.1=bigdata01:2888:3888
server.2=bigdata02:2888:3888
server.3=bigdata03:2888:3888
vi 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. # 设置zookeeper文件存放目录 dataDir=/opt/modules/zookeeper-3.5.6/data/zData # 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 # 指定zookeeper集群中各个机器的信息 server.1=bigdata01:2888:3888 server.2=bigdata02:2888:3888 server.3=bigdata03:2888:3888
创建myid文件
在dataDir所指定的目录(/opt/modules/zookeeper-3.5.6/data/zData)下创一个名为myid的文件,文件内容为server点后面的数字。
cd /opt/modules/zookeeper-3.5.6/ mkdir -p data/zData echo 1 > /opt/modules/zookeeper-3.5.6/data/zData/myid cat /opt/modules/zookeeper-3.5.6/data/zData/myid
分发到bigdata02、bigdata03
scp -r /opt/modules/zookeeper-3.5.6 bigdata02:/opt/modules
scp -r /opt/modules/zookeeper-3.5.6 bigdata03:/opt/modules
修改bigdata02、bigdata03上的myid文件
bigdata02上操作:
echo 2 >/opt/modules/zookeeper-3.5.6/data/zData/myid cat /opt/modules/zookeeper-3.5.6/data/zData/myid
bigdata03上操作:
echo 3 >/opt/modules/zookeeper-3.5.6/data/zData/myid cat /opt/modules/zookeeper-3.5.6/data/zData/myid
启动zookeeper
在各个机器上分别启动zookeeper
bigdata01上操作:
cd /opt/modules/zookeeper-3.5.6 bin/zkServer.sh start
bigdata02上操作:
cd /opt/modules/zookeeper-3.5.6 bin/zkServer.sh start
bigdata03上操作:
cd /opt/modules/zookeeper-3.5.6 bin/zkServer.sh start
zookeeper命令
zookeeper类似一个小型的文件系统,/是根目录,下面的所有节点都叫zNode。
进入zk shell 后输入任意字符,可以列出所有的zookeeper命令。
进入zkshell 界面(在任意一台机器执行都可以。)
cd /opt/modules/zookeeper-3.5.6 bin/zkCli.sh
创建一个zNode
create /znode_test "demodata"
查询zNode上的数据
get /znode_test
列出所有zNode:
ls /
删除znode
rmr /znode_test
提示已被弃用(但是还是可以用),使用deleteall
再建一个,用deleteall删除
create /znode_test "demodata" deleteall /znode_test
退出shell模式
quit