单节点单Broker部署
##############
## 解压
tar -zxvf kafka_2.10-0.8.1.1.tgz
##############
## 关于zookeeper
cd kafka_2.10-0.8.1.1
vi config/zookeeper.properties
#修改ZooKeeper的数据目录
dataDir=/usr/local/db/zookeeper
#配置host.name和advertised.host.name为IP地址,防止通过Java客户端连接时解析为localhost
host.name=192.168.209.121
advertised.host.name=192.168.209.121
# 后台启动zooKeeper
./zookeeper-server-start.sh -daemon /usr/local/kafka_2.10-0.8.1.1/config/zookeeper.properties
##############
## 关于kafka
vi config/server.properties
log.dirs=/usr/local/kafka/kafka-logs
# 后台启动kafka
./kafka-server-start.sh -daemon /usr/local/kafka_2.10-0.8.1.1/config/server.properties
##############
## 关于topic
# 创建topic
cd /usr/local/kafka_2.10-0.8.1.1/bin/
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
# 查看刚才的topic
./kafka-topics.sh --list --zookeeper localhost:2181
test
# 生产者发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is My mesage
# 消费者接受消息
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
This is a message
This is My me
感谢以下链接:
https://blog.csdn.net/l1028386804/article/details/78348367
https://blog.csdn.net/HG_Harvey/article/details/79174104
cat zookeeper.service
[Unit]
Description=Zookeeper service
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/bin"
User=zookeeper
Group=zookeeper
ExecStart=bin/zkServer.sh start
ExecStop=bin/zkServer.sh stop
Restart=on-failure
WorkingDirectory=/usr/local/zookeeper
[Install]
WantedBy=multi-user.target
#原文链接:https://blog.csdn.net/weixin_34284188/article/details/92926437
cat kafka.service
[Unit]
Description=Apache Kafka server (broker)
After=network.target zookeeper.service
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/bin"
User=kafka
Group=kafka
ExecStart=bin/kafka-server-start.sh config/server.properties
ExecStop=bin/kafka-server-stop.sh
Restart=on-failure
WorkingDirectory=/usr/local/kafka
[Install]
WantedBy=multi-user.target
#原文链接:https://blog.csdn.net/qq_37707251/article/details/104929254
##
ln -s /usr/local/kafka_2.12-2.7.0/ /usr/local/kafka
ln -s /usr/local/apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper
systemctl enable zookeeper
systemctl enable kafka
id kafka || useradd -s /sbin/nologin -M kafka
id zookeeper || useradd -s /sbin/nologin -M zookeeper
chown -R zookeeper.zookeeper /usr/local/zookeeper
chown -R kafka.kafka /usr/local/kafka
kafka相关术语
Broker:消息中间件处理节点;每个Kafka服务节点称之为一个Broker,一个Kafka集群由一个或多个Broker组成Topic:一类特定数据集合的统称;可类比DB中Table的概念;逻辑概念 Producer:消息的生产者,向Broker发送消息的客户端 Consumer:消息的消费者,向Broker读取消息的客户端 Consumer Group:每一个Consumer隶属于一个特定的Consumer Group,一条消息可以被不同Group中的Consumer消费,但同一Group内的消息只能被一个Consumer消费 Partition:是对Topic中所包含数据集的物理分区;物理概念 Replication:副本集;是Kafka高可用的一种保障机制
原文链接:https://blog.csdn.net/YHYR_YCY/article/details/85016112
kafka几个应用场景
五种场景:异步处理,应用解耦,流量削锋,日志采集和消息通讯 原文链接:https://blog.csdn.net/leehsiao/article/details/103589126