1. 依赖准备
1.1 jdk安装
安装jdk,版本推荐8以上
1.2 zk安装
- 下载zk对应版本
比如下载http://apache.communilink.net/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz - 解压
tar -xvf apache-zookeeper-3.5.5-bin.tar.gz mv apache-zookeeper-3.5.5-bin /usr/local/apache-zookeeper-3.5.5
- 创建数据目录及日志目录
mkdir {data,logs}
- 修改配置文件
# 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/apache-zookeeper-3.5.5/data dataLogDir=/usr/local/apache-zookeeper-3.5.5/logs # the port at which the clients will connect clientPort=2181 admin.serverPort=8181 # 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
- 设置环境变量
设置立即生效vim /etc/profile export ZOOKEEPER_HOME=/usr/local/apache-zookeeper-3.5.5 export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
source /etc/profile
- 启动&关闭zk服务
#启动ZooKeeper的Server zkServer.sh start #关闭ZooKeeper的Server zkServer.sh stop
2. kafka部署
- 下载对应集群版本https://archive.apache.org/dist/kafka/,以2.3.0为例
wget <https://archive.apache.org/dist/kafka/2.3.0/kafka_2.12-2.3.0.tgz>
- 解压安装包
tar zxvf kafka_2.12-2.3.0.tgz
- 修改配置文件
- 添加 delete.topic.enable=true,主要方便删除topic
- 去掉注释listeners=PLAINTEXT://:9092
- 设置zookeeper连接地址,一般zk后面接上自定义kafka绑定节点,zookeeper.connect=localhost:2181/kafka
- 配置日志目录,log.dirs=/tmp/kafka-logs
- 设置 broke.id,需要保证同一个集群中的各个节点值唯一
- 设置主题分区数,分区数一般为节点的整数倍,num.partitions=3
- 启动服务
#常规模式启动,可以查看控制台输出 bin/kafka-server-start.sh config/server.properties #后台启动 bin/kafka-server-start.sh -daemon config/server.properties
kafka简单使用请参考下一篇博客kafka常用控制台命令集合