3台机器部署zookeeper-3.4.10集群

来源:互联网 发布:福岛 知乎 编辑:程序博客网 时间:2024/05/07 10:11

一. 环境介绍

三台主机,主机名和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/confbigdata@ubuntu1:~/run/zookeeper/conf$ lsconfiguration.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 ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=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 connectclientPort=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=1server.1=10.3.19.171:2888:3888server.2=10.3.19.172:2888:3888server.3=10.3.19.173:2888:3888bigdata@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/myid1bigdata@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 statusZooKeeper JMX enabled by defaultUsing config: /home/bigdata/run/zookeeper/bin/../conf/zoo.cfgMode: follower
停止zookeeper
bigdata@ubuntu1:~/run/zookeeper/bin$ ./zkServer.sh stop

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

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









0 0
原创粉丝点击