linux安装配置zookeeper-3.4.10

zookeeper 专栏收录该内容
1 篇文章 0 订阅

1.环境介绍

本次实验采用三台虚拟机(必须为 奇数个),操作系统为centos6.4
1
[hadoop@hadoop1 conf]$ cat /etc/redhat-release 
2
CentOS release 6.4 (Final)
3
[hadoop@hadoop1 conf]$ uname -a
4
Linux hadoop1 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
三台机器已经做了ssh互信,具体IP地址主机名如下:
1
[hadoop@hadoop1 conf]$ cat /etc/hosts
2
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
3
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
4
192.168.56.15 basic
5
192.168.56.1 PC-201306171517
6
192.168.56.21 hadoop1
7
192.168.56.22 hadoop2
8
192.168.56.23 hadoop3
9

2.下载zookeeper

zookeeper下载地址如下:
我这里选择stable版本3.4.10.

3.解压缩zookeeper

只需要先在一台机器上做安装配置,再将目录拷贝到其它主机上.在主机hadoop1上解压缩zookeeper
1
[hadoop@hadoop1 soft]$ tar zxvf zookeeper-3.4.10.tar.gz 
2
zookeeper-3.4.10/
3
zookeeper-3.4.10/LICENSE.txt
4
zookeeper-3.4.10/lib/
5
zookeeper-3.4.10/lib/log4j-1.2.16.LICENSE.txt
6
zookeeper-3.4.10/lib/cobertura/
7
zookeeper-3.4.10/lib/cobertura/README.txt
8
zookeeper-3.4.10/lib/jline-0.9.94.LICENSE.txt
9
...
10
zookeeper-3.4.10/bin/zkServer.sh
11
zookeeper-3.4.10/bin/zkCli.cmd
12
zookeeper-3.4.10/bin/zkEnv.cmd
13
zookeeper-3.4.10/ivysettings.xml
将解压缩后的文件夹拷贝到安装目录中:
1
[hadoop@hadoop1 soft]$ mv zookeeper-3.4.10 /hadoop/zookeeper/

4.配置zookeeper

将默认的配置文件zoo_sample.cfg改名为zoo.cfg
1
[hadoop@hadoop1 conf]$ pwd
2
/hadoop/zookeeper/conf
3
[hadoop@hadoop1 conf]$ mv zoo_sample.cfg zoo.cfg
修改配置文件zoo.cfg:
1
[hadoop@hadoop1 conf]$ vi zoo.cfg
2
3
# The number of milliseconds of each tick
4
tickTime=2000
5
# The number of ticks that the initial 
6
# synchronization phase can take
7
initLimit=10
8
# The number of ticks that can pass between 
9
# sending a request and getting an acknowledgement
10
syncLimit=5
11
# the directory where the snapshot is stored.
12
# do not use /tmp for storage, /tmp here is just 
13
# example sakes.
14
dataDir=/hadoop/zookeeper/data      ###################这里是zookeeper快照目录,建议根据实际修改
15
# the port at which the clients will connect
16
clientPort=2181
17
# the maximum number of client connections.
18
# increase this if you need to handle more clients
19
#maxClientCnxns=60
20
server.1=hadoop1:2888:3888          ####################server.1中的1是id,后面是主机名和端口号
21
server.2=hadoop2:2888:3888
22
server.3=hadoop3:2888:3888
23
#
24
# Be sure to read the maintenance section of the 
25
# administrator guide before turning on autopurge.
26
#
27
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
28
#
29
# The number of snapshots to retain in dataDir
30
#autopurge.snapRetainCount=3
31
# Purge task interval in hours
32
# Set to "0" to disable auto purge feature
33
#autopurge.purgeInterval=1
34
根据zoo.cfg创建zookeeper快照目录
1
[hadoop@hadoop1 conf]$ mkdir /hadoop/zookeeper/data
在data目录中新建myid文件,文件内容为server.id中的id号
1
[hadoop@hadoop1 data]$ pwd
2
/hadoop/zookeeper/data
3
[hadoop@hadoop1 data]$ echo "1" > myid

5.其它节点安装

