3台机器部署zookeeper-3.4.10集群

一. 环境介绍

三台主机,主机名和ip分别为:
ubuntu1  10.3.19.171
ubuntu2  10.3.19.172
ubuntu3  10.3.19.173
三台主机的登录用户名是bigdata,home目录是/home/bigdata
现在三台主机上部署zookeeper集群。

二.在ubuntu1机器上安装zookeeper

1. 解压复制安装包

bigdata@ubuntu1:~/download$ tar -zxvf zookeeper-3.4.10.tar.gz
bigdata@ubuntu1:~/download$ mv zookeeper-3.4.10 ../run/
bigdata@ubuntu1:~/download$ cd ../run/
bigdata@ubuntu1:~/run$ ln -s zookeeper-3.4.10 zookeeper

2. 修改配置文件

bigdata@ubuntu1:~/run/zookeeper/conf$ pwd
/home/bigdata/run/zookeeper/conf
bigdata@ubuntu1:~/run/zookeeper/conf$ ls
configuration.xsl  log4j.properties  zoo_sample.cfg
bigdata@ubuntu1:~/run/zookeeper/conf$ cp zoo_sample.cfg zoo.cfg 

创建tmp目录

bigdata@ubuntu1:~/run/zookeeper/conf$ mkdir /home/bigdata/run/zookeeper/dataDir

修改zoo.cfg配置文件,内容如下:
bigdata@ubuntu1:~/run/zookeeper/conf$ cat 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/bigdata/run/zookeeper/dataDir
# 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=10.3.19.171:2888:3888
server.2=10.3.19.172:2888:3888
server.3=10.3.19.173:2888:3888
bigdata@ubuntu1:~/run/zookeeper/conf$ 

创建myid文件,如下:
bigdata@ubuntu1:~/run/zookeeper/conf$ touch /home/bigdata/run/zookeeper/dataDir/myid

因为ubuntu1是server.1 所以myid中的值为1, 如下:
bigdata@ubuntu1:~/run/zookeeper/conf$ cat /home/bigdata/run/zookeeper/dataDir/myid
1
bigdata@ubuntu1:~/run/zookeeper/conf$

至此, 在ubunt1上安装zookeeper已完毕,接着在ubuntu2 和ubuntu3上安装zookeeper。

3. 在ubuntu2 ubuntu3机器上安装zookeeper

为了安装配置方便,直接将ubuntu1上已安装好的zookeeper, 打包后拷贝到ubuntu2 ubuntu3机器上, 如下:
bigdata@ubuntu1:~/run$ tar -zcvf zookeeper-3.4.10.tar.gz zookeeper-3.4.10/
bigdata@ubuntu1:~/run$ scp zookeeper-3.4.10.tar.gz ubuntu2:/home/bigdata/run/
bigdata@ubuntu1:~/run$ scp zookeeper-3.4.10.tar.gz ubuntu3:/home/bigdata/run/


   
   
在ubuntu2 ubuntu3上将其解压,并创建软件连接。ubuntu2上操作如下,ubuntu3类似


bigdata@ubuntu2:~/run$ tar -zxvf zookeeper-3.4.10.tar.gz
bigdata@ubuntu2:~/run$ ln -s zookeeper-3.4.10 zookeeper

修改ubuntu2中,zookeeper的配置文件, 将/home/bigdata/run/zookeeper/dataDir/myid值修改为2
bigdata@ubuntu2:~/run/zookeeper/dataDir$ cat /home/bigdata/run/zookeeper/dataDir/myid   
2

修改ubuntu3中,zookeeper的配置文件, 将/home/bigdata/run/zookeeper/dataDir/myid值修改为3
bigdata@ubuntu2:~/run/zookeeper/dataDir$ cat /home/bigdata/run/zookeeper/dataDir/myid   
3

至此,zookeeper已安装到了ubuntu1  ubuntu2  ubuntu3 三台机器上。

4. 启动zookeeper

在 三台机器上分别执行执动脚本:
bigdata@ubuntu1:~/run/zookeeper/bin$ ./zkServer.sh status
查看zookeeper状态:
bigdata@ubuntu1:~/run/zookeeper/bin$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/bigdata/run/zookeeper/bin/../conf/zoo.cfg
Mode: follower
停止zookeeper
bigdata@ubuntu1:~/run/zookeeper/bin$ ./zkServer.sh stop

a. 查看状态时,可能报错如下, 其原因是其它的两台机器的zookeeper未启动

bigdata@ubuntu1:~/run/zookeeper/bin$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/bigdata/run/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
启动另外两台机器的zookeeper, 即没有此报错。









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值