您好,登錄后才能下訂單哦!
config目錄下創(chuàng)建kafka_server_jaas.conf文件:內(nèi)容如下:
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin-secret"
user_admin="admin-secret"
user_alice="alice-secret";
};
config目錄下創(chuàng)建kafka_client_jaas.conf文件:內(nèi)容如下:
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="alice"
password="alice-secret";
};
3. 修改config目錄下的server.properties文件:
修改內(nèi)容:自定義log.dirs(從新定義日志文件)
log.dirs=D:/kafka_2.10-0.9.0.0/kafka_2.10-0.10.1.0/kafka-logs
添加內(nèi)容:
#advertised.listeners=PLAINTEXT://192.168.66.119:9092
listeners=SASL_PLAINTEXT://localhost:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
#配置這個(gè)會(huì)報(bào)org.apache.kafka.common.errors.GroupAuthorizationException: Not authorized to access group:這個(gè)是授權(quán)配置的
#authorizer.class.name = kafka.security.auth.SimpleAclAuthorizer
allow.everyone.if.no.acl.found=false
4. config目錄下的consumer.properties和producer.properties添加如下內(nèi)容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
5. \bin\windows目錄下的kafka-server-start.bat文件添加內(nèi)容如下:
set KAFKA_OPTS=-Djava.security.auth.login.config=D:/kafka_2.10-0.9.0.0/kafka_2.10-0.10.1.0/config/kafka_server_jaas.conf
6. \bin\windows目錄下的kafka-console-producer.bat和kafka-console-consumer.bat文件添加內(nèi)容如下:
set KAFKA_OPTS=-Djava.security.auth.login.config=D:/kafka_2.10-0.9.0.0/kafka_2.10-0.10.1.0/config/kafka_client_jaas.conf
-------------------- 基本的配置已經(jīng)完成, 現(xiàn)在開始逐個(gè)啟動(dòng)----------------------------------
7. 啟動(dòng)kafka自帶的zookeeper:
在\bin\windows目錄下:shit+右鍵:彈出框后點(diǎn)擊(在此處打開命令窗口), 輸入命令:zkserver
8. 啟動(dòng)kafka
在kafka根目錄下:shit+右鍵:彈出框后點(diǎn)擊(在此處打開命令窗口), 輸入命令:
.\bin\windows\kafka-server-start.bat .\config\server.properties
9. 創(chuàng)建主題:
在\bin\windows目錄下:shit+右鍵:彈出框后點(diǎn)擊(在此處打開命令窗口), 輸入命令:
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
10. 創(chuàng)建一個(gè)生產(chǎn)者:
在\bin\windows目錄下:shit+右鍵:彈出框后點(diǎn)擊(在此處打開命令窗口), 輸入命令:
kafka-console-producer.bat --broker-list localhost:9092 --topic test --producer.config D:/kafka_2.10-0.9.0.0/kafka_2.10-0.10.1.0/config/producer.properties
11. 創(chuàng)建一個(gè)消費(fèi)者:
在\bin\windows目錄下:shit+右鍵:彈出框后點(diǎn)擊(在此處打開命令窗口), 輸入命令:
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning --consumer.config D:/kafka_2.10-0.9.0.0/kafka_2.10-0.10.1.0/config/consumer.properties
12. 在生產(chǎn)者的命令窗口隨意輸入, 回車發(fā)送信息, 在消費(fèi)者窗口查看接收的消息
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。