kafka cheap clothes

Download address: http://kafka.apache.org/downloads

 

#jdkinstallation

slightly...

 

#Unzip kafka to /usr/local/kafka

 

#Set the configuration file /etc/profile file and increase the path of kafka

$ vim /etc/profile

export KAFKA_HOME=/usr/local/kafka

export PATH=$PATH:$KAFKA_HOME/bin

 

#Configuration file takes effect immediately

$ source /etc/profile

 

#Check if the kafka environment is valid

$ kafka-server-stop.sh

No kafka server to stop

 

#Start zookeeper (here uses the zookeeper that comes with kafka, and can also deploy zookeeper independently)

Use the default zookeeper.properties configuration file

$ zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties

 

#start kafka

Use the default server.properties configuration file

$ kafka-server-start.sh /usr/local/kafka/config/server.properties

 

#Create a topic named test

2181 is the default port of zookeeper

$ kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

Created topic "test"

 

#Create a consumer to receive messages

9092 is the default port for kafka

$ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

 

#Create a producer and enter information

$ kafka-console-producer.sh --broker-list localhost:9092 --topic test

>hello world

 

#You can see the corresponding input information in the consumer process

hello world

 

#View kafka's current topic list

$ kafka-topics.sh --list --zookeeper localhost:2181

 

#Use the parameter --from-beginning to let the consumer receive messages from the first one

$ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

 

Question 1:

[2018-04-23 06:04:29,542] INFO Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

2018-04-23 06:04:27,333] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)

java.net.ConnectException: Connection refused

at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)

at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)

at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)

solve:

Start zookeeper first, then start kafka

 

Question 2:

/usr/local/kafka/bin/kafka-run-class.sh: line 271: exec: java: cannot execute: Is a directory

Solution: install jdk

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326150226&siteId=291194637