其它节点安装只需要将整个zookeeper目录拷贝到相同的文件夹下面,并且修改data下的myid文件,修改为各自的id:
1
[hadoop@hadoop2 hadoop]$ pwd
2
/hadoop
3
[hadoop@hadoop2 hadoop]$ scp -r hadoop1:/hadoop/zookeeper .
4
[hadoop@hadoop2 hadoop]$ cd /hadoop/zookeeper/data
5
[hadoop@hadoop2 hadoop]$ echo "2" > myid

6.启动zookeeper

为了方便可以将zookeeper的可执行文件目录添加到PATH环境变量中:
1
PATH=/hadoop/zookeeper/bin:$HIVE_HOME/bin:/hadoop/pig/bin:$JAVA_HOME/bin:$PATH:$HOME/bin:/hadoop/hadoop/bin:/hadoop/hadoop/sbin
分别在每个节点上执行zkServer.sh start:
1
[hadoop@hadoop3 data]$ zkServer.sh start
2
ZooKeeper JMX enabled by default
3
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
4
Starting zookeeper ... STARTED
查看zookeeper的状态,可以发现一个是leader,其它两个是follower:
1
[hadoop@hadoop3 data]$ zkServer.sh status
2
ZooKeeper JMX enabled by default
3
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
4
Mode: follower
1
[hadoop@hadoop1 data]$ zkServer.sh status
2
ZooKeeper JMX enabled by default
3
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
4
Mode: follower
1
[hadoop@hadoop2 hadoop]$ zkServer.sh status
2
ZooKeeper JMX enabled by default
3
Using config: /hadoop/zookeeper/bin/../conf/zoo.cfg
4
Mode: leader
查看进程信息:
1
[hadoop@hadoop2 hadoop]$ jps
2
2065 Jps
3
1962 QuorumPeerMain

7.连接zookeeper集群

使用 zkCli.sh -server IP:PORT来连接zookeeper集群,具体语法如下:
1
[hadoop@hadoop1 data]$ zkCli.sh -server 127.0.0.1:2181
2
Connecting to 127.0.0.1:2181
3
2017-09-04 21:39:29,785 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
4
2017-09-04 21:39:29,788 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=hadoop1
5
2017-09-04 21:39:29,789 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_131
6
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
7
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.8.0_131/jre
8
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/hadoop/zookeeper/bin/../build/classes:/hadoop/zookeeper/bin/../build/lib/*.jar:/hadoop/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/hadoop/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/hadoop/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/hadoop/zookeeper/bin/../lib/log4j-1.2.16.jar:/hadoop/zookeeper/bin/../lib/jline-0.9.94.jar:/hadoop/zookeeper/bin/../zookeeper-3.4.10.jar:/hadoop/zookeeper/bin/../src/java/lib/*.jar:/hadoop/zookeeper/bin/../conf:
9
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
10
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
11
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
12
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
13
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
14
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-358.el6.x86_64
15
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hadoop
16
2017-09-04 21:39:29,791 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hadoop
17
2017-09-04 21:39:29,792 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/hadoop/zookeeper/data
18
2017-09-04 21:39:29,796 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@506c589e
19
Welcome to ZooKeeper!
20
2017-09-04 21:39:29,899 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
21
JLine support is enabled
22
2017-09-04 21:39:30,093 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
23
[zk: 127.0.0.1:2181(CONNECTING) 0] 2017-09-04 21:39:30,223 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15e4d06c91b0000, negotiated timeout = 30000
24
25
WATCHER::
26
27
WatchedEvent state:SyncConnected type:None path:null
使用help可以查看相关命令帮助:
1
[zk: 127.0.0.1:2181(CONNECTED) 0] help
2
ZooKeeper -server host:port cmd args
3
    stat path [watch]
4
    set path data [version]
5
    ls path [watch]
6
    delquota [-n|-b] path
7
    ls2 path [watch]
8
    setAcl path acl
9
    setquota -n|-b val path
10
    history 
11
    redo cmdno
12
    printwatches on|off
13
    delete path [version]
14
    sync path
15
    listquota path
16
    rmr path
17
    get path [watch]
18
    create [-s] [-e] path data acl
19
    addauth scheme auth
20
    quit 
21
    getAcl path
22
    close 
23
    connect host:port
24
[zk: 127.0.0.1:2181(CONNECTED) 1] 
25





























  • 0
    点赞
  • 1
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值