您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關centos中怎么安裝kafka,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
Broker kafk實例,kafka集群包含一個或多個實例,原則上來說一臺主機上只配一個實例。
Topic kafka消息主題,kafka的消息必須屬于某個主題,一個Broker存在多個Topic。
Partition
它是物理層的概念,被稱之為分區,每個Topic包含一個或者多個分區。
Producer
消息發布者,即負責發布消息到kafka的Broker
Consumer
消息消費者,即負責向kafka Broker消費消息的客戶端
Consumer Group
每個消費者必須屬于一個消費者組
$ cd /usr/java
[root@43-c59438365-0048-0727982 java]# cd kafka
[root@43-c59438365-0048-0727982 kafka]# wget http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz
由此可見,我下載的kafka版本是2.3.0
[root@43-c59438365-0048-0727982 kafka]# ll
total 55936
-rw-r--r-- 1 root root 57215197 Jun 25 08:38 kafka_2.12-2.3.0.tgz
[root@43-c59438365-0048-0727982 kafka]# tar zxvf kafka_2.12-2.3.0.tgz
...
[root@43-c59438365-0048-0727982 kafka]# ll
total 55940
drwxr-xr-x 6 root root 4096 Jun 20 04:44 kafka_2.12-2.3.0
-rw-r--r-- 1 root root 57215197 Jun 25 08:38 kafka_2.12-2.3.0.tgz
[root@43-c59438365-0048-0727982 kafka]#
$ vi /etc/profile
添加如下兩行
export KAFKA_HOME=/usr/java/kafka/kafka_2.12-2.3.0
export PATH=$PATH:$KAFKA_HOME/bin
退出后,執行刷新命令
source profile
由于kafka依賴zookeeper,所以啟動kafka之前需要先啟動zookeeper。所以我們需要找到zookeeper的配置文件,如下
[root@43-c59438365-0048-0727982 config]# ll
total 68
-rw-r--r-- 1 root root 906 Jun 20 04:43 connect-console-sink.properties
-rw-r--r-- 1 root root 909 Jun 20 04:43 connect-console-source.properties
-rw-r--r-- 1 root root 5321 Jun 20 04:43 connect-distributed.properties
-rw-r--r-- 1 root root 883 Jun 20 04:43 connect-file-sink.properties
-rw-r--r-- 1 root root 881 Jun 20 04:43 connect-file-source.properties
-rw-r--r-- 1 root root 1552 Jun 20 04:43 connect-log4j.properties
-rw-r--r-- 1 root root 2262 Jun 20 04:43 connect-standalone.properties
-rw-r--r-- 1 root root 1221 Jun 20 04:43 consumer.properties
-rw-r--r-- 1 root root 4727 Jun 20 04:43 log4j.properties
-rw-r--r-- 1 root root 1925 Jun 20 04:43 producer.properties
-rw-r--r-- 1 root root 6851 Jun 20 04:43 server.properties
-rw-r--r-- 1 root root 1032 Jun 20 04:43 tools-log4j.properties
-rw-r--r-- 1 root root 1169 Jun 20 04:43 trogdor.conf
-rw-r--r-- 1 root root 1023 Jun 20 04:43 zookeeper.properties
[root@43-c59438365-0048-0727982 config]# pwd
/usr/java/kafka/kafka_2.12-2.3.0/config
[root@43-c59438365-0048-0727982 config]#
如上就是zookeeper配置文件的絕對路徑,接下來啟動zookeeper,進入kafka安裝目錄bin下,執行如下啟動命令
[root@43-c59438365-0048-0727982 bin]# ./zookeeper-server-start.sh /usr/java/kafka/kafka_2.12-2.3.0/config/zookeeper.properties &
[1] 25053
[root@43-c59438365-0048-0727982 bin]# [2019-08-24 15:31:29,375] INFO Reading configuration from: /usr/java/kafka/kafka_2.12-2.3.0/config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
...
[2019-08-24 15:31:29,407] INFO tickTime set to 3000 (org.apache.zookeeper.server.ZooKeeperServer)
[2019-08-24 15:31:29,407] INFO minSessionTimeout set to -1 (org.apache.zookeeper.server.ZooKeeperServer)
[2019-08-24 15:31:29,407] INFO maxSessionTimeout set to -1 (org.apache.zookeeper.server.ZooKeeperServer)
[2019-08-24 15:31:29,413] INFO Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory (org.apache.zookeeper.server.ServerCnxnFactory)
[2019-08-24 15:31:29,416] INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)
^C
[root@43-c59438365-0048-0727982 bin]#
如上說明zookeeper啟動成功。
接著啟動kafka服務
kafka服務啟動需要kafka配置文件,配置文件同zookeeper配置文件是一個位置,如/usr/java/kafka/kafka_2.12-2.3.0/config
[root@43-c59438365-0048-0727982 bin]# ./kafka-server-start.sh /usr/java/kafka/kafka_2.12-2.3.0/config/server.properties &
[2] 25406
[root@43-c59438365-0048-0727982 bin]# [2019-08-24 15:37:12,829] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2019-08-24 15:37:13,489] INFO Registered signal handlers for TERM, INT, HUP (org.apache.kafka.common.utils.LoggingSignalHandler)
[2019-08-24 15:37:13,490] INFO starting (kafka.server.KafkaServer)
[2019-08-24 15:37:13,491] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
...
[2019-08-24 15:37:14,823] INFO [SocketServer brokerId=0] Started data-plane processors for 1 acceptors (kafka.network.SocketServer)
[2019-08-24 15:37:14,830] INFO Kafka version: 2.3.0 (org.apache.kafka.common.utils.AppInfoParser)
[2019-08-24 15:37:14,830] INFO Kafka commitId: fc1aaa116b661c8a (org.apache.kafka.common.utils.AppInfoParser)
[2019-08-24 15:37:14,830] INFO Kafka startTimeMs: 1566632234826 (org.apache.kafka.common.utils.AppInfoParser)
[2019-08-24 15:37:14,831] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
由此可見,kafka啟動成功了。
創建Topic
[root@43-c59438365-0048-0727982 bin]# kafka-topics.sh --create --zookeeper localhost:2181 --topic myTopic --partitions 1 --replication-factor 1
[2019-08-24 16:15:21,854] INFO Accepted socket connection from /0:0:0:0:0:0:0:1:44731 (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2019-08-24 16:15:21,857] INFO Client attempting to establish new session at /0:0:0:0:0:0:0:1:44731 (org.apache.zookeeper.server.ZooKeeperServer)
[2019-08-24 16:15:21,860] INFO Established session 0x10085c3259c0002 with negotiated timeout 30000 for client /0:0:0:0:0:0:0:1:44731 (org.apache.zookeeper.server.ZooKeeperServer)
[2019-08-24 16:15:22,126] INFO Got user-level KeeperException when processing sessionid:0x10085c3259c0002 type:setData cxid:0x4 zxid:0x44 txntype:-1 reqpath:n/a Error Path:/config/topics/myTopic Error:KeeperErrorCode = NoNode for /config/topics/myTopic (org.apache.zookeeper.server.PrepRequestProcessor)
Created topic myTopic.
由上可知,我們創建了一個叫myTopic的主題。
創建生產者 [root@43-c59438365-0048-0727982 bin]# kafka-console-producer.sh --topic myTopic --broker-list localhost:9092
$>
由上可知,生產者創建好了。
創建消費者
這里很明顯,需要新開一個窗口,
[root@43-c59438365-0048-0727982 bin]# kafka-console-consumer.sh --topic myTopic --bootstrap-server localhost:9092
如下就可以在生產者窗口發送消息,消費者窗口及時收到消息。
##6.kafka開外網
設置kafka的server.properties文件,
listeners=PLAINTEXT://服務器內網ip:9092
advertised.listeners=PLAINTEXT://服務器外網ip:9092
通過ifconfig查看服務器的內網ip。通過內外網映射關系查看服務器外網ip。
運行一段時間后,發現kafka進行被殺掉了,采用如下命令啟動kafka服務可以避免這個問題
./kafka-server-start.sh -daemon /usr/java/kafka/kafka_2.12-2.5.0/config/server.properties &
啟動命令后加上-daemon
自此結束。
關于centos中怎么安裝kafka就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。