Note: Before deploying Kafka, deploy the environment Java, Zookeeper
Prepare three centos_6.5_x64 servers, respectively:
IP: 192.168.0.249 dbTest249 Kafka IP: 192.168.0.250 Other250 Kafka IP: 192.168.0.251 webTest251 Kafka
First, install the Kafka
# tar zxvf kafka_2.9.1-0.8.2.2.tgz-c/usr/local/# cd/usr/local/kafka_2.9.1-0.8.2.2/
Second, we install 3 brokers, respectively, on 3 machines: dbtest249,other250,webtest251:
1. Edit dbTest249:
# Vim Config/server.properties
1 broker.id=0 2 port=9092 3 host.name=dbTest249 4 advertised.host.name=dbTest249 5 num.partitions=2 6 zookeeper.connect=dbtest249:2181,other250:2181,webtest251:2181
2. Edit Other250
# Vim Config/server.properties
1 broker.id=1 2 port=9092 3 host.name=Other250 4 advertised.host.name=Other250 5 num.partitions=2 6 zookeeper.connect=dbtest249:2181,other250:2181,webtest251:2181
3. Edit webTest251
# Vim Config/server.properties
1 broker.id=2 2 port=9092 3 host.name=webTest251 4 advertised.host.name=webTest251 5 num.partitions=2 6 zookeeper.connect=dbtest249:2181,other250:2181,webtest251:2181
Third, start the Kafka service, respectively on 3 machines: dbtest249,other250,webtest251:
# nohup/usr/local/kafka_2.9.1-0.8.2.2/bin/kafka-server-start.sh/usr/local/kafka_2.9.1-0.8.2.2/config/ Server.properties >/var/log/kafka.log 2>&1 &# Ps-ef | grep kafka# NETSTAT-TUNPL |grep java
Iv. Testing
1, on the dbTest249, a new topic (Replication-factor=num of brokers)
#/usr/local/kafka_2.9.1-0.8.2.2/bin/kafka-topics.sh--create--topic Test--replication-factor 3--partitions 2-- Zookeeper dbtest249:2181
2, we in Other250, open a terminal, send messages to Kafka (Other250 analog producer)
#/usr/local/kafka_2.9.1-0.8.2.2/bin/kafka-console-producer.sh--broker-list dbtest249:9092--sync--topic test
Send message at Send terminal: Hello Kafka
3, we are on the webTest251, open a terminal, display the consumption of messages (webTest251 analog consumer)
#/usr/local/kafka_2.9.1-0.8.2.2/bin/kafka-console-consumer.sh--zookeeper dbtest249:2181--topic test-- From-beginning
At the end of consumer message display: Hello Kafka
Deploy Kafka distributed cluster, install and test under Linux