Original address: http://blog.csdn.net/shangboerds/article/details/38944743
-- Start
1. Start ZooKeeper
Start ZooKeeper first.
2. Start Kafka borker
First, copy two copies of server.properties under config directory, named server-1.properties and server-2.properties respectively. Then modify the following attributes of these two files to ensure the existence of the log directory.
server-1.properties:
server-2.properties:
broker.id is used to uniquely identify each broker. Since we are running three brokers on the same machine, we also need to modify the port and log.dirs attributes. Of course, there are many other attributes in this file that we can set, and each attribute is explained. You can take a closer look at this attribute file.
Now we have three broker s, which are started on three command lines.
3. Create topic
Open a new command prompt, and the following command creates a topic named topic1.
Have you ever wondered what these parameters of create mean? Where can I find out what they mean? Try the following commands.
Maybe you've seen what these parameters mean, but you don't necessarily understand what replication-factor s and partitions really mean. Now let's look at the relationship between topic, partition and log. You can understand topic as folder, partition. For subfolders under topic, log is under partition, and messages are saved in log. So in the above command -- partitions 3 means creating three partitions under topic1. So what does replication-factor 2 mean? It means copying any partition onto two brokers, so if one broker hangs up, we can still get messages from another broker. What if two brokers hang up? Ha-ha, that's really hanging up. What about? Not yet understood? Never mind, just look at the directory structure below.
After a while, you may have forgotten how topic1 is defined. If you want to see the details of topic1, try the following command.
The above command yields the following output:
The first line is an overview of topic. The next three lines describe each partition.
Each partition has a broker as leader, which is responsible for all read and write operations within the partition, while the other brokers passively copy leader broker. If leader broker hangs up, one of the other brokers will automatically become the new leader of the partition.
Replicas: 0,1 means that the partition is stored under broker 0 and broker 1.
Isr: 0,1 means that we can access the partition under broker 0 and broker 1 at present. If broker 0 hangs up, it will look like this.
4. Send messages
The following command sends a message to topic1.
5. Receiving messages
The following command receives messages from topic1.
6. Close broker 1
Now we close the command window that starts broker 1. Then use the following command to review the status of topic1 again.
You can try sending another message to see if you can receive it.
You can also close another broker and try sending a message to see what happens.