Built environment:
- JDK: java version 1.8.0_221
- zookeeper:zookeeper-3.5.2
- Kafka: Kafka A-2. 11-1.1.0
First, install the JDK
Due to the need java environment, so we need to install JDK
1, JDK download and unzip
mkdir / usr / java // create java in usr
the JDK-8u221 Linux-cp-x64.tar.gz / usr / java / // will be downloaded JDK file copy to / usr / java directory
cd /usr/java
the JDK-xzvf-8u221-tar Linux-x64.tar.gz // extract to the current directory
2, configure the environment variables
vi / etc / profile
Add the following to the contents of the final document:
JAVA_HOME=/usr/java/jdk1.8.0_221 CLASSPATH=$JAVA_HOME/lib/ PATH=$PATH:$JAVA_HOME/bin export PATH JAVA_HOME CLASSPATH
Save and exit, and executed
Source / etc / Profile // make the environment variables to take effect
3. Check installation
java -version
Sometimes encountered:
Every time you open a terminal, must input source / etc / profile environment variables to take effect!
Solution:
vi ~ / .bashrc
the source / etc / profile file added to bashrc
Second, the installation kafka 1.1.0
kafka Download: http://kafka.apache.org/downloads
1, (this installation is Zhendi uncomfortable, various error ...)
Once you have downloaded, extract the archive, and enter its directory
xzvf tar kafka211110tgz
cd kafka_2.11-1.1.0
2, here, you must first start in a terminal services zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties & //
I use kafka comes zookeeper-server-start.sh start zookeeper service, and then start all kinds of error does not come kafka, I finally downloaded directly Quguan zookeeper, re-install their own
Installation method can refer to the article: https://www.jianshu.com/p/7dcec9758614
3, then open another terminal, and then start the service kafka
bin/kafka-server-start.sh config/server.properties
4, test
Create a topic called "test" and see
linux-ym54:/usr/local/kafka/kafka_2.11-1.1.0 # bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
linux-ym54:/usr/local/kafka/kafka_2.11-1.1.0 # bin/kafka-topics.sh --list --zookeeper localhost:2181
test
Send a message:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
Receive messages:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
Sometimes encountered:
- Zookeeper when you start the service, there will be
INFO Closed socket connection for client /127.0.0.1:48452 which had sessionid 0x15698f5ac360001 (org.apache.zookeeper.server.NIOServerCnxn)
That is not an error. The topic details are fetched from Zookeeper. Hence the client (invoked by kafka-topics.sh) first connects to Zookeeper, then establishes a session, gets the data and then disconnects at the end. This is the expected behavior of any clients that will get some data from Zookeeper.
- 在启动kafka服务时,会出现
[2019-08-10 09:59:58,527] ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.net.UnknownHostException: linux-ym54: linux-ym54: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1506)
at kafka.server.KafkaServer$$anonfun$3.apply(KafkaServer.scala:387)
at kafka.server.KafkaServer$$anonfun$3.apply(KafkaServer.scala:385)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at kafka.server.KafkaServer.createBrokerInfo(KafkaServer.scala:385)
at kafka.server.KafkaServer.startup(KafkaServer.scala:253)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
at kafka.Kafka$.main(Kafka.scala:92)
at kafka.Kafka.main(Kafka.scala)
Caused by: java.net.UnknownHostException: linux-ym54: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
... 13 more
修改 /etc/hosts文件,
把 “ your ip localhost ” 添加进去
三、kafka在windows中的安装
可以参考文章:https://blog.csdn.net/u012050154/article/details/76270655
有时会遇到:
xshell连接不上的问题!
- 检查ssh是否开启
service sshd status
- 检查22端口是否开放
- 最后检查发现是防火墙导致的
关闭防火墙,然后重启。
linux-ym54:/home/ilk/Desktop # systemctl list-dependencies |grep firewall ● ├─SuSEfirewall2.service ● ├─SuSEfirewall2_init.service linux-ym54:/home/ilk/Desktop # chkconfig SuSEfirewall2 off Removed symlink /etc/systemd/system/multi-user.target.wants/SuSEfirewall2.service. Removed symlink /etc/systemd/system/multi-user.target.wants/SuSEfirewall2_init.service. Removed symlink /etc/systemd/system/SuSEfirewall2_setup.serv