ubuntu下下kafka 單機配置部署

2021-08-10 21:19:22 字數 2970 閱讀 9834

修改配置vim /etc/profile

export zookeeper_home=/usr/local/kafka/zookeeper-3.3.6

使配置生效:

source /etc/profile

成功;#sh $zookeeper_home/bin/zkserver.sh start

jmx enabled by default

using config: /home/zookeeper-3.3.6/bin/../conf/zoo.cfg

grep: /home/zookeeper-3.3.6/bin/../conf/zoo.cfg: no such file or directory

starting zookeeper ... started

三.安裝kafka

解壓;tar -xzvf kafka_2.10-0.9.0.1.tgz

配置kafka,修改server.properties

mkdir /usr/local/kafka/log/kafka #建立kafka日誌目錄

cd /usr/local/kafka/kafka_2.10-0.9.0.1/config #進入配置目錄

vi server.properties #編輯修改相應的引數

broker.id=0

port=9092 #埠號

host.name=0.0.0.0 #自己的伺服器ip

log.dirs=/usr/local/kafka/log/kafka #日誌存放路徑

zookeeper.connect=localhost:2181 #zookeeper位址和埠,單機配置部署,localhost:2181

配置kafka下的zookeeper:

mkdir /usr/local/kafka/zookeeper #建立zookeeper目錄

mkdir /usr/local/kafka/log/zookeeper #建立zookeeper日誌目錄

cd /usr/local/kafka/kafka_2.10-0.9.0.1/config #進入配置目錄

vi zookeeper.properties #編輯修改相應的引數

datadir=/usr/local/kafka/zookeeper #zookeeper資料目錄

datalogdir=/usr/local/kafka/log/zookeeper #zookeeper日誌目錄

clientport=2181

maxclientcnxns=100

ticktime=2000

initlimit=10

建立啟動、關閉kafka指令碼:

啟動指令碼kafkastart.sh:

#!/bin/bash

#啟動zookeeper

/usr/local/kafka/kafka_2.10-0.9.0.1/bin/zookeeper-server-start.sh /usr/local/kafka/kafka_2.10-0.9.0.1/config/zookeeper.properties &

sleep 3 #等3秒後執行

/usr/local/kafka/kafka_2.10-0.9.0.1/bin/kafka-server-start.sh /usr/local/kafka/kafka_2.10-0.9.0.1/config/server.properties &

關閉指令碼kafkastop.sh;

#!/bin/bash

#啟動zookeeper

/usr/local/kafka/kafka_2.10-0.9.0.1/bin/zookeeper-server-stop.sh /usr/local/kafka/kafka_2.10-0.9.0.1/config/zookeeper.properties &

sleep 3 #等3秒後執行

/usr/local/kafka/kafka_2.10-0.9.0.1/bin/kafka-server-stop.sh /usr/local/kafka/kafka_2.10-0.9.0.1/config/server.properties &

注意:前邊要加上#!/bin/bash,不然會報錯找不到-bash

建立好要新增指令碼執行許可權!!!

chmod +x kafkastart.sh

chmod +x kafkastop.sh

測試一下。

[一]啟動zookeeper

sh $zookeeper_home/bin/zkserver.sh start

jmx enabled by default

using config: /home/laoyang/zookeeper/bin/../conf/zoo.cfg

grep: /home/laoyang/zookeeper/bin/../conf/zoo.cfg: no such file or directory

starting zookeeper ... started

[二]啟動kafka

./kafkastart.sh

[三]測試建立topic

cd /usr/local/kafka/kafka_2.10-0.9.0.1/bin

./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 --zookeeper localhost:2181 --topic test --from-beginning

會出現之前輸入的內容。

[六]停止kafka

./kafkastop.sh

Kafka 單機kafka部署

1 上傳部署包 kafka 2.11 0.11.0.0.tgz 放到 opt software 2 解壓 tar zxvf kafka 2.11 0.11.0.0.tgz c opt module 3 切換目錄 opt module kafka 2.11 0.11.0.0 conf 4 修改配置 v...

kafka單機部署

2 解壓 tar zxvf kafka 2.12 0.11.0.3.tgz c local sda kafka3 使用kafka自帶的zookeeper,修改zookeeper.properties cd local sda kafka kafka 2.12 0.11.0.3 進入kafka主目錄 ...

Kafka 單機部署

kafka 單機部署區分整合zookeeper 部署和zookeeper kafka 部署倆總方式,如果是單機部署kafka,整合zookeeper 最簡單,也可以選擇zookeeper kafka 這種模式,但是如果為kafka集群的話,則必須需要部署 zookeeper 集群。一.獲取解壓wge...