一. 环境介绍
三台主机,主机名和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
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
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$
bigdata@ubuntu1:~/run/zookeeper/conf$ touch /home/bigdata/run/zookeeper/dataDir/myid
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/
在ubuntu2 ubuntu3上将其解压,并创建软件连接。ubuntu2上操作如下,ubuntu3类似bigdata@ubuntu1:~/run$ scp zookeeper-3.4.10.tar.gz ubuntu3:/home/bigdata/run/
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, 即没有此报错。