CentOS7上部署搭建Kafka集群
2017-12-15 18:20
513 查看
CentOS7上部署搭建Kafka集群
在三个主机节点上进行部署。
cfkafka1:192.168.2.174
cfkafka2:192.168.2.175
cfkafka3:192.168.2.176
1.虚拟机配置
2:主机名修改和网络配置
静态主机名修改方法:
3:关闭系统防火墙
4:上传所需要的软件资源到/opt/kafkasrc目录下
5:删除系统自带的JDK 安装最新版JDK1.8
发现我这个系统竟然不带原生的JDK,哈哈
http://blog.csdn.net/hui_2016/article/details/69941850
安装上传到opt/kafkasrc下面的jre-8u144-linux-x64.rpm
5:解压kafka zookeeper,改名
tar -xzf zookeeper-3.4.10.tar.gz
6:配置环境变量
7:执行环境变量
8:部署zokeeper 配置
http://www.cnblogs.com/wxisme/p/5178211.html
重命名
新建zookeeper的data和logs文件夹
修改zoo.cfg文件
执行以下命令创建myid文件,并写入ID:
拷贝配置文件到其他节点
这里需要注意的是,每个节点中的myid是不能相同的。
9:启动Zookeeper集群
#CF-Kafka-176
#CF-Kafka-174
CF-kafka-175
10:验证 HA的故障自动转移是否好用
待测试
11:配置kafka
修改CF-kafka174、CF-kafka175、CF-kafka176的配置
vim opt/kafkasrc/kafka/config/server.proprtties
12 启动和测试
实际启动时,先启动4台机器的zookeeper,再启动4台机器的kafka。由于在设置的过程中,在zookeeper中设置了其他几台仪器的ip地址。因此,启动一台zookeeper时报一些错误信息,不用理会,等其他几台机器启动好了后就会恢复正常。
启动zookeer
见9:启动Zookeeper集群
启动kafka
关闭kafka
13:创建一个主题
我们用一个分区和一个副本创建一个名为“menpengpeng”的主题
我们现在可以看到这个话题,如果我们运行列表主题命令:
#查看topic中的属性(副本,等)
14:发送一些消息
Kafka带有一个命令行客户端,它将从文件或标准输入中获取输入,并将其作为消息发送到Kafka集群。默认情况下,每行将作为单独的消息发送。
运行生产者,然后在控制台输入一些消息发送到服务器。
15:启动一个消费者
命令行消费者,将消息转储到标准输出
在三个主机节点上进行部署。
cfkafka1:192.168.2.174
cfkafka2:192.168.2.175
cfkafka3:192.168.2.176
1.虚拟机配置
2:主机名修改和网络配置
静态主机名修改方法:
hostnamectl -- static set-hostname <hostname> vim /etc/hosts [root@cfkafka3 ~]# cat /etc/hosts 127.0.0.1 cfkafka3 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 |
[root@cfkafka1 ~]# clear [root@cfkafka1 ~]# systemctl stop firewalld.service [root@cfkafka1 ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. [root@cfkafka1 ~]# firewall-cmd --state not running |
[root@cfkafka2 ~]# cd /opt [root@cfkafka2 opt]# ls [root@cfkafka2 opt]# mkdir kafkasrc [root@cfkafka2 opt]# ls kafkasrc [root@cfkafka2 opt]# cd kafkasrc/ [root@cfkafka2 kafkasrc]# rz [root@cfkafka2 kafkasrc]# ls hd2u-1.0.0.tgz jre-8u144-linux-x64.rpm kafka_2.11-0.11.0.1.tgz test.sh zookeeper-3.4.10.tar.gz |
[root@cfkafka1 kafkasrc]# rpm -qa | grep java [root@cfkafka1 kafkasrc]# rpm -qa | grep jdk |
http://blog.csdn.net/hui_2016/article/details/69941850
安装上传到opt/kafkasrc下面的jre-8u144-linux-x64.rpm
[root@cfkafka1 kafkasrc]# ll 总用量 133164 -rw-r--r--. 1 root root 54461 10月 16 10:06 hd2u-1.0.0.tgz -rw-r--r--. 1 root root 59219102 10月 13 20:36 jre-8u144-linux-x64.rpm -rw-r--r--. 1 root root 42031343 10月 29 16:43 kafka_2.11-0.11.0.1.tgz -rw-r--r--. 1 root root 1952 10月 16 09:51 test.sh -rw-r--r--. 1 root root 35042811 10月 13 20:33 zookeeper-3.4.10.tar.gz [root@cfkafka1 kafkasrc]# chomd 755 jre-8u144-linux-x64.rpm -bash: chomd: 未找到命令 [root@cfkafka1 kafkasrc]# chmod 755 jre-8u144-linux-x64.rpm [root@cfkafka1 kafkasrc]# ll 总用量 133164 -rw-r--r--. 1 root root 54461 10月 16 10:06 hd2u-1.0.0.tgz -rwxr-xr-x. 1 root root 59219102 10月 13 20:36 jre-8u144-linux-x64.rpm -rw-r--r--. 1 root root 42031343 10月 29 16:43 kafka_2.11-0.11.0.1.tgz -rw-r--r--. 1 root root 1952 10月 16 09:51 test.sh -rw-r--r--. 1 root root 35042811 10月 13 20:33 zookeeper-3.4.10.tar.gz [root@cfkafka1 kafkasrc]# rpm -ivh jre-8u144-linux-x64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:jre1.8.0_144-1.8.0_144-fcs ################################# [100%] Unpacking JAR files... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... [root@cfkafka1 kafkasrc]# java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode) |
[root@cfkafka2 kafkasrc]# tar -zxvf kafka_2.11-0.11.0.1.tgz |
[root@cfkafka2 kafkasrc]# mv kafka_2.11-0.11.0.1 kafka [root@cfkafka2 kafkasrc]# mv zookeeper-3.4.10 zookeeper |
[root@cfkafka1 kafkasrc]# cd zookeeper [root@cfkafka1 zookeeper]# pwd /opt/kafkasrc/zookeeper [root@cfkafka1 zookeeper]# cd .. [root@cfkafka1 kafkasrc]# cd kafka [root@cfkafka1 kafka]# pwd /opt/kafkasrc/kafka [root@cfkafka1 kafka]# cd /etc [root@cfkafka1 etc]# echo "export ZOOKEEPER_HOME=/opt/kafkasrc/zookeeper">>/etc/profile [root@cfkafka1 etc]# echo "export KAFKA_HOME=/opt/kafkasrc/kafka">>/etc/profile [root@cfkafka1 etc]# cd /usr/java [root@cfkafka1 java]# ls default jre1.8.0_144 latest [root@cfkafka1 java]# echo "export JAVA_HOME=/usr/java/jre1.8.0_144">>/etc/profile [root@cfkafka1 java]# echo "export JAVA_BIN=/usr/java/jre1.8.0_144/bin">>/etc/profile [root@cfkafka1 java]# echo "export PATH=$PATH:$JAVA_HOME/bin:$KAFKA_HOME/bin:$ZOOKEEPER_HOME/bin">>/etc/profile [root@cfkafka1 java]# echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">>/etc/profile [root@cfkafka1 java]# echo "export JAVA_HOME JAVA_BIN PATH CLASSPATH">>/etc/profile [root@cfkafka1 java]# echo "export PATH=$PATH:$KAFKA_HOME/bin:$ZOOKEEPER_HOME/bin">>/etc/profile [root@cfkafka1 java]# echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">>/etc/profile [root@cfkafka1 java]# echo "export PATH ">>/etc/profile [root@cfkafka1 java]# |
[root@cfkafka1 java]# cd / [root@cfkafka1 /]# ./etc/profile |
http://www.cnblogs.com/wxisme/p/5178211.html
重命名
[root@cfkafka1 kafkasrc]# cd zookeeper [root@cfkafka1 zookeeper]# ls bin contrib ivysettings.xml LICENSE.txt README.txt zookeeper-3.4.10.jar zookeeper-3.4.10.jar.sha1 build.xml dist-maven ivy.xml NOTICE.txt recipes zookeeper-3.4.10.jar.asc conf docs lib README_packaging.txt src zookeeper-3.4.10.jar.md5 [root@cfkafka1 zookeeper]# cd conf [root@cfkafka1 conf]# ls configuration.xsl log4j.properties zoo.cfg zoo.cfg? zoo_sample.cfg [root@cfkafka1 conf]# mv zoo_sample.cfg zoo.cfg |
[root@cfkafka1 zookeeper]# mkdir datasrc [root@cfkafka1 zookeeper]# mkdir logs [root@cfkafka1 zookeeper]# ls bin contrib docs lib NOTICE.txt recipes zookeeper-3.4.10.jar.asc build.xml datasrc ivysettings.xml LICENSE.txt README_packaging.txt src zookeeper-3.4.10.jar.md5 conf dist-maven ivy.xml logs README.txt zookeeper-3.4.10.jar zookeeper-3.4.10.jar.sha1 [root@cfkafka1 zookeeper]# cd datasrc/ [root@cfkafka1 datasrc]# pwd /opt/kafkasrc/zookeeper/datasrc [root@cfkafka1 datasrc]# cd .. [root@cfkafka1 zookeeper]# cd logs [root@cfkafka1 logs]# pwd /opt/kafkasrc/zookeeper/logs |
[root@cfkafka1 conf]# vim zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # dataDir=/tmp/zookeeper dataDir=/opt/kafkasrc/zookeeper/datasrc dataLogDir=/opt/kafkasrc/zookeeper/logs autopurge.snapRetainCount=3 autopurge.purgeInterval=1 server.174=192.168.2.174:2888:3888 #添加Zookeeper集群各节点地址: server.175=192.168.2.175:2888:3888 server.176=192.168.2.176:2888:3888 # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 |
[root@cfkafka3 zookeeper]# mkdir datasrc [root@cfkafka3 zookeeper]# mkdir logs [root@cfkafka3 zookeeper]# cd datasrc/ [root@cfkafka3 datasrc]# ls [root@cfkafka3 datasrc]# touch myid [root@cfkafka3 datasrc]# echo 3 > myid [root@cfkafka3 datasrc]# cat myid 174 一定要保持myid中写入的数值与server后面的id保持一致。 |
这里需要注意的是,每个节点中的myid是不能相同的。
9:启动Zookeeper集群
Usage: zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd} |
[root@cfkafka3 zookeeper]# cd bin [root@cfkafka3 bin]# ls README.txt zkCleanup.sh zkCli.cmd zkCli.sh zkEnv.cmd zkEnv.sh zkServer.cmd zkServer.sh zookeeper.out [root@cfkafka3 bin]# sh zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@cfkafka3 bin]# sh zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Mode: follower |
[root@cfkafka1 bin]# sh zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@cfkafka1 bin]# sh zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Error contacting service. It is probably not running. [root@cfkafka1 bin]# sh zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Mode: follower |
[root@cfkafka2 datasrc]# cd .. [root@cfkafka2 zookeeper]# cd bin [root@cfkafka2 bin]# sh zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@cfkafka2 bin]# sh zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/kafkasrc/zookeeper/bin/../conf/zoo.cfg Mode: leader |
待测试
11:配置kafka
修改CF-kafka174、CF-kafka175、CF-kafka176的配置
vim opt/kafkasrc/kafka/config/server.proprtties
[root@localhost config]# vi server.properties # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # see kafka.server.KafkaConfig for additional details and defaults ############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker. broker.id=174 #175和176的配置相同 只需修改id即可 broker.id=175 broker.id=176 #下面红色的标注也是相同修改 # Switch to enable topic deletion or not, default value is false #delete.topic.enable=true ############################# Socket Server Settings ############################# # The address the socket server listens on. It will get the value returned from # java.net.InetAddress.getCanonicalHostName() if not configured. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 listeners=PLAINTEXT://192.168.2.174:9092 # Hostname and port the broker will advertise to producers and consumers. If not set, # it uses the value for "listeners" if configured. Otherwise, it will use the value # returned from java.net.InetAddress.getCanonicalHostName(). #advertised.listeners=PLAINTEXT://your.host.name:9092 # Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details #listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL # The number of threads that the server uses for receiving requests from the network and sending responses to the network num.network.threads=3 # The number of threads that the server uses for processing requests, which may include disk I/O num.io.threads=8 # The send buffer (SO_SNDBUF) used by the socket server socket.send.buffer.bytes=102400 # The receive buffer (SO_RCVBUF) used by the socket server socket.receive.buffer.bytes=102400 # The maximum size of a request that the socket server will accept (protection against OOM) socket.request.max.bytes=104857600 ############################# Log Basics ############################# # A comma seperated list of directories under which to store log files log.dirs=/usr/src/kafka/kafka-logs-174 #需要新建这个文件夹 # The default number of log partitions per topic. More partitions allow greater # parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1 # The number of threads per data directory to be used for log recovery at startup and flushing at shutdown. # This value is recommended to be increased for installations with data dirs located in RAID array. num.recovery.threads.per.data.dir=1 ############################# Internal Topic Settings ############################# # The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state" # For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3. offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 ############################# Log Flush Policy ############################# # Messages are immediately written to the filesystem but by default we only fsync() to sync # the OS cache lazily. The following configurations control the flush of data to disk. # There are a few important trade-offs here: # 1. Durability: Unflushed data may be lost if you are not using replication. # 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush. # 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks. # The settings below allow one to configure the flush policy to flush data after a period of time or # every N messages (or both). This can be done globally and overridden on a per-topic basis. # The number of messages to accept before forcing a flush of data to disk #log.flush.interval.messages=10000 # The maximum amount of time a message can sit in a log before we force a flush #log.flush.interval.ms=1000 ############################# Log Retention Policy ############################# # The following configurations control the disposal of log segments. The policy can # be set to delete segments after a period of time, or after a given size has accumulated. # A segment will be deleted whenever *either* of these criteria are met. Deletion always happens # from the end of the log. # The minimum age of a log file to be eligible for deletion due to age log.retention.hours=168 # A size-based retention policy for logs. Segments are pruned from the log as long as the remaining # segments don't drop below log.retention.bytes. Functions independently of log.retention.hours. #log.retention.bytes=1073741824 # The maximum size of a log segment file. When this size is reached a new log segment will be created. log.segment.bytes=1073741824 # The interval at which log segments are checked to see if they can be deleted according # to the retention policies log.retention.check.interval.ms=300000 ############################# Zookeeper ############################# # Zookeeper connection string (see zookeeper docs for details). # This is a comma separated host:port pairs, each corresponding to a zk # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002". # You can also append an optional chroot string to the urls to specify the # root directory for all kafka znodes. zookeeper.connect=localhost:2181 # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=6000 ############################# Group Coordinator Settings ############################# # The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance. # The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms. # The default value for this is 3 seconds. # We override this to 0 here as it makes for a better out-of-the-box experience for development and testing. # However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup. group.initial.rebalance.delay.ms=0 [root@localhost config]# ls Socket error Event: 32 Error: 10053. Connection closing...Socket close. Connection closed by foreign host. Disconnected from remote host(cf-kafka-171) at 10:07:47. |
mkdir kafka/kafka-logs-174 vim kafka/config/producer.properties bootstrap.servers=192.168.2.171:9092,192.168.2.172:9092,192.168.2.173:9092 |
实际启动时,先启动4台机器的zookeeper,再启动4台机器的kafka。由于在设置的过程中,在zookeeper中设置了其他几台仪器的ip地址。因此,启动一台zookeeper时报一些错误信息,不用理会,等其他几台机器启动好了后就会恢复正常。
启动zookeer
见9:启动Zookeeper集群
启动kafka
[root@cfkafka2 kafkasrc]# kafka/bin/kafka-server-start.sh -daemon /opt/kafkasrc/kafka/config/server.properties& [root@cfkafka2 kafka [1] 12597 [root@cfkafka2 kafka]# [2017-12-09 18:27:05,781] INFO KafkaConfig values: advertised.host.name = null advertised.listeners = null advertised.port = null alter.config.policy.class.name = null authorizer.class.name = |
kafka关闭 ./bin/kafka-server-stop.sh |
[root@cfkafka3 kafka]# ./bin/kafka-server-stop.sh [root@cfkafka3 kafka]# [2017-12-11 13:58:14,994] INFO [Kafka Server 176], shutting down (kafka.server.KafkaServer) [2017-12-11 13:58:14,994] INFO [Kafka Server 176], Starting controlled shutdown (kafka.server.KafkaServer) [2017-12-11 13:58:15,020] INFO [Kafka Server 176], Remaining partitions to move: my-replicated-topic-0 (kafka.server.KafkaServer) [2017-12-11 13:58:15,020] INFO [Kafka Server 176], Error code from controller: 0 (kafka.server.KafkaServer) [2017-12-11 13:58:20,020] WARN [Kafka Server 176], Retrying controlled shutdown after the previous attempt failed... (kafka.server.KafkaServer) [2017-12-11 13:58:20,028] INFO [Kafka Server 176], Remaining partitions to move: my-replicated-topic-0 (kafka.server.KafkaServer) [2017-12-11 13:58:20,028] INFO [Kafka Server 176], Error code from controller: 0 (kafka.server.KafkaServer) [2017-12-11 13:58:25,028] WARN [Kafka Server 176], Retrying controlled shutdown after the previous attempt failed... (kafka.server.KafkaServer) [2017-12-11 13:58:25,037] INFO [Kafka Server 176], Remaining partitions to move: my-replicated-topic-0 (kafka.server.KafkaServer) [2017-12-11 13:58:25,037] INFO [Kafka Server 176], Error code from controller: 0 (kafka.server.KafkaServer) [2017-12-11 13:58:30,037] WARN [Kafka Server 176], Retrying controlled shutdown after the previous attempt failed... (kafka.server.KafkaServer) [2017-12-11 13:58:30,038] WARN [Kafka Server 176], Proceeding to do an unclean shutdown as all the controlled shutdown attempts failed (kafka.server.KafkaServer) [2017-12-11 13:58:30,039] INFO [Socket Server on Broker 176], Shutting down (kafka.network.SocketServer) [2017-12-11 13:58:30,042] INFO [Socket Server on Broker 176], Shutdown completed (kafka.network.SocketServer) |
我们用一个分区和一个副本创建一个名为“menpengpeng”的主题
[root@cfkafka1 kafka]# ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic menpengpeng Created topic "menpengpeng". [2017-12-11 14:26:35,279] INFO [ReplicaFetcherManager on broker 174] Removed fetcher for partitions menpengpeng-0 (kafka.server.ReplicaFetcherManager) [2017-12-11 14:26:35,281] INFO Loading producer state from offset 0 for partition menpengpeng-0 with message format version 2 (kafka.log.Log) [2017-12-11 14:26:35,281] INFO Completed load of log menpengpeng-0 with 1 log segments, log start offset 0 and log end offset 0 in 1 ms (kafka.log.Log) [2017-12-11 14:26:35,282] INFO Created log for partition [menpengpeng,0] in /opt/kafkasrc/kafka/kafka-logs with properties {compression.type -> producer, message.format.version -> 0.11.0-IV2, file.delete.delay.ms -> 60000, max.message.bytes -> 1000012, min.compaction.lag.ms -> 0, message.timestamp.type -> CreateTime, min.insync.replicas -> 1, segment.jitter.ms -> 0, preallocate -> false, min.cleanable.dirty.ratio -> 0.5, index.interval.bytes -> 4096, unclean.leader.election.enable -> false, retention.bytes -> -1, delete.retention.ms -> 86400000, cleanup.policy -> [delete], flush.ms -> 9223372036854775807, segment.ms -> 604800000, segment.bytes -> 1073741824, retention.ms -> 604800000, message.timestamp.difference.max.ms -> 9223372036854775807, segment.index.bytes -> 10485760, flush.messages -> 9223372036854775807}. (kafka.log.LogManager) [2017-12-11 14:26:35,282] INFO Partition [menpengpeng,0] on broker 174: No checkpointed highwatermark is found for partition menpengpeng-0 (kafka.cluster.Partition) [2017-12-11 14:26:35,282] INFO Replica loaded for partition menpengpeng-0 with initial high watermark 0 (kafka.cluster.Replica) [2017-12-11 14:26:35,282] INFO Partition [menpengpeng,0] on broker 174: menpengpeng-0 starts at Leader Epoch 0 from offset 0. Previous Leader Epoch was: -1 (kafka.cluster.Partition) |
#创建topic kafka/bin/kafka-topics.sh --create --zookeeper 192.168.2.174:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic |
[root@cfkafka1 kafka]# ./bin/kafka-topics.sh --list --zookeeper localhost:2181 __consumer_offsets menpengpeng my-replicated-topic test test1 |
[root@cfkafka2 kafkasrc]# kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs: Topic: my-replicated-topic Partition: 0 Leader: 174 Replicas: 175,176,174 Isr: 174,175,176 |
Kafka带有一个命令行客户端,它将从文件或标准输入中获取输入,并将其作为消息发送到Kafka集群。默认情况下,每行将作为单独的消息发送。
运行生产者,然后在控制台输入一些消息发送到服务器。
[root@cfkafka1 kafka]# ./bin/kafka-console-producer.sh --broker-list 192.168.2.174:9092 --topic menpengpeng >haungyn^Hun^H^H^H >[2017-12-11 14:30:26,127] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset-1} for Partition: menpengpeng-0. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache) mne^H^H >menpeng >123456 >this is a message > |
命令行消费者,将消息转储到标准输出
[root@cfkafka2 kafka]# ./bin/kafka-console-consumer.sh --bootstrap-server 192.168.2.175:9092 --topic menpengpeng --from-beginning [2017-12-11 14:32:27,586] INFO [GroupCoordinator 175]: Preparing to rebalance group console-consumer-7282 with old generation 0 (__consumer_offsets-8) (kafka.coordinator.group.GroupCoordinator) [2017-12-11 14:32:27,587] INFO [GroupCoordinator 175]: Stabilized group console-consumer-7282 generation 1 (__consumer_offsets-8) (kafka.coordinator.group.GroupCoordinator) [2017-12-11 14:32:27,593] INFO [GroupCoordinator 175]: Assignment received from leader for group console-consumer-7282 for generation 1 (kafka.coordinator.group.GroupCoordinator) [2017-12-11 14:32:27,594] INFO Updated PartitionLeaderEpoch. New: {epoch:0, offset:0}, Current: {epoch:-1, offset-1} for Partition: __consumer_offsets-8. Cache now contains 0 entries. (kafka.server.epoch.LeaderEpochFileCache) haungyun mne menpeng WARN Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient 123456 this is a message |
相关文章推荐
- centos7 搭建kafka集群笔记
- Kafka(二)CentOS7.5搭建Kafka2.11-1.1.0集群与简单测试
- Kafka集群搭建01-Zookeeper 集群部署
- Kafka在Centos6.4中的集群搭建
- Centos 下Kafka集群的搭建
- CentOS 7部署Kafka和Kafka集群
- CentOS6.5下Cloudera安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)
- CentOS6.5下Ambari安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)
- Centos7---kafka集群搭建
- CentOS6.5下Ambari安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)
- kafka集群搭建部署测试
- Kafka集群搭建02-Kafka 集群部署
- centos7下kafka集群搭建
- Centos7搭建RabbitMQ集群及单机多节点部署和rabbitmq理论解析
- centos7下kafka集群安装部署
- Hadoop2.7.3在CentOS 6.5中的集群搭建
- centos6.5下搭建MySql集群
- Centos7.3部署Elasticsearch5.4.0集群
- CentOS中配置Kafka集群