1.Kafka的安装与启动
2.Kafka常ç¨å½ä»¤(zookeeperä¸bootstrap-server)
Kafka的安装与启动
安装Kafka在mac上,使用brew install kafka命令进行安装。若无Zookeeper,Kafka会自动安装。智能台灯附源码
启动Kafka前,先启动Zookeeper。wordpress站群源码进入Kafka安装目录下的bin目录,执行以下命令:./zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &(确保后台运行)。
启动Kafka使用brew services start kafka命令(在任意路径)。
创建话题topic,执行命令:kafka-topics --create --zookeeper localhost: --replication-factor 1 --partitions 1 --topic 你的topic名字。
创建话题后,使用kafka-topics --list --zookeeper localhost:命令查看已创建的小游戏源码 c话题。
接下来,创建生产者向话题传入数据。使用命令:kafka-console-producer --broker-list localhost: --topic 话题名字。天量预警源码
注意:原始参数为Zookeeper地址端口localhost:,Kafka服务器地址为localhost:。
根据以上步骤,e分销 源码下载对Kafka消费者进行配置,接受信息。详情请参考jianshu.com/p/ddd...
Kafka常ç¨å½ä»¤(zookeeperä¸bootstrap-server)
å¨ 0.9.0.0 ä¹åç Kafkaï¼åºç°äºå 个æ°åå¨ï¼ä¸ä¸ªæ¯å¨ Server 端å¢å äº GroupCoordinator è¿ä¸ªè§è²ï¼å¦ä¸ä¸ªè¾å¤§çåå¨æ¯å° topic ç offset ä¿¡æ¯ç±ä¹ååå¨å¨ zookeeper ä¸æ¹ä¸ºåå¨å°ä¸ä¸ªç¹æ®ç topicï¼__consumer_offsetsï¼ä¸ Kafkaçå¯å¨åå°å¸¸é©»æ¹å¼,带ä¸åæ° -daemon,å¦:
/kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.propertiesæå® JMX port 端å£å¯å¨ï¼æå® jmxï¼å¯ä»¥æ¹ä¾¿çæ§ Kafka é群
JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties åæ¢Kafka/kafka/bin/kafka-server-stop.sh Topic[使ç¨zk] --zookeeper localhost:
[使ç¨å ç½®] --bootstrap-server localhost:
1. å建 Topicå®æ¹æ¨èå¦ækafkaçæ¬å¤§äºçäº2.2使ç¨--bootstrap-serveræ¿ä»£--zookeeper ï¼2.2以ä¸ä¹å ¼å®¹--zookeeperï¼å½ä»¤å¦ä¸
kafka-topics.sh --create --bootstrap-server localhost: --replication-factor 1 --partitions 1 --topic mytestå¦ækafkaçæ¬å°äº2.2åå½ä»¤å¦ä¸
kafka-topics.sh --create --zookeeper localhost: --replication-factor 1 --partitions 1 --topic myteståæ°è§£é1.æå®kafkaé群(2.2以ä¸)æzookeeperé群
--bootstrap-server node1:,node2:,node3:....æ
--zookeeper node1:,node2:,node3:...2.æå®ååºæ°
--partitions3.æå®ååºçå¯æ¬æ°
--replication-factoræ以æ§è¡ä¸é¢å½ä»¤å°ä¼å建ä¸ä¸ªå为mytestçtopicï¼è¯¥topicä¸é¢æ1个ååº,并ä¸è¯¥ååºåªæ1个å¯æ¬
2. ååºææTopickafka-topics.sh --list --bootstrap-server localhost:.æ¥çæå®TopicJMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties0JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties.å¢å Topicçpartitionæ°kafka-topics.sh --bootstrap-server localhost: --alter --topic mytest --partitions .æ¥ç topic æå®ååº offset çæ大å¼ææå°å¼time 为 -1 æ¶è¡¨ç¤ºæ大å¼ï¼ä¸º -2 æ¶è¡¨ç¤ºæå°å¼ï¼
kafka-run-class.sh kafka.tools.GetOffsetShell --topic mytest --time -1 --broker-list .0.0.1: --partitions 0 6.å é¤TopicJMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties4 ç产æ¶æ¯JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties5 æ¶è´¹æ¶æ¯1.ä»å¤´å¼å§JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties6 2.ä»å°¾é¨å¼å§ä»å°¾é¨å¼å§åæ°æ®ï¼å¿ éè¦æå®ååºï¼
JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties7 3.æå®ååºJMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties7 4.åæå®ä¸ªæ°JMX_PORT= /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties7 --max-messages 1 æ¶è´¹è Group1.æå®Group/kafka/bin/kafka-server-stop.sh0 2.æ¶è´¹è Groupå表/kafka/bin/kafka-server-stop.sh1 3.æ¥çGroup详æ [ç¨æ¥å¤ææ¯å¦æ延è¿æ°æ®]/kafka/bin/kafka-server-stop.sh2è¾åº
/kafka/bin/kafka-server-stop.sh3TOPIC ? PARTITION ?CURRENT-OFFSET ?LOG-END-OFFSET ?LAG CONSUMER-ID HOST CLIENT-ID test 0 ?5 ? 5 ? 0 ? - ? - ? -
CURRENT-OFFSET: å½åæ¶è´¹è 群ç»æè¿æ交ç offsetï¼ä¹å°±æ¯æ¶è´¹è ååºé读åçå½åä½ç½®LOG-END-OFFSET: å½åæé«æ°´ä½å移éï¼ä¹å°±æ¯æè¿ä¸ä¸ªè¯»åæ¶æ¯çå移éï¼åæ¶ä¹æ¯æè¿ä¸ä¸ªæ交å°é群çå移éLAGï¼æ¶è´¹è ç CURRENT-OFFSET ä¸ broker ç LOG-END-OFFSET ä¹é´çå·®è·/kafka/bin/kafka-server-stop.sh4kafka-consumer-groups.sh --bootstrap-server localhost: --group test_group --delete
/kafka/bin/kafka-server-stop.sh5kafka-preferred-replica-election.sh --bootstrap-server localhost: æ kafka-leader-election.sh --bootstrap-server localhost: --topic test --partition=2 --election-type preferred --partition:æå®éè¦éæ°åé leaderçpartitionç¼å·
/kafka/bin/kafka-server-stop.sh6kafka-producer-perf-test.sh --topic test --num-records --record-size 1 --throughput --producer-props bootstrap.servers=localhost:
/kafka/bin/kafka-server-stop.sh7åæï¼/post/