zookeeper单机模式和伪分布式集群的搭建

选择版本下载并解压

apache-zookeeper-3.5.7-bin.tar.gz

单机模式

tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /usr/local/zookeeper

创建data目录,将conf下的zoo_sample.cfg改名为zoo.cfg 

mkdir /usr/local/zookeeper/data

cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg

配置zookeeper的dataDir路径和clientPort

vi /usr/local/zookeeper/conf/zoo.cfg

dataDir=/usr/local/zookeeper/data

clientPort=2181

进入到zookeeper的bin下

./zkServer.sh start

 单机模式搭建完成

伪分布式集群

集群搭建

jdk

检索自带jdk: rpm -qa | grep jdk

卸载jdk: yum -y remove java-1.8*

下载jdk并解压

配置环境变量: vi /etc/bashrc

export JAVA_HOME=/opt/jdk/jdk1.8
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

刷新环境变量:source /etc/bashrc

zookeeper

tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /usr/local/zookeeper-cluster

进入/usr/local/zookeeper-cluster下

将解压后的文件存放到三个路径

cp -r zookeeper3.5.7/ /usr/local/zookeeper-cluster/zookeeper1

cp -r zookeeper3.5.7/ /usr/local/zookeeper-cluster/zookeeper2

cp -r zookeeper3.5.7/ /usr/local/zookeeper-cluster/zookeeper3

创建data目录,将conf下的zoo_sample.cfg改名为zoo.cfg

mkdir /usr/local/zookeeper-cluster/zookeeper1/data

mkdir /usr/local/zookeeper-cluster/zookeeper2/data

mkdir /usr/local/zookeeper-cluster/zookeeper3/data

cp /usr/local/zookeeper-cluster/zookeeper1/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper1/conf/zoo.cfg

cp /usr/local/zookeeper-cluster/zookeeper2/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper2/conf/zoo.cfg

cp /usr/local/zookeeper-cluster/zookeeper3/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper3/conf/zoo.cfg

配置每个zookeeper的dataDir路径和clientPort(2181,2182,2183)

vi /usr/local/zookeeper-cluster/zookeeper1/conf/zoo.cfg

dataDir=/usr/local/zookeeper-cluster/zookeeper1/data

clientPort=2181

vi /usr/local/zookeeper-cluster/zookeeper2/conf/zoo.cfg

dataDir=/usr/local/zookeeper-cluster/zookeeper2/data

clientPort=2182

vi /usr/local/zookeeper-cluster/zookeeper3/conf/zoo.cfg

dataDir=/usr/local/zookeeper-cluster/zookeeper3/data

clientPort=2183

集群配置

在每个zookeeper的data目录下创建myid文件,内容分别为1,2,3.记录每个服务器的id

echo 1 > /usr/local/zookeeper-cluster/zookeeper1/data/myid

echo 2 > /usr/local/zookeeper-cluster/zookeeper2/data/myid

echo 3 > /usr/local/zookeeper-cluster/zookeeper3/data/myid

在每个zookeeper的zoo.cfg文件中配置集群服务器ip列表和客户端访问端口

server.id=ip:服务器通信端口:服务器选举端口

server.1=192.168.227.141:2188:3888

server.2=192.168.227.141:2189:3889

server.3=192.168.227.141:2190:3890

集群启动

启动:

/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh start

/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh start

/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh start

脚本控制

zkStart.sh

#!bin/bash
/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh start
/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh start
/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh start

zkStop.sh

#!bin/bash
/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh stop
/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh stop
/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh stop

zkStatus.sh

#!bin/bash
/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh status
/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh status
/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh status

zkRestart.sh

#!bin/bash
/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh stop
/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh stop
/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh stop
/usr/local/zookeeper-cluster/zookeeper1/bin/zkServer.sh start
/usr/local/zookeeper-cluster/zookeeper2/bin/zkServer.sh start
/usr/local/zookeeper-cluster/zookeeper3/bin/zkServer.sh start

使用sh/bash + 脚本名 启动

伪分布式集群搭建完成

 

 

 

 

你可能感兴趣的:(zookeeper,java-ee)