您的位置:首页 > 运维架构 > Linux

Centos7下Zookeeper-3.4.6安装

2016-01-07 16:30 495 查看

Zookeeper-3.4.6 安装部署

注:Centos 7 环境搭建,可参考文章http://blog.csdn.net/u011523533/article/details/50476931

解压压缩包(该压缩包位于文件夹zookeeper下)

$ tar -zxvf zookeeper-3.4.6.tar.gz


创建data,logs目录

$ cd zookeeper/
$ mkdri data
$ mkdir logs


配置Zookeeper

$ cd zookeeper-3.4.6/conf
$ cp zoo_sample.cfg zoo.cfg
$ vi zoo.cfg

各机器下,zoo.cfg配置内容
master:
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=/home/hadoop/zookeeper/data
dataLogDir=/home/hadoop/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
server.1=master:8880:7770
server.2=slave1:8880:7770
server.3=slave2:8880:7770

slave1:
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=/home/hadoop/zookeeper/data
dataLogDir=/home/hadoop/zookeeper/logs
# the port at which the clients will connect
clientPort=2182
server.1=master:8880:7770
server.2=slave1:8880:7770
server.3=slave2:8880:7770

192.168.192.13:
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=/home/hadoop/zookeeper/data
dataLogDir=/home/hadoop/zookeeper/logs
# the port at which the clients will connect
clientPort=2183
server.1=master:8880:7770
server.2=slave1:8880:7770
server.3=slave2:8880:7770


在刚才创建的data文件夹地下创建myid文件

$ vi myid

各节点myid文件内容如下
192.168.192.11:
1
192.168.192.12:
2
192.168.192.13:
3


各节点分别启动zookeeper

$ cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
$ ./zkServer.sh start

$ ./zkServer.sh status (查看状态)
$ ./zkServer.sh stop(关闭)


我这里写了各小脚本,方便在Master直接调用脚本启动Zookeeper和关闭Zookeeper

启动脚本如下:

#!/bin/bash
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
./zkServer.sh start
ssh -tt  hadoop@192.168.192.12 > /dev/null 2>&1  << remotessh
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
./zkServer.sh start
exit
remotessh

ssh -tt hadoop@192.168.192.13 > /dev/null 2>&1  << remotessh
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
./zkServer.sh start
exit
remotessh


关闭脚本如下:

#!/bin/bash
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
./zkServer.sh stop
ssh -tt  hadoop@192.168.192.12 > /dev/null 2>&1 << remotessh
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
./zkServer.sh stop
exit
remotessh

ssh -tt hadoop@192.168.192.13 > /dev/null 2>&1 << remotessh
cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
./zkServer.sh stop
exit
remotessh


注:使用脚本时,请先赋予脚本权限以及注意脚本文件格式

$ sudo chmod 777 脚本名称.sh


出现:

/bin/bash^M: bad interpreter: No such file or dire

在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识。 查看脚本文件是dos格式还是unix格式的几种办法。

(1)cat -A filename 从显示结果可以判断,dos格式的文件行尾为^M,unix格式的文件行尾为。

(2)od -t x1 filename 如果看到输出内容中存在0d 0a的字符,那么文件是dos格式,如果只有0a,则是unix格式。

(3)vi filename打开文件,执行 : set ff,如果文件为dos格式在显示为fileformat=dos,如果是unxi则显示为fileformat=unix。

解决方法:

(1)使用linux命令dos2unix filename,直接把文件转换为unix格式

(2)使用sed命令sed -i “s/\r//” filename 或者 sed -i “s/^M//” filename直接替换结尾符为unix格式

(3)vi filename打开文件,执行 : set ff=unix 设置文件为unix,然后执行:wq,保存成unix格式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  zookeeper centos