搭建zookeeper集群

zookeeper集群

  • 下载zookeeper-3.4.14.tar.gz https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
  • 使用xshell的rz命令或者xftp工具将zookeeper-3.4.14.tar.gz压缩文件上传到三台主机的 /opt 目录下
  • 解压 zookeeper-3.4.14.tar.gz

    tar -zxvf zookeeper-3.4.14.tar.gz
  • 切换到zookeeper-3.4.14目录,创建data和log文件夹【三台机器都要创建】

    cd zookeeper-3.4.14
    mkdir data log
    ###############################################
    [root@hservice zookeeper-3.4.14]# ls -l
    总用量 1672
    drwxr-xr-x  2 2002 2002     202 3月   7 2019 bin
    -rw-rw-r--  1 2002 2002   97426 3月   7 2019 build.xml
    drwxr-xr-x  2 2002 2002      77 3月   7 2019 conf
    drwxr-xr-x  2 root root       6 9月  29 19:13 data
    drwxr-xr-x  2 2002 2002    4096 3月   7 2019 dist-maven
    -rw-rw-r--  1 2002 2002    1709 3月   7 2019 ivysettings.xml
    -rw-rw-r--  1 2002 2002   10742 3月   7 2019 ivy.xml
    drwxr-xr-x  4 2002 2002     308 3月   7 2019 lib
    -rw-rw-r--  1 2002 2002   11970 3月   7 2019 LICENSE.txt
    drwxr-xr-x  2 root root       6 9月  29 19:13 log
    -rw-rw-r--  1 2002 2002    3132 3月   7 2019 NOTICE.txt
    -rw-rw-r--  1 2002 2002   31622 3月   7 2019 pom.xml
    -rw-rw-r--  1 2002 2002    1765 3月   7 2019 README.md
    -rw-rw-r--  1 2002 2002    1770 3月   7 2019 README_packaging.txt
    drwxr-xr-x  3 2002 2002      22 3月   7 2019 src
    -rw-rw-r--  1 2002 2002 1515359 3月   7 2019 zookeeper-3.4.14.jar
    -rw-rw-r--  1 2002 2002     836 3月   7 2019 zookeeper-3.4.14.jar.asc
    -rw-rw-r--  1 2002 2002      33 3月   7 2019 zookeeper-3.4.14.jar.md5
    -rw-rw-r--  1 2002 2002      41 3月   7 2019 zookeeper-3.4.14.jar.sha1
    drwxr-xr-x  3 2002 2002      47 3月   7 2019 zookeeper-client
    drwxr-xr-x 12 2002 2002    4096 3月   7 2019 zookeeper-contrib
    drwxr-xr-x  7 2002 2002    4096 3月   7 2019 zookeeper-docs
    drwxr-xr-x  3 2002 2002      35 3月   7 2019 zookeeper-it
    drwxr-xr-x  4 2002 2002      46 3月   7 2019 zookeeper-jute
    drwxr-xr-x  5 2002 2002     176 3月   7 2019 zookeeper-recipes
    drwxr-xr-x  3 2002 2002      32 3月   7 2019 zookeeper-server
  • 切换到conf目录下, 复制zoo_sample.cfg 文件名为zoo.cfg

    cd conf
    [root@hservice conf]# ls
    configuration.xsl  log4j.properties  zoo_sample.cfg
    [root@hservice conf]# cp zoo_sample.cfg zoo.cfg 
    [root@hservice conf]# ls
    configuration.xsl  log4j.properties  zoo.cfg  zoo_sample.cfg
    [root@hservice conf]# 
  • 修改zoo.cfg文件
# 需要修改的文件
dataDir=/opt/zookeeper-3.4.14/data
dataLogDir=/opt/zookeeper-3.4.14/log
server.1=192.168.129.200:2888:3888
server.2=192.168.129.201:2888:3888
server.3=192.168.129.202:2888:3888

使用scp将修改完的zoo.cfg文件赋值到其它两台主机conf目录下

scp zoo.cfg root@node1:/opt/zookeeper-3.4.14/conf/
  • 为三台主机添加zookeeper环境变量

     ZOOKEEPER_HOME=/opt/zookeeper-3.4.14
     PATH=$PATH:$ZOOKEEPER_HOME/bin

启动zookeeper

# 三台都需要执行
/opt/zookeeper-3.4.14/bin
zkServer.sh  status # 查看状态
zkServer.sh  start # 启动zookeeper服务
####################################
zkCli.sh # 启动zookeeper工具,任意一台机器执行 
# DEMO
[root@hservice bin]# zkServer.sh 
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Usage: /opt/zookeeper-3.4.14/bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
[root@hservice bin]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
[root@hservice bin]# zkCli.sh 
Connecting to localhost:2181
2019-09-29 20:24:46,132 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
2019-09-29 20:24:46,136 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=hservice
2019-09-29 20:24:46,136 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_181
2019-09-29 20:24:46,138 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-09-29 20:24:46,138 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/opt/jdk1.8.0_181/jre
2019-09-29 20:24:46,138 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/opt/zookeeper-3.4.14/bin/../build/classes:/opt/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/opt/zookeeper-3.4.14/bin/../build/lib/*.jar:/opt/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/opt/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/opt/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/opt/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/opt/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/opt/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/zookeeper-3.4.14/bin/../conf:.:/opt/jdk1.8.0_181/lib/tools.jar:/opt/jdk1.8.0_181/jre/rt.jar
2019-09-29 20:24:46,138 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-09-29 20:24:46,138 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-09-29 20:24:46,139 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2019-09-29 20:24:46,139 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2019-09-29 20:24:46,141 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2019-09-29 20:24:46,142 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-862.el7.x86_64
2019-09-29 20:24:46,142 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2019-09-29 20:24:46,142 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2019-09-29 20:24:46,142 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.14/bin
2019-09-29 20:24:46,143 [myid:] - INFO  [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@255316f2
2019-09-29 20:24:46,175 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1025] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2019-09-29 20:24:46,440 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-09-29 20:24:46,458 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x6d7c4873940004, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper, hbase]
[zk: localhost:2181(CONNECTED) 1] 

添加新评论

已有 1 条评论

还可以,大佬厉害了,快把hadoop生态圈搭建好,然后分享!