Kafka安装和简单命令使用

## 下载kafka压缩版
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/kafka/2.1.0/kafka_2.12-2.1.0.tgz
[root@localhost src]# ll
-rw-r--r--.  1 root   root   55201623 11月 21 03:16 kafka_2.12-2.1.0.tgz
## 解压
[root@localhost src]# tar -zxvf kafka_2.12-2.1.0.tgz
[root@localhost src]# cd kafka_2.12-2.1.0/
[root@localhost kafka_2.12-2.1.0]# ll
总用量 52
drwxr-xr-x. 3 root root  4096 11月 10 03:54 bin
drwxr-xr-x. 2 root root  4096 11月 10 03:54 config
drwxr-xr-x. 2 root root  4096 12月 17 09:57 libs
-rw-r--r--. 1 root root 32216 11月 10 03:50 LICENSE
-rw-r--r--. 1 root root   336 11月 10 03:50 NOTICE
drwxr-xr-x. 2 root root    44 11月 10 03:54 site-docs

## 查看配置文件
[root@localhost kafka_2.12-2.1.0]# cd config/
[root@localhost config]# ll
总用量 68
-rw-r--r--. 1 root root  906 11月 10 03:50 connect-console-sink.properties
-rw-r--r--. 1 root root  909 11月 10 03:50 connect-console-source.properties
-rw-r--r--. 1 root root 5321 11月 10 03:50 connect-distributed.properties
-rw-r--r--. 1 root root  883 11月 10 03:50 connect-file-sink.properties
-rw-r--r--. 1 root root  881 11月 10 03:50 connect-file-source.properties
-rw-r--r--. 1 root root 1111 11月 10 03:50 connect-log4j.properties
-rw-r--r--. 1 root root 2262 11月 10 03:50 connect-standalone.properties
-rw-r--r--. 1 root root 1221 11月 10 03:50 consumer.properties
-rw-r--r--. 1 root root 4727 11月 10 03:50 log4j.properties
-rw-r--r--. 1 root root 1925 11月 10 03:50 producer.properties
-rw-r--r--. 1 root root 6851 11月 10 03:50 server.properties
-rw-r--r--. 1 root root 1032 11月 10 03:50 tools-log4j.properties
-rw-r--r--. 1 root root 1169 11月 10 03:50 trogdor.conf
-rw-r--r--. 1 root root 1023 11月 10 03:50 zookeeper.properties
[root@localhost config]#

# kafka伪分布式

## 配置server.properties文件
[root@localhost config]# cp server.properties server0.properties
[root@localhost config]# cp server.properties server1.properties
[root@localhost config]# cp server.properties server2.properties

## 配置以下四个参数
broker.id=0 
port=9092 
log.dirs=/home/kafka/kafka-0
zookeeper.connect=localhost:2181

broker.id=1
port=9093 
log.dirs=/home/kafka/kafka-1
zookeeper.connect=localhost:2182

broker.id=2
port=9094
log.dirs=/home/kafka/kafka-2
zookeeper.connect=localhost:2183

## 启动kafka:启动前先启动zookeeper
###  后台方式启动 ./kafka-server-start.sh  -daemon ../config/server0.properties 
[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server0.properties
[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server1.properties
[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server2.properties

# kafka 命令使用

## 创建topic主题
[root@localhost bin]# ./kafka-topics.sh --create --topic test0 --zookeeper localhost:2181 --partitions 2 --replication-factor 1
Created topic "test0".
## 查看
[root@localhost bin]# ./kafka-topics.sh --list --zookeeper localhost:2181
test0
## 查看指定topic的描述
[root@localhost bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test0
Topic:test0     PartitionCount:2        ReplicationFactor:1     Configs:
        Topic: test0    Partition: 0    Leader: 1       Replicas: 1     Isr: 1
        Topic: test0    Partition: 1    Leader: 2       Replicas: 2     Isr: 2
[root@localhost bin]#

## 修改topic配置信息
[root@localhost bin]# ./kafka-topics.sh --zookeeper localhost:2181 --alter --topic test0 --config max.message.bytes=102400
WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
         Going forward, please use kafka-configs.sh for this functionality
Updated config for topic "test0".

## 删除topic配置信息
[root@localhost bin]# ./kafka-topics.sh --zookeeper localhost:2181 --alter --topic test0 --delete-config max.message.bytes
WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
         Going forward, please use kafka-configs.sh for this functionality
Updated config for topic "test0".
[root@localhost bin]#

### partition分区数只能增加不能减少
[root@localhost bin]# ./kafka-topics.sh --zookeeper localhost:2181 --alter --topic test0 --partitions 1
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Error while executing topic command : The number of partitions for a topic can only be increased. Topic test0 currently has 2 partitions, 1 would not be an increase.
[2018-12-17 11:47:06,720] ERROR org.apache.kafka.common.errors.InvalidPartitionsException: The number of partitions for a topic can only be increased. Topic test0 currently has 2 partitions, 1 would not be an increase.
 (kafka.admin.TopicCommand$)
[root@localhost bin]#

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值