单节点单Broker部署

  1. ##############
  2. ## 解压
  3. tar -zxvf kafka_2.10-0.8.1.1.tgz
  4. ##############
  5. ## 关于zookeeper
  6. cd kafka_2.10-0.8.1.1
  7. vi config/zookeeper.properties
  8. #修改ZooKeeper的数据目录
  9. dataDir=/usr/local/db/zookeeper
  10. #配置host.name和advertised.host.name为IP地址,防止通过Java客户端连接时解析为localhost
  11. host.name=192.168.209.121
  12. advertised.host.name=192.168.209.121
  13. # 后台启动zooKeeper
  14. ./zookeeper-server-start.sh -daemon /usr/local/kafka_2.10-0.8.1.1/config/zookeeper.properties
  15. ##############
  16. ## 关于kafka
  17. vi config/server.properties
  18. log.dirs=/usr/local/kafka/kafka-logs
  19. # 后台启动kafka
  20. ./kafka-server-start.sh -daemon /usr/local/kafka_2.10-0.8.1.1/config/server.properties
  21. ##############
  22. ## 关于topic
  23. # 创建topic
  24. cd /usr/local/kafka_2.10-0.8.1.1/bin/
  25. ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
  26. Created topic "test".
  27. # 查看刚才的topic
  28. ./kafka-topics.sh --list --zookeeper localhost:2181
  29. test
  30. # 生产者发送消息
  31. ./kafka-console-producer.sh --broker-list localhost:9092 --topic test
  32. This is a message
  33. This is My mesage
  34. # 消费者接受消息
  35. ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
  36. This is a message
  37. This is My me

感谢以下链接:
https://blog.csdn.net/l1028386804/article/details/78348367
https://blog.csdn.net/HG_Harvey/article/details/79174104

  1. cat zookeeper.service
  2. [Unit]
  3. Description=Zookeeper service
  4. After=network.target
  5. [Service]
  6. Type=simple
  7. Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/bin"
  8. User=zookeeper
  9. Group=zookeeper
  10. ExecStart=bin/zkServer.sh start
  11. ExecStop=bin/zkServer.sh stop
  12. Restart=on-failure
  13. WorkingDirectory=/usr/local/zookeeper
  14. [Install]
  15. WantedBy=multi-user.target
  16. #原文链接:https://blog.csdn.net/weixin_34284188/article/details/92926437
  17. cat kafka.service
  18. [Unit]
  19. Description=Apache Kafka server (broker)
  20. After=network.target zookeeper.service
  21. [Service]
  22. Type=simple
  23. Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/bin"
  24. User=kafka
  25. Group=kafka
  26. ExecStart=bin/kafka-server-start.sh config/server.properties
  27. ExecStop=bin/kafka-server-stop.sh
  28. Restart=on-failure
  29. WorkingDirectory=/usr/local/kafka
  30. [Install]
  31. WantedBy=multi-user.target
  32. #原文链接:https://blog.csdn.net/qq_37707251/article/details/104929254
  33. ##
  34. ln -s /usr/local/kafka_2.12-2.7.0/ /usr/local/kafka
  35. ln -s /usr/local/apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper
  36. systemctl enable zookeeper
  37. systemctl enable kafka
  38. id kafka || useradd -s /sbin/nologin -M kafka
  39. id zookeeper || useradd -s /sbin/nologin -M zookeeper
  40. chown -R zookeeper.zookeeper /usr/local/zookeeper
  41. 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