zk kafka 部署文档(ubuntu 20 + kafka 2.6)

本文档仅适用 ubuntu 18 和 ubuntu 20, 老久版本系统请联系开发索取配置方法.

机器要求:

一套 zk kafka 环境, 需要 3 台服务器, 每台布置一套 zk kafka

系统环境

apt-get update
apt-get install -y default-jdk 

下载软件

take /work/soft

wget http://common-software.oss-cn-hangzhou.aliyuncs.com/kafka/kafka_2.13-2.6.0.tgz \

&& tar -xvf kafka_2.13-2.6.0.tgz \

&& ln -s kafka_2.13-2.6.0 kafka

⚠️注意⚠️这里一定要对 kafka 目录做软连接, 以后所有软件目录, 都要在带版本号目录 (如 kafka_2.13-2.6.0) 的基础上, 做软连接(硬性规定).

Zookeeper

Zookeeper 不需要单独安装, 直接用 kafka 自带的 Zookeeper

初始化

下面 3 条命令在 3 台服务器上分别执行:

mkdir -p /work/soft/zookeeper/version-2 && echo 1 > /work/soft/zookeeper/myid
mkdir -p /work/soft/zookeeper/version-2 && echo 2 > /work/soft/zookeeper/myid
mkdir -p /work/soft/zookeeper/version-2 && echo 3 > /work/soft/zookeeper/myid

配置文件

vi /work/soft/kafka/config/zookeeper.properties

使用以下配置做覆盖, 修改 IP 地址部分即可

# The number of milliseconds of each tick
tickTime=2000

# the port at which the clients will connect
clientPort=2181
# 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.
dataDir=/work/soft/zookeeper

server.1=10.1.215.56:2888:3888
server.2=10.1.215.58:2888:3888
server.3=10.1.215.57:2888:3888

supervisor 配置

vim /etc/supervisor/conf.d/zookeeper.conf
[program:zookeeper]
directory=/work/soft/kafka
command=/work/soft/kafka/bin/zookeeper-server-start.sh /work/soft/kafka/config/zookeeper.properties
autostart=true
autorestart=true
startsecs=3
startretries=20

Kafka

配置文件

vim /work/soft/kafka/config/server.properties

修改部分:
- `broker.id=0`, id 每台机器唯一 0, 1, 2
- `listeners=PLAINTEXT://192.168.0.90:9092`, 替换ip地址为本地ip(内网)

- message 保存时间, 保存时间过长可能导致硬盘被打

     #####, 保存48+12 = 60小时
     log.retention.hours=60 

- log.dirs=/work/soft/kafka/kafka-logs
- zookeeper连接信息`zookeeper.connect=10.30.0.237:2181,10.30.0.235:2181,10.30.0.236:2181`替换机器列表ip地址(内网)


添加部分:

# increate message size limit
message.max.bytes=20000000
replica.fetch.max.bytes=30000000
# replication factor
default.replication.factor=3

supervisor 配置

vim /etc/supervisor/conf.d/kafka.conf
[program:kafka]
directory=/work/soft/kafka
command=/work/soft/kafka/bin/kafka-server-start.sh /work/soft/kafka/config/server.properties
autostart=true
autorestart=true
startsecs=3
startretries=20

启动 zk kafka

- 启动supervisor `supervisorctl`
- 重新读取配置文件`reread`
- 更新配置文件`update`
- 查看状态`status`
- 查看日志`less /work/soft/kafka/logs/server.log`

检验是否部署成功

topic创建成功后,使用生产者发送消息到kafka,消费者消费kafka中的消息,这里使用kafkacat工具:

生产消息(需改kafka_IP为集群ip例如: 10.1.192.89:9092,10.1.192.91:9092,10.1.192.90:9092  , topic为test):

docker run --interactive --rm \

      confluentinc/cp-kafkacat \

      kafkacat -b kafka_IP:9092 \

              -t test \

              -K: \

              -P

消费消息(需改IP, topic为test):

docker run --tty --interactive --rm \

         confluentinc/cp-kafkacat \

         kafkacat -b kafka_IP:9092 -C -t test -T

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值