• zookeeper单节点安装


    本文介绍zookeeper单节点安装。

    下载

    http://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/

    解压后,把conf中的zoo_sample.cfg复制一份成为zoo.cfg,修改一下里面的路径:

    启动zookeeper

    [work@xxx zookeeper-3.4.6]$ bin/zkServer.sh start
    JMX enabled by default
    Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED

    如果配置文件不是zoo.cfg,可以在start后面加上你指定的配置文件的名字

    查看状态

    [work@xxx zookeeper-3.4.6]$ bin/zkServer.sh status
    JMX enabled by default
    Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Error contacting service. It is probably not running.

    明明提示起来了,但是状态就不对,看了一下进程都没有起来。这时候看了网上各种文章,里面列出了一些解决方法:

    1、zoo.cfg配置文件中指定目录却没有创建,创建相应目录即可

    2、使用service iptables stop 关闭防火墙;使用service iptables status确认

    3、打开zkServer.sh 找到
    status)
        STAT=`echo stat | nc localhost $(grep clientPort "$ZOOCFG" | sed -e 's/.*=//') 2> /dev/null| grep Mode`
    在nc与localhost之间加上 -q 1 (是数字1而不是字母l),如果已存在则去掉

    4、2181端口被占用

    但是我遇到的情况都不是上面提到的,后面查到有个zookeeper.out的文件,里面会有一些log信息。

    查看zookeeper.out

    [work@xxx zookeeper-3.4.6]$cat zookeeper.out
    nohup: failed to run command `/usr/java/jdk1.8.0_65//bin/java': No such file or directory

    这里可以看到是系统的环境变量有问题了!!!

    查看系统环境变量

    [work@xxx zookeeper-3.4.6]$ export
    declare -x CVS_RSH="ssh"
    declare -x G_BROKEN_FILENAMES="1"
    declare -x HISTCONTROL="ignoredups"
    declare -x HISTSIZE="1000"
    declare -x HISTTIMEFORMAT="%F %T work "
    declare -x HOME="/home/work"
    declare -x JAVA_HOME="/usr/java/jdk1.8.0_65/"

    果然TM有问题!

    修改系统环境变量

    [work@xxx zookeeper-3.4.6]$ export JAVA_HOME=/usr

    再次启动zookeeper

    [work@xxx zookeeper-3.4.6]$ bin/zkServer.sh start
    JMX enabled by default
    Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED

    再次查看状态

    [work@xxx zookeeper-3.4.6]$ bin/zkServer.sh status
    JMX enabled by default
    Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Mode: standalone

    再次查看zookeeper.out

    [work@xxx zookeeper-3.4.6]$ cat zookeeper.out
    2018-01-05 20:29:36,745 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    2018-01-05 20:29:36,751 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
    2018-01-05 20:29:36,752 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
    2018-01-05 20:29:36,752 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
    2018-01-05 20:29:36,752 [myid:] - WARN  [main:QuorumPeerMain@113] - Either no config or no quorum defined in config, running  in standalone mode
    2018-01-05 20:29:36,767 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
    2018-01-05 20:29:36,767 [myid:] - INFO  [main:ZooKeeperServerMain@95] - Starting server
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:host.name=xxx
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:java.version=1.7.0_111
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/jre
    2018-01-05 20:29:36,776 [myid:] - INFO  [main:Environment@100] - Server environment:java.class.path=/home/work/soft/zookeeper-3.4.6/bin/../build/classes:/home/work/soft/zookeeper-3.4.6/bin/../build/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/work/soft/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/home/work/soft/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../conf:
    2018-01-05 20:29:36,777 [myid:] - INFO  [main:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
    2018-01-05 20:29:36,777 [myid:] - INFO  [main:Environment@100] - Server environment:java.io.tmpdir=/tmp
    2018-01-05 20:29:36,777 [myid:] - INFO  [main:Environment@100] - Server environment:java.compiler=<NA>
    2018-01-05 20:29:36,779 [myid:] - INFO  [main:Environment@100] - Server environment:os.name=Linux
    2018-01-05 20:29:36,779 [myid:] - INFO  [main:Environment@100] - Server environment:os.arch=amd64
    2018-01-05 20:29:36,779 [myid:] - INFO  [main:Environment@100] - Server environment:os.version=3.10.0_1-0-0-8
    2018-01-05 20:29:36,780 [myid:] - INFO  [main:Environment@100] - Server environment:user.name=work
    2018-01-05 20:29:36,780 [myid:] - INFO  [main:Environment@100] - Server environment:user.home=/home/work
    2018-01-05 20:29:36,780 [myid:] - INFO  [main:Environment@100] - Server environment:user.dir=/home/work/soft/zookeeper-3.4.6
    2018-01-05 20:29:36,787 [myid:] - INFO  [main:ZooKeeperServer@755] - tickTime set to 2000
    2018-01-05 20:29:36,787 [myid:] - INFO  [main:ZooKeeperServer@764] - minSessionTimeout set to -1
    2018-01-05 20:29:36,787 [myid:] - INFO  [main:ZooKeeperServer@773] - maxSessionTimeout set to -1
    2018-01-05 20:29:36,803 [myid:] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181
    2018-01-05 20:29:41,380 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /127.0.0.1:33745
    2018-01-05 20:29:41,385 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@827] - Processing srvr command from /127.0.0.1:33745
    2018-01-05 20:29:41,388 [myid:] - INFO  [Thread-1:NIOServerCnxn@1007] - Closed socket connection for client /127.0.0.1:33745 (no session established for client)

    启动成功后可以看到zoo_0中

    里面的文件zookeeper_server.pid就是对应的进程号

    安装后用cli来测试一下:
    [work@xxx zookeeper-3.4.6]$ bin/zkCli.sh -server 127.0.0.1:2181
    Connecting to 127.0.0.1:2181
    2018-01-05 21:25:15,952 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2018-01-05 21:25:15,956 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=xxx
    2018-01-05 21:25:15,956 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_111
    2018-01-05 21:25:15,958 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
    2018-01-05 21:25:15,958 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/jre
    2018-01-05 21:25:15,958 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/work/soft/zookeeper-3.4.6/bin/../build/classes:/home/work/soft/zookeeper-3.4.6/bin/../build/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/work/soft/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/home/work/soft/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../conf:
    2018-01-05 21:25:15,958 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0_1-0-0-8
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=work
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/work
    2018-01-05 21:25:15,959 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/work/soft/zookeeper-3.4.6
    2018-01-05 21:25:15,961 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@544cbce2
    Welcome to ZooKeeper!
    2018-01-05 21:25:15,988 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
    JLine support is enabled
    2018-01-05 21:25:15,994 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
    2018-01-05 21:25:16,018 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x160c67e9c270000, negotiated timeout = 30000
    [zk: 127.0.0.1:2181(CONNECTED) 0]
    WATCHER::

    WatchedEvent state:SyncConnected type:None path:null

    [zk: 127.0.0.1:2181(CONNECTED) 0]
    [zk: 127.0.0.1:2181(CONNECTED) 0] help
    ZooKeeper -server host:port cmd args
            connect host:port
            get path [watch]
            ls path [watch]
            set path data [version]
            rmr path
            delquota [-n|-b] path
            quit
            printwatches on|off
            create [-s] [-e] path data acl
            stat path [watch]
            close
            ls2 path [watch]
            history
            listquota path
            setAcl path acl
            getAcl path
            sync path
            redo cmdno
            addauth scheme auth
            delete path [version]
            setquota -n|-b val path
    [zk: 127.0.0.1:2181(CONNECTED) 1]
    [zk: 127.0.0.1:2181(CONNECTED) 1]
    [zk: 127.0.0.1:2181(CONNECTED) 1]

    windows下的安装方式见:zookeeper单节点windows下安装

    本文参考自:

    http://blog.csdn.net/xiewendong93/article/details/50500471

    http://qsfwy.iteye.com/blog/1667191

    https://www.cnblogs.com/haippy/archive/2012/07/19/2599989.html

  • 相关阅读:
    剑指offer字符串列表
    剑指offer数组3
    剑指offer数组2
    剑指offer数组1
    剑指offer数组列表
    tensorflow+ssd_mobilenet实现目标检测的训练
    Win7+keras+tensorflow使用YOLO-v3训练自己的数据集
    Java是如何实现跨平台的
    Xshell 、PuTTY 复制文件到Linux
    Asp.Net Core2.0在linux下发布
  • 原文地址:https://www.cnblogs.com/abc-begin/p/8206727.html
Copyright © 2020-2023  润新知