• 在Ubuntu上搭建Zookeeper集群


    新建data文件夹

    cd /usr/local/zookeeper/
    mkdir data

    分别设定在各主机使用一个命令表示id

    这里直接在各个主机分别输入(echo "1" > /usr/local/zookeeper/data/myid    中的1是第一台主机,其余的主机往后递增)

    echo "1" > /usr/local/zookeeper/data/myid

    测试:

    1.启动ZooKeeper

    在各个主机都输入:

    cd /usr/local/zookeeper/bin/
    ./zkServer.sh start

    显示如下

    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED

    2查看状态

    在各个主机都输入:

    ./zkServer.sh status

    观察各个主机的Mode显示有一台主机是leader和多台主机是follower就是成功了

    检测是否成功启动,在客户端连接下服务端

    ./zkCli.sh -server slave1:2181

    显示如下:

    复制代码
    Connecting to slave1:2181
    2020-10-17 01:51:39,229 [myid:] - INFO  [main:Environment@109] - Client environment:zookeeper.version=3.5.8-f439ca583e70862c3068a1f2a7d4d068eec33315, built on 05/04/2020 15:07 GMT
    2020-10-17 01:51:39,233 [myid:] - INFO  [main:Environment@109] - Client environment:host.name=master
    2020-10-17 01:51:39,233 [myid:] - INFO  [main:Environment@109] - Client environment:java.version=1.8.0_265
    2020-10-17 01:51:39,236 [myid:] - INFO  [main:Environment@109] - Client environment:java.vendor=Private Build
    2020-10-17 01:51:39,236 [myid:] - INFO  [main:Environment@109] - Client environment:java.home=/usr/lib/jvm/java-8-openjdk-amd64/jre
    2020-10-17 01:51:39,236 [myid:] - INFO  [main:Environment@109] - Client environment:java.class.path=/usr/local/zookeeper/bin/../zookeeper-server/target/classes:/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/zookeeper-jute-3.5.8.jar:/usr/local/zookeeper/bin/../lib/zookeeper-3.5.8.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/usr/local/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-transport-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-resolver-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-handler-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-common-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-codec-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/netty-buffer-4.1.48.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.17.jar:/usr/local/zookeeper/bin/../lib/json-simple-1.1.1.jar:/usr/local/zookeeper/bin/../lib/jline-2.11.jar:/usr/local/zookeeper/bin/../lib/jetty-util-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/jetty-server-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/jetty-security-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/jetty-io-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/jetty-http-9.4.24.v20191120.jar:/usr/local/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/usr/local/zookeeper/bin/../lib/jackson-databind-2.10.3.jar:/usr/local/zookeeper/bin/../lib/jackson-core-2.10.3.jar:/usr/local/zookeeper/bin/../lib/jackson-annotations-2.10.3.jar:/usr/local/zookeeper/bin/../lib/commons-cli-1.2.jar:/usr/local/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper/bin/../zookeeper-*.jar:/usr/local/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/local/zookeeper/bin/../conf:.:/usr/share/java/jdk1.8.0_261/lib:/lib
    2020-10-17 01:51:39,236 [myid:] - INFO  [main:Environment@109] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:java.io.tmpdir=/tmp
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:java.compiler=<NA>
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:os.name=Linux
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:os.arch=amd64
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:os.version=4.15.0-120-generic
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:user.name=hadoop
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:user.home=/home/hadoop
    2020-10-17 01:51:39,237 [myid:] - INFO  [main:Environment@109] - Client environment:user.dir=/usr/local/zookeeper/bin
    2020-10-17 01:51:39,238 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.free=25MB
    2020-10-17 01:51:39,239 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.max=228MB
    2020-10-17 01:51:39,239 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.total=31MB
    2020-10-17 01:51:39,242 [myid:] - INFO  [main:ZooKeeper@868] - Initiating client connection, connectString=slave1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@726f3b58
    2020-10-17 01:51:39,249 [myid:] - INFO  [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
    2020-10-17 01:51:39,259 [myid:] - INFO  [main:ClientCnxnSocket@237] - jute.maxbuffer value is 4194304 Bytes
    2020-10-17 01:51:39,268 [myid:] - INFO  [main:ClientCnxn@1653] - zookeeper.request.timeout value is 0. feature enabled=
    Welcome to ZooKeeper!
    2020-10-17 01:51:39,386 [myid:slave1:2181] - INFO  [main-SendThread(slave1:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server slave1/192.168.58.129:2181. Will not attempt to authenticate using SASL (unknown error)
    JLine support is enabled
    2020-10-17 01:51:39,570 [myid:slave1:2181] - INFO  [main-SendThread(slave1:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /192.168.58.128:48134, server: slave1/192.168.58.129:2181
    2020-10-17 01:51:39,748 [myid:slave1:2181] - INFO  [main-SendThread(slave1:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server slave1/192.168.58.129:2181, sessionid = 0x200005f99630000, negotiated timeout = 30000
    
    WATCHER::
    
    WatchedEvent state:SyncConnected type:None path:null
    [zk: slave1:2181(CONNECTED) 0]
    复制代码

    现在就可以通过客户端执行基本命令 ls /

    [zk: slave2:2181(CONNECTED) 0] create /test 111
    Created /test
    [zk: slave2:2181(CONNECTED) 1] ls /
    [test, zookeeper]
    [zk: slave2:2181(CONNECTED) 2] get /test
    111

    验证数据是否同步

    [zk: slave1:2181(CONNECTED) 0] get /test
    111
    [zk: slave1:2181(CONNECTED) 1] 

    通过验证可以看出 在服务slave2上创建的节点,在slave1上也可以获取到,说明集群部署是OK的.

    配置环境变量(进入管理员)(在每台主机上执行相同的操作)

    su
    vim /etc/profile

    在最后添加:

    export ZOOKEEPER_HOME=/usr/local/zookeeper
    export PATH=$PATH:$ZOOKEEPER_HOME/bin

    保存退出(:wq!)

  • 相关阅读:
    abp 框架定时任务(一)
    jenkins构建maven项目:找不到本地依赖包的解决办法
    python异常处理及常用异常
    python中unittest常用断言
    python自动化中遇到问题--Assert断言失败了,但是在异常捕获了,生成测试报告却是pass的。
    python+unittest框架
    linux虚拟机内网突然不通了
    curl 命令-接口测试
    python中使用os.path.join()
    ActiveMQ消费重试机制
  • 原文地址:https://www.cnblogs.com/studya/p/14204043.html
Copyright © 2020-2023  润新知