linux下配置zookeeper

作者: 我叫了了 | 来源:发表于2017-03-12 00:54 被阅读589次

    我使用的是VMware装ubuntude 虚拟机,

    使用Xshell连接到linux虚拟机

    先下载zookeeper

    wget http://apache.fayea.com/zookeeper/stable/zookeeper-3.4.9.tar.gz
    

    接着 解压

    tar -xzvf zookeeper-3.4.9.tar.gz
    

    重命名

    mv zookeeper-3.4.9.tar.gz zookeeper
    

    然后查看一下

    ls -l
    

    进入zookeeper的conf目录下,然后再查看下

    cd /opt/zookeeper/conf
    ls -l
    

    然后将conf目录下的zoo_sample.cfg复制一份 名字叫zoo.cfg
    zookeeper启动的时候默认是读叫zoo.cfg这个文件的,zoo_sample.cfg只是zookeeper官方提供的一份配置文件样板。

    cp zoo_sample.cfg zoo.cfg
    

    现在使用vi编辑器打开它

    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 
    # zookeeper文件位置
    dataDir=/opt/zookeeper1/zookeeperData  
    #日志位置
    dataLogDir=/opt/zookeeper1/zookeeperLog
    # 对客户端开放的端口号
    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=127.0.0.1:2888:3888
    server.2=127.0.0.1:2889:3889
    server.3=127.0.0.1:2890:3890
    

    这里我使用的是 伪集群模式,集群模式就是将几个zookeeper部署到不同的服务器上,然后配置文件最下面那部分换成对应的ip地址。

    因为我配置了3台主机,所以要使用3个zookeeper,将刚才的zookeeper文件夹再复制两份,

    然后改下配置文件的 dataDir (zookeeper文件位置), dataLogDir(日志文件位置), clientPort(对客户端开放的端口号),这3个需要改成不一样的(如果是集群模式无所谓)。

    然后cd到你刚才配置dataDir的位置

    使用vi创建一个新文件叫myid,里面写入刚在配置文件中配置的server.id

    一共有3个zookeeper,所以要分别在 相应的目录创建。一共创建3次。完成后就可以启动3台zookeeper。

    启动方法,

    cd /opt/zookeeper/bin/
    ./zkServer.sh start
    

    启动后,再执行

    ./zkCl.sh
    

    就可以创建相应的节点并存放数据了

    相关文章

      网友评论

        本文标题:linux下配置zookeeper

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