zookeeper(动物园管理员)是一个广泛应用于分布式服务提供协调服务Apache的开源框架
zookeeper由Java开发所有要运行zookeeper需要现安装jdk
可以下载免安装版jdk,解压后配置一下环境变量即可
linux下的环境变量配置文件在
/etc/profile
然后在该文件下增加如下配置即可
export JAVA_HOME=/usr/java/jdk-21/jdk-21.0.1 // 我自己的jdk目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
然后从新加载配置文件,命令为
source /etc/profile
查看Java版本
则表示已成功安装Jdk
进入zookeeper官网,找到下载页面,下载-bin.tar.gz版即可,如果没有想要的版本则可以在下载页面的存档连接中找到
tar -zxvf apache-zookeeper-3.5.7- bin.tar.gz -C /mydata/zookeeper
mv apache-zookeeper-3.5.7 -bin/ zookeeper-3.5.7
1、将/mydata/zookeeper/zookeeper-3.5.7/conf这个路径下的 zoo_sample.cfg 修改为 zoo.cfg;
mv zoo_sample.cfg zoo.cfg
2、打开 zoo.cfg 文件,修改 dataDir 配置的路径 修改为如下内容(默认的tmp路径是临时路径,一段时间后,linux会自动删除里面的文件,所有不适合正式环境使用)
dataDir=/mydata/zookeeper/zookeeper-3.5.7/data
3、在/mydata/zookeeper/zookeeper-3.5.7/这个目录上创建 data文件夹
1、启动 Zookeeper
3、查看状态
4、启动客户端
./zkCli.sh
5、退出客户端:
[zk: localhost:2181(CONNECTED) 0] quit
6、停止 Zookeeper
.bin/zkServer.sh stop
Zookeeper中的配置文件zoo.cfg中参数含义解读如下:
1)tickTime = 2000:通信心跳时间,Zookeeper服务器与客户端心跳时间,单位毫秒
Leader和Follower初始连接时能容忍的最多心跳数(tickTime的数量)
3)syncLimit = 5:LF同步通信时限
Leader和Follower之间通信时间如果超过syncLimit * tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。
4)dataDir:保存Zookeeper中的数据
注意:默认的tmp目录,容易被Linux系统定期删除,所以一般不用默认的tmp目录。
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="d7919ed1-15af-49fe-9b4e-aad1456eed3d"
DEVICE="ens33"
ONBOOT="yes"IPADDR=192.168.127.100
# wangGuan
GATEWAY=192.168.127.2
# DNS
DNS1=192.168.127.2
vim /etc/hostnamehadoop102
[root@hadoop100 ~]# vim /etc/hosts
192.168.127.100 hadoop100
192.168.127.101 hadoop101
192.168.127.102 hadoop102
192.168.127.103 hadoop103
192.168.127.104 hadoop104
192.168.127.105 hadoop105
192.168.127.106 hadoop106
192.168.127.107 hadoop107
192.168.127.108 hadoop108
192.168.127.132 qingmangmall
[root@hadoop100 ~]# reboot
192.168.127.100 hadoop100
192.168.127.101 hadoop101
192.168.127.102 hadoop102
192.168.127.103 hadoop103
192.168.127.104 hadoop104
192.168.127.105 hadoop105
192.168.127.106 hadoop106
192.168.127.107 hadoop107
192.168.127.108 hadoop108
192.168.127.132 qingmangmall
[user@hadoop102 ~]$ sudo chown user:user -R /mydata
[user@ hadoop102 ~]$ scp -r /mydata/zookeeper user@hadoop103:/mydata
100
scp -r /mydata/zookeeper/zookeeper-3.5.7/data user@hadoop103:/mydata/zookeeper/zookeeper-3.5.7
[user@hadoop102 conf]$ mv zoo_sample.cfg zoo.cfg
[user@hadoop102 conf]$ vim zoo.cfg
dataDir=/opt/module/zookeeper-3.5.7/zkData
#######################cluster##########################server.100=hadoop100:2888:3888server.103=hadoop103:2888:3888server.132=qingmangmall:2888:3888
[user@hadoop100 zookeeper-3.5.7]$ bin/zkServer.sh start[user@hadoop103 zookeeper-3.5.7]$ bin/zkServer.sh start[user@qingmangmall zookeeper-3.5.7]$ bin/zkServer.sh start
[user@hadoop100 zookeeper-3.5.7]# bin/zkServer.sh statusJMX enabled by defaultUsing config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfgMode: follower[user@hadoop103 zookeeper-3.5.7]# bin/zkServer.sh statusJMX enabled by defaultUsing config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfgMode: leader[user@qingmangmall zookeeper-3.5.7]# bin/zkServer.sh statusJMX enabled by defaultUsing config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfgMode: follower
[root@hadoop100 ~]# useradd user[root@hadoop100 ~]# passwd user
[root@hadoop100 ~]# vim /etc/sudoers
## Allow root to run any commands anywhereroot ALL=(ALL) ALL## Allows people in group wheel to run all commands% wheel ALL=(ALL) ALLuser ALL=(ALL) NOPASSWD:ALL
mkdir /mydata