Centos7下Zookeeper-3.4.6安装

本文详细介绍了如何在CentOS7环境下使用Zookeeper-3.4.6进行安装部署,并通过脚本实现自动化运维。包括解压、配置、启动与关闭Zookeeper服务器,以及解决执行shell脚本时遇到的Dos格式文件问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Zookeeper-3.4.6 安装部署

注:Centos 7 环境搭建,可参考文章http://blog.youkuaiyun.com/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格式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值