准备好zookeeper、kafka二进制包,安装好java环境
1、解压zookeeper二进制包,软连接到相关目录下
tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz -C /usr/local/src/
ln -s /usr/local/src/apache-zookeeper-3.6.0 /usr/local/zookeeper
2、复制文件做配置文件,更改配置文件
cp /usr/local/zookeeper1/conf/zoo_sample.cfg /usr/local/zookeeper1/conf/zoo.cfg
vim zoo.cfg
配置文件如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper1/data
dataLogDir=/usr/local/zookeeper1/logs
clientPort=2181
3、创建数据、日志文件夹
mkdir /usr/local/zookeeper1/{data,logs}
4、配置环境变量
vim /etc/profile
zookeeper,指定zookeeper的配置文件目录路径
export ZOOKEEPER_HOME=/usr/local/zookeeper1
export PATH=PATH
5、启动zookeeper
/usr/local/zookeeper1/bin/zkServer.sh start
jps
成功启动
<meta charset="utf-8">
kafka单节点
1、解压kafka二进制包,软连接到相关目录下
tar -zxvf kafka_2.12-2.6.0.tgz -C /usr/local/src/
ln -s /usr/local/src/kafka_2.12-2.6.0/ /usr/local/kafka1
2、更改kafka配置文件
vim /usr/local/kafka1/config/server.properties
配置文件如下
broker.id=1
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://192.168.7.114:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/usr/local/kafka1/data
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.7.114:2181
zookeeper.connection.timeout.ms=18000
group.initial.rebalance.delay.ms=0
修改consumer.properties配置文件
vim /usr/local/kafka1/config/consumer.properties
bootstrap.servers=192.168.7.114:9092
group.id=test-consumer-group
修改producer.properties配置文件
vim /usr/local/kafka1/config/producer.properties
bootstrap.servers=192.168.7.114:9092
compression.type=none
3、创建数据目录文件夹
mkdir /usr/local/kafka1/data
4、启动kafka
/usr/local/kafka1/bin/kafka-server-start.sh -daemon /usr/local/kafka1/config/server.properties
jps
[图片上传失败...(image-bf9776-1623940479685)]
创建生产者
./kafka-console-producer.sh --broker-list 192.168.7.114:9092 --topic test
生产者发送信息
[图片上传失败...(image-bd7fbc-1623940479685)]
创建消费者
./bin/kafka-console-consumer.sh --bootstrap-server 192.168.7.114:9092 --topic test --from-beginning
消费者消费信息
[图片上传失败...(image-358bb-1623940479685)]