2. zookeeper 集群搭建

zookeeper 集群搭建

  • 准备服务器三台

    server1=192.169.31.121
    server2=192.169.31.152
    server3=192.169.31.226

  • 下载zookeeper安装包 下载

    在linux中使用 wget 下在zookeeper安装包

    wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
    
  • 解压缩

    tar -zxvf zookeeper-3.4.12.tar.gz
    
  • 配置服务

    copy zookeeper-3.4.12/conf 下 zoo_sample.cfg 文件重命名为 zoo.cfg

    vim zoo.cfg

    # 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.
    # 存储zookeeper快照文件目录
    dataDir=/var/zookeeper
    # the port at which the clients will connect
    # zookeeper服务对外提供服务的端口
    clientPort=2181
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the 
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    
    # 服务配置
    # 样式
    # server.id=host:port:port
    server.1=192.169.31.121:2999:3999
    server.2=192.169.31.152:2999:3999
    server.3=192.169.31.226:2999:3999
    

    注意:将配分别 scp 到其它的两台 zookeeper conf 中

    scp zoo.cfg [email protected]:/opt/zookeeper-3.4.12/conf
    
  • 配置 myid 文件

    zoo.cfg 中配置的 dataDir=/var/zookeeper 目录,创建 myid 文件

    vim myid 输入当前服务器的id, 保存。
    同样配置其它两台服务器的 myid 文件。

  • 启动 zookeeper 服务

    /opt/zookeeper-3.4.12/bin 目录下执行命令 ./zkServer.sh start 启动服务,如下则表示服务启动该成功:

    [root@zivs bin]# ./zkServer.sh start
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper-3.4.12/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    
  • 检查 zookeeper 服务是否对外提供服务

    查看档前服务状态

    [root@zivs bin]# ./zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper-3.4.12/bin/../conf/zoo.cfg
    Mode: leader
    

    使用 telnet 命令 telnet 192.168.31.121 2181

    [root@zivs bin]# telnet 192.168.31.121 2181
    Trying 192.168.31.121...
    Connected to 192.168.31.121.
    Escape character is '^]'.
    stat
    This ZooKeeper instance is not currently serving requests
    Connection closed by foreign host.
    

    上面的提示说明 zookeeper 服务没有对外提供服务,继续启动其它服务 telnet 如下即表示 zookeeper 集群服务器搭建成功:

    [root@zivs bin]# telnet 192.168.31.121 2181
    Trying 192.168.31.121...
    Connected to 192.168.31.121.
    Escape character is '^]'.
    stat
    Zookeeper version: 3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
    Clients:
     /192.168.31.121:44360[0](queued=0,recved=1,sent=0)
    
    Latency min/avg/max: 0/0/0
    Received: 2
    Sent: 1
    Connections: 1
    Outstanding: 0
    Zxid: 0x300000000
    Mode: leader
    Node count: 4
    Connection closed by foreign host.
    

    zookeeper 规定一个集群中只有过半的服务启动对外提供服务,该集群才可对外提供服务

    yum install telnet 没有安装 telnet 命令可先通过这个命令先安装 telnet 命令

  • zookeeper 集群,伪集群,单机配置

    集群

    # server.id=host:port:port
    server.1=192.169.31.121:2999:3999
    server.2=192.169.31.152:2999:3999
    server.3=192.169.31.226:2999:3999
    

    伪集群 - host 一样 port 不一样

    # server.id=host:port:port
    server.1=192.169.31.121:2997:3997
    server.2=192.169.31.121:2998:3998
    server.3=192.169.31.121:2999:3999
    

    单机 - 一台服务即可

    # server.id=host:port:port
    server.1=192.169.31.121:2997:3997
    

你可能感兴趣的:(2. zookeeper 集群搭建)