您的位置:首页 > 其它

zookeeper伪分布式集群搭建

2017-02-26 01:16 274 查看
安装步骤
第一步上传zookeeper-348targz并解压

第二步配置zookeeper
1 在zookeeper01中创建一个 data的文件夹

2 在data中创建一个myid的文件

3 在myid文件的内容为1

4 zookeeper01zookeeper03依次类推

5 修改配置文件
51修改zookeeper01的配置文件

52修改zookeeper02的配置文件

53修改zookeeper03的配置文件

6 启动zookeeper集群

第三步 zookeeper启动脚本编写

出现错误的解决

安装步骤

第一步:上传zookeeper-3.4.8.tar.gz并解压

1. #usr/local/ 下创建zookeeper文件夹
[root@localhost /]# mkdir /usr/local/zookeeper
2. #解压tar:
tar -zxvf zookeeper-3.4.8.tar.gz
3. #usr/local/zookeeper/下复制三份解压后的文件:
[root@localhost donggua]# cp -r zookeeper-3.4.8 /usr/local/zookeeper/zookeeper01
[root@localhost donggua]# cp -r zookeeper-3.4.8 /usr/local/zookeeper/zookeeper02
[root@localhost donggua]# cp -r zookeeper-3.4.8 /usr/local/zookeeper/zookeeper03


第二步:配置zookeeper

2.1 在zookeeper01中创建一个 data的文件夹

[root@localhost zookeeper01]# mkdir data


2.2 在data中创建一个myid的文件

[root@localhost zookeeper01]# cd data/
[root@localhost data]# ls
[root@localhost data]#
[root@localhost data]#
[root@localhost data]# touch myid


2.3 在myid文件的内容为1

[root@localhost data]# vim myid #写入内容为1


2.4 zookeeper01、zookeeper03依次类推

zookeeper02:

[root@localhost zookeeper02]# mkdir data
[root@localhost zookeeper02]# cd data/
[root@localhost data]# touch myid
[root@localhost data]# echo 2 > myid
[root@localhost data]# vim myid


zookeeper03:

[root@localhost zookeeper03]# mkdir data
[root@localhost zookeeper03]# cd data/
[root@localhost data]# touch myid
[root@localhost data]# echo 3 > myid


2.5 修改配置文件

2.5.1修改zookeeper01的配置文件:

[root@localhost /]# cd /usr/local/zookeeper/zookeeper01/
[root@localhost zookeeper01]# ls
bin          data             lib                   recipes                  zookeeper-3.4.8.jar.sha1
build.xml    dist-maven       LICENSE.txt           src
CHANGES.txt  docs             NOTICE.txt            zookeeper-3.4.8.jar
conf         ivysettings.xml  README_packaging.txt  zookeeper-3.4.8.jar.asc
contrib      ivy.xml          README.txt            zookeeper-3.4.8.jar.md5

[root@localhost zookeeper01]# cd conf/  #进入zookeeper01的配置文件路径下
[root@localhost conf]# ll
total 12
-rw-r--r--. 1 root root  535 Feb 25 09:21 configuration.xsl
-rw-r--r--. 1 root root 2161 Feb 25 09:21 log4j.properties
-rw-r--r--. 1 root root  922 Feb 25 09:21 zoo_sample.cfg

[root@localhost conf]# cp zoo_sample.cfg  zoo.cfg #zoo_sample.cfg 复制一份 命名为:zoo.cfg
[root@localhost conf]# ll
total 16
-rw-r--r--. 1 root root  535 Feb 25 09:21 configuration.xsl
-rw-r--r--. 1 root root 2161 Feb 25 09:21 log4j.properties
-rw-r--r--. 1 root root  922 Feb 25 10:01 zoo.cfg
-rw-r--r--. 1 root root  922 Feb 25 09:21 zoo_sample.cfg
[root@localhost conf]# vim zoo.cfg

dataDir=/usr/local/zookeeper/zookeeper01/data/ #配置zookeeper01的data路径
clientPort=2181 #配置端口号
server.1=192.168.31.103:2881:3881 #配置三个zookeeper节点,注意端口号不能重复
server.2=192.168.31.103:2882:3882
server.3=192.168.31.103:2883:3883


2.5.2修改zookeeper02的配置文件:

同2.5.1 复制zoo_sample.cfg 一份 命名为:zoo.cfg

编辑如下内容:

dataDir=/usr/local/zookeeper/zookeeper02/data/ #配置zookeeper02的data路径
clientPort=2182 #配置端口号
server.1=192.168.31.103:2881:3881 #配置三个zookeeper节点,注意端口号不能重复
server.2=192.168.31.103:2882:3882
server.3=192.168.31.103:2883:3883


2.5.3修改zookeeper03的配置文件:

同2.5.1 复制zoo_sample.cfg 一份 命名为:zoo.cfg

编辑如下内容:

dataDir=/usr/local/zookeeper/zookeeper03/data/ #配置zookeeper03的data路径
clientPort=2183 #配置端口号
server.1=192.168.31.103:2881:3881 #配置三个zookeeper节点,注意端口号不能重复
server.2=192.168.31.103:2882:3882
server.3=192.168.31.103:2883:3883


2.6 启动zookeeper集群

[root@localhost zookeeper]# cd zookeeper01/bin/
[root@localhost bin]# ./zkServer.sh start #stuas 查看状态, stop 关闭
[root@localhost zookeeper]# cd zookeeper02/bin/
[root@localhost bin]# ./zkServer.sh start #stuas 查看状态, stop 关闭
[root@localhost zookeeper]# cd zookeeper03/bin/
[root@localhost bin]# ./zkServer.sh start #stuas 查看状态, stop 关闭


第三步 zookeeper启动脚本编写:

[root@localhost zookeeper]# vim zookeeper-start.sh

#!/bin/sh
cd zookeeper01/bin/
./zkServer.sh start
cd ../..
cd zookeeper02/bin/
./zkServer.sh start
cd ../..
cd zookeeper03/bin/
./zkServer.sh start
cd ../..


出现错误的解决:

查看状态时出现:

[root@localhost bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper01/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.


解决:

1. 是否关闭防火墙或者 端口是否开放

2. data/myid 的内容是否和当前节点是否匹配: zookeeper01-> 1,

zookeeper02 ->2, zookeeper03->3

3.conf/zoo.cfg中,端口号是否匹配。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: