美文网首页
zookeeper伪集群搭建

zookeeper伪集群搭建

作者: 茧铭 | 来源:发表于2020-11-03 16:36 被阅读0次

    1、解压zookeeper

    tar -zxvf -C /opt/app/zk1
    

    2、复制到伪集群的另外两个节点

    cd /opt/app
    cp -R  zk1/zookeeper-3.6.2   ./zk2
    cp -R  zk1/zookeeper-3.6.2   ./zk3
    

    3、新建数据存储文件夹

    mkdir -p zk1/zookeeper-3.6.2/data
    mkdir -p zk2/zookeeper-3.6.2/data
    mkdir -p zk3/zookeeper-3.6.2/data
    

    4、修改启动配置文件

    vim zk1/zookeeper-3.6.2/conf/zoo_sample.cfg
    zk2和zk3同理,修改dataDir、dataLogDir和clientPort
    增加(前面的端口是zookeeper服务之间通信的端口。后面的端口是zookeeper与其他应用程序通信的端口。伪分布式需要防止冲突)
    server.1=localhost:2287:3387
    server.2=localhost:2288:3388
    server.3=localhost:2289:3389

      # 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=/opt/app/zk1/zookeeper-3.6.2/data   
    dataLogDir=/opt/app/zk1/zookeeper-3.6.2/logs
    # the port at which the clients will connect
    clientPort=2181
    server.1=localhost:2287:3387
    server.2=localhost:2288:3388
    server.3=localhost:2289:3389
    
    # 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=/opt/app/zk2/zookeeper-3.6.2/data   
    dataLogDir=/opt/app/zk2/zookeeper-3.6.2/logs
    # the port at which the clients will connect
    clientPort=2182
    server.1=localhost:2287:3387
    server.2=localhost:2288:3388
    server.3=localhost:2289:3389
    
    # 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=/opt/app/zk3/zookeeper-3.6.2/data   
    dataLogDir=/opt/app/zk3/zookeeper-3.6.2/logs
    # the port at which the clients will connect
    clientPort=2183
    server.1=localhost:2287:3387
    server.2=localhost:2288:3388
    server.3=localhost:2289:3389
    

    5、增加在data文件夹下增加myid文件,并添加server的值,按照zoo.cnf的文件配置,myid的内容为1、2、3

    echo "1" > /opt/app/zk1/zookeeper-3.6.2/data/myid
    echo "2" > /opt/app/zk2/zookeeper-3.6.2/data/myid
    echo "3" > /opt/app/zk3/zookeeper-3.6.2/data/myid
    

    6、创建一个启动脚本

    /opt/app/zk1/zookeeper-3.6.2/bin/zkServer.sh start /opt/app/zk1/zookeeper-3.6.2/conf/zoo_sample.cfg
    /opt/app/zk2/zookeeper-3.6.2/bin/zkServer.sh start /opt/app/zk2/zookeeper-3.6.2/conf/zoo_sample.cfg
    /opt/app/zk3/zookeeper-3.6.2/bin/zkServer.sh start /opt/app/zk3/zookeeper-3.6.2/conf/zoo_sample.cfg
    
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk1/zookeeper-3.6.2/conf/zoo_sample.cfg
    Starting zookeeper ... already running as process 4860.
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk2/zookeeper-3.6.2/conf/zoo_sample.cfg
    Starting zookeeper ... STARTED
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk3/zookeeper-3.6.2/conf/zoo_sample.cfg
    Starting zookeeper ... STARTED
    

    查看状态的脚本

    /opt/app/zk1/zookeeper-3.6.2/bin/zkServer.sh status //opt/app/zk1/zookeeper-3.6.2/conf/zoo_sample.cfg
    /opt/app/zk2/zookeeper-3.6.2/bin/zkServer.sh status //opt/app/zk2/zookeeper-3.6.2/conf/zoo_sample.cfg
    /opt/app/zk3/zookeeper-3.6.2/bin/zkServer.sh status //opt/app/zk3/zookeeper-3.6.2/conf/zoo_sample.cfg
    
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk1/zookeeper-3.6.2/conf/zoo_sample.cfg
    Client port found: 2181. Client address: localhost. Client SSL: false.
    Mode: follower
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk2/zookeeper-3.6.2/conf/zoo_sample.cfg
    Client port found: 2182. Client address: localhost. Client SSL: false.
    Mode: leader
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: //opt/app/zk3/zookeeper-3.6.2/conf/zoo_sample.cfg
    Client port found: 2183. Client address: localhost. Client SSL: false.
    Mode: follower
    

    相关文章

      网友评论

          本文标题:zookeeper伪集群搭建

          本文链接:https://www.haomeiwen.com/subject/mufivktx.html