1下载:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz
一定要选择下载bin这个才是安装包,小的一个是源代码。
下载完成之后解压路径以及整个程序包的结构如下:(清楚整个文件的结构才能把对应的文件配置定位处理正确,因为有的命令没有使用绝对路径需要自己去调整命令)
tar -vzxf 解压的文件 -C 解压目标路径
2安装
每台机器需要更改的配置
1.vim /etc/hosts 这里设置集群内每一个服务器ip对应主机的别名 用于 zoo.cfg配置引用
#原有的内容或者其他内容
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#新增
192.168.251.99 zoo1
192.168.251.98 zoo2
192.168.251.97 zoo3
2.vim /etc/bashrc 增加关于zookeeper的bin目录 source /etc/bashrc
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=
P
A
T
H
:
PATH:
PATH:ZOOKEEPER_HOME/bin
3.java安装vim /etc/profile 环境变量 source /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
export PATH=
P
A
T
H
:
PATH:
PATH:JAVA_HOME/bin
export CLASSPATH=.:
J
A
V
A
H
O
M
E
/
l
i
b
/
d
t
.
j
a
r
:
JAVA_HOME/lib/dt.jar:
JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
4.zookeeper下面创建 data logs 两个文件夹 配置到zoo.cfg里面去(详见zoo.cfg配置)
5.data目录下面创建一个myid文件内容必须是zoo.cfg配置的服务器别名(△所有配置就这个需要特殊配置,其他都是一样的)
cat >myid (需要root权限)
1
ctrl+d 结束把内容写入文件
vim myid 确认内容是否正确
6.vim /opt/zookeeper/conf/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=/opt/zookeeper/data/
dataLogs=/opt/zookeeper/logs/
# the port at which the clients will connect 服务端端口默认是8080如果被占用需要重新指定
clientPort=2181
admin.serverPort=8800
# 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
#这里的1 2 3对一个的myid里面的内容 zoo1 zoo2 zoo3 对应hosts文件配置的 ip 映射别名
server.1=zoo1:2333:3888
server.2=zoo2:2333:3888
server.3=zoo3:2333:3888
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7.以上配置好之后使用scp复制到其他主机去
8.分别启动每一个机器 zkServer.sh start 启动 stop 关闭 status状态 restart 重启