Zookeeper安装、集群配置

本文详细介绍了Zookeeper的安装步骤,包括在Linux环境下使用wget下载、tar命令解压,以及配置数据存储和日志目录。接着,讲解了Zookeeper集群的搭建,包括设置myid文件和配置集群节点信息。最后,展示了Zookeeper配置文件的关键参数,如tickTime、dataDir、clientPort等,并提及了集群维护的autopurge功能。

Zookeeper安装

官网下载地址:https://zookeeper.apache.org/releases.html

  1. Linux服务器wget命令下载

    windows直接解压设置配置文件然后运行

    #版本号去官网选择自己下载的版本,本地电脑下载再上传也可,随便
    wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9-bin.tar.gz
    #未安装wget,yum安装
    yum install wget -y
    
    #tar命令解压
    tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz
    
  2. 编辑配置文件

    到解压出来zookeeper目录下的conf目录下,创建配置文件zoo.cfg

    #复制zookeeper提供的配置文件样例,改为正确的配置文件名称
    cp zoo_sample.cfg zoo.cfg
    

    配置文件中指定数据存储目录和日志目录(不指定用默认的建议指定)

    #数据存储目录
    dataDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/data
    #日志目录
    dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/logs
    #zookeeper提供了自动清理事务日志和快照文件的功能,指定频率,单位小时,1小时
    autopurge.snapRetainCount=1
    
  3. 启动zookeeper

    zookkeeper安装目录bin目录下执行命令

    #bin目录下执行
    ./zkServer.sh start
    #查看zookeeper状态
    ./zkServer.sh status
    #停止zookeeper
    ./zkServer.sh stop
    #重启zookeeper
    ./zkServer.sh restart
    

Zookeeper集群

  1. 添加myid配置,设置集群中每个服务器的ID

    在zookeeper的data目录下创建一个myid的文件记录服务器的id,内容为1表示这个zookeeper服务器id为1(每个都创建不要重复)

    # >的意思是将输出的内容不输出到控制台输出到文件,文件不存在自动创建,一个>是覆盖内容,两个>>是追加内容,每个服务唯一
    echo 1 > myid
    
  2. 配置文件中添加集群结点信息

    确保用到的端口打开或者关闭防火墙

    #增加集群配置,最好奇数集群
    #server.服务器ID=服务器IP地址:服务器之间通信端口:服务器直接投票选举端口
    server.1={server.ip}:{server.port1}:{server.port2}
    server.2={server.ip}:{server.port1}:{server.port2}
    

    查看集群效果Leader,显示 Mode: leader

    ZooKeeper JMX enabled by default
    Using config: /usr/local/zookeeper/apache-zookeeper-3.5.9-bin/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost. Client SSL: false.
    Mode: leader
    

Zookeeper配置文件

# 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=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/data
dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.5.9-bin/logs
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
server.1=192.168.136.133:2888:3888
server.2=192.168.136.132:2888:3888
#
# 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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值