您好,登錄后才能下訂單哦!
kafka 基本介紹
概念
一個分布式流處理平臺,消息訂閱平臺,一般有三個特性
適用場景
構建實時流式應用程序,對這些流數據進行轉換或者影響。 (就是流處理,通過kafka stream topic和topic之間內部進行變化)
部署安裝
kafka 部署安裝需要依賴于 zoookper 和java 環境
安裝java 環境
yum install java-1.8.0-openjdk* -y
安裝zoookper
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
解壓縮到指定位置
cp zoo_sample.cfg zoo.cfg
配置文件如下,創建所需要的目錄
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper_data
clientPort=2181
cat /etc/systemd/system/zookeeper.service
[Unit]
Description=zookeeper.service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
[Install]
WantedBy=multi-user.target
systemctl start zookeeper
安裝kafka
curl -LO https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.1.0/kafka_2.12-2.1.0.tgz
解壓縮到指定位置
修改配置文件
server.properties
broker.id=1
port=9092
host.name=localhost
log.dirs=/usr/local/kafka_logs
zookeeper.connect=localhost:2181
zookeeper.properties
dataDir=/usr/local/kafaka_data
clientPort=2181
maxClientCnxns=0
host.name=localhost
producer.properties
metadata.broker.list=localhost:9092
bootstrap.servers=localhost:9092
compression.type=none
consumer.properties
bootstrap.servers=localhost:9092
group.id=test-consumer-group
zookeeper.connect=localhost:2181
* 制作標準服務啟動
cat /etc/systemd/system/kafka.service
[Unit]
Description=Apache Kafka server (broker)
After=network.target
After=syslog.target
After=zookeeper.target
[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
ExecReload=/bin/kill -HUP $MAINPID
KillMode=none
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
systemctl start kafka
創建話題Topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic kafka01
Created topic "kafka01".
bin/kafka-topics.sh --list --zookeeper localhost:2181
啟動消息生產者并發送消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafka01
啟動消息消費者并收到消息
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafka01 --from-beginning
查看topic 列表 詳細信息
bin/kafka-topics.sh --zookeeper localhost:2181 --list
bin/kafka-topics.sh --zookeeper localhost:2181 --topic kafka01 --describe
Topic:kafka01 PartitionCount:1 ReplicationFactor:1 Configs:
Topic: kafka01 Partition: 0 Leader: 1 Replicas: 1 Isr: 1
拓展分區
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic kafka01 --partitions 2
bin/kafka-topics.sh --zookeeper localhost:2181 --topic kafka01 --describe
Topic:kafka01 PartitionCount:2 ReplicationFactor:1 Configs:
Topic: kafka01 Partition: 0 Leader: 1 Replicas: 1 Isr: 1
Topic: kafka01 Partition: 1 Leader: 1 Replicas: 1 Isr: 1
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。