单机模式一个服务(broker)
下载:http://kafka.apache.org/downloads
上传解压:tar -zxvf ~/soft/kafka_2.11-0.10.1.0.tgz ~/soft/
创建软连接(kafka安装目录上一层):ln -s kafka_2.11-0.10.1.0 kafka
配置环境变量:vim ~/.bashrc
export KAFKA_HOME=/home/hyxy/soft/kafka
export PATH=$KAFKA_HOME/bin:$FLUME_HOME/bin......
加载环境变量:source ~/.bashrc
修改broker配置文件(~/soft/kafka/config)
vim server.properties
修改属性:log.dirs=/home/hyxy/tmp/kafka-logs 【自己选一个文件夹存放】
使用kafka内置启动zookeeper(当前在kafka目录下)
zookeeper-server-start.sh config/zookeeper.properties
启动broker服务(在kafka目录下):kafka-server-start.sh config/server.properties
创建主题
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
启动生产者
kafka-console-producer.sh --broker-list localhost:9092 --topic test
写入数据
随便写点就行
启动消费者
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
显示写入的数据(成功)
=======================================================================================
单机多服务
下载:http://kafka.apache.org/downloads
上传解压:tar -zxvf ~/soft/kafka_2.11-0.10.1.0.tgz ~/soft/
创建软连接(kafka安装目录上一层):ln -s kafka_2.11-0.10.1.0 kafka
配置环境变量:vim ~/.bashrc
export KAFKA_HOME=/home/hyxy/soft/kafka
export PATH=$KAFKA_HOME/bin:$FLUME_HOME/bin
加载环境变量:source ~/.bashrc
修改broker配置文件(~/soft/kafka/config)
vim server.properties
修改属性:log.dirs=/home/hyxy/tmp/kafka-logs
cp server.properties server-1.properties
修改属性
log.dirs=/home/hyxy/tmp/kafka-logs-1
broker.id=1
添加属性
listeners=PLAINTEXT://:9093
使用kafka内置启动zookeeper(当前在kafka目录下)
zookeeper-server-start.sh config/zookeeper.properties
启动broker服务(在kafka目录下)
kafka-server-start.sh config/server.properties
kafka-server-start.sh config/server-1.properties
创建主题
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 2 --topic test
查看主题
kafka-topics.sh --list --zookeeper master:2181,slave1:2181,slave2:2181
启动生产者
kafka-console-producer.sh --broker-list localhost:9092,localhost:9093 --topic test
写入数据
随便写点就行
启动消费者
kafka-console-consumer.sh --bootstrap-server localhost:9092,localhost:9093 --topic test --from-beginning
显示写入的数据(成功)