zookeeper 安装模式有三种:单机模式:单机单 server;集群模式:多机多 server,形成集群;伪集群模式:单机多 server,形成伪集群。 ~ 本篇内容包括:Zookeeper 官网下载、Zookeeper 单机模式部署、Zookeeper 集群安装、Zookeeper 集群安装
文章目录
代码语言:txt复制- [一、Zookeeper 官网下载](https://cloud.tencent.com/developer)
- [二、Zookeeper 单机模式部署](https://cloud.tencent.com/developer)
- [1、安装 JDK](https://cloud.tencent.com/developer)
- [2、安装 Zookeeper](https://cloud.tencent.com/developer)
- [3、修改 Zookpeeper 配置](https://cloud.tencent.com/developer)
- [4、运行 Zookeeper](https://cloud.tencent.com/developer)
- [三、Zookeeper 集群安装](https://cloud.tencent.com/developer)
- [1、安装JDK(每一台服务器);](https://cloud.tencent.com/developer)
- [2、安装 Zookeeper](https://cloud.tencent.com/developer)
- [3、修改 Zookpeeper 配置](https://cloud.tencent.com/developer)
- [4、运行 Zookeeper](https://cloud.tencent.com/developer)
- [四、Zookeeper 集群启动停止脚本](https://cloud.tencent.com/developer)
一、Zookeeper 官网下载
进入官网下载 Zookeeper,这里我们使用的版本为 Zookeeper-3.5.7
Zookeeper 官网地址: http://zookeeper.apache.org/
zookeeper 安装模式有三种:单机模式:单机单 server;集群模式:多机多 server,形成集群;伪集群模式:单机多 server,形成伪集群。
二、Zookeeper 单机模式部署
1、安装 JDK
安装JDK
可以参照:Java基础:Java程序设计环境
2、安装 Zookeeper
官网下载
拷贝 apache-zookeeper-3.5.7-bin.tar.gz
到 Linux系统下
解压到指定目录:
代码语言:javascript复制tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
改名
代码语言:javascript复制mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
3、修改 Zookpeeper 配置
进入conf目录
mv zoo_sample.cfg zoo.cfg
mkdir /opt/module/zookeeper-3.5.7/zkData
vi zoo.cfg
代码语言:javascript复制# 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/module/zookeeper-3.5.7/zkData
# 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
4、运行 Zookeeper
启动Zookeeper:bin/zkServer.sh start
查看进程:jps
客户端访问:bin/zkCli.sh
三、Zookeeper 集群安装
1、安装JDK(每一台服务器);
安装JDK
可以参照:Java基础:Java程序设计环境
2、安装 Zookeeper
拷贝 apache-zookeeper-3.5.7-bin.tar.gz
到 Linux系统下(每一台服务器)
解压到指定目录(每一台服务器):
代码语言:javascript复制tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
改名(每一台服务器)
代码语言:javascript复制mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
3、修改 Zookpeeper 配置
进入conf目录(每一台服务器)
mv zoo_sample.cfg zoo.cfg
(每一台服务器)
mkdir /opt/module/zookeeper-3.5.7/zkData
(每一台服务器)
vi /opt/module/zookeeper-3.5.7/zkData/myid
,填写每天服务器对应的 ID
vi zoo.cfg
(每一台服务器)
代码语言:javascript复制# 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/module/zookeeper-3.5.7/zkData
# 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
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
4、运行 Zookeeper
启动服务:每台机器执行:bin/zkServer.sh start
查看每个节点状态:bin/zkServer.sh status
四、Zookeeper 集群启动停止脚本
代码语言:javascript复制#!/bin/bash
case $1 in
"start"){
for i in master slave1 slave2
do
echo ----- zookeeper $i 启动-----
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh start"
done
}
;;
"stop"){
for i in master slave1 slave2
do
echo ----- zookeeper $i 停止-----
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"
done
}
;;
"status"){
for i in master slave1 slave2
do
echo ----- zookeeper $i 状态-----
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"
done
}
;;
esac