構建大數(shù)據(jù)平臺(六)Kafka集群搭建

一胸嘴、前提:

(1)Kafka服務油吭,是基于zookeeper的勾扭。

(2)Kafka使用穩(wěn)定版本:kafka_2.11-1.0.0.tgz;

(3)可在master上安裝后要尔,scp到其他slave機器上舍杜。

二、配置Hbase:

首先要注意在生產(chǎn)環(huán)境中目錄結構要定義好赵辕,防止在項目過多的時候找不到所需的項目

  1. 目錄統(tǒng)一放在/home下面 既绩,首先創(chuàng)建kafka項目目錄
cd /home

#創(chuàng)建項目目錄
mkdir kafka
cd /home/kafka

#創(chuàng)建kafka消息目錄,主要存放kafka消息
mkdir kafkalogs
  1. 將 kafka_2.11-1.0.0.tgz 放在 /home/kafka下还惠,并解壓縮饲握,解壓縮完成后可刪除安裝包:
#解壓縮
tar -zxvf kafka_2.11-1.0.0.tgz

#完成后可刪除
rm -f kafka_2.11-1.0.0.tgz
  1. 修改配置文件

(1)進入到config目錄

cd /home/kafka/kafka_2.11-1.0.0/config/

主要關注:server.properties 這個文件即可,我們可以發(fā)現(xiàn)在目錄下:
有很多文件,這里可以發(fā)現(xiàn)有Zookeeper文件救欧,我們可以根據(jù)Kafka內帶的zk集群來啟動衰粹,但是建議使用獨立的zk集群

(2)修改配置文件 server.properties:

其中broker.id=,host.name=笆怠,listeners=铝耻,每臺服務器都不能相同,scp完后注意修改

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://master:9092
# Hostname the broker will bind to. If not set, the server will bind to all interfaces
# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured.  Otherwise, it will use the value


num.network.threads=3

num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600
# A comma seperated list of directories under which to store log files
log.dirs=/home/kafka/kafkalogs


num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings  #############################
############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# from the end of the log.


message.max.byte=5242880

replica.fetch.max.bytes=5242880

# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

log.segment.bytes=1073741824

default.replication.factor=2

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

log.cleaner.enable=false

############################# Zookeeper #############################

# root directory for all kafka znodes.
############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

(3) 將安裝配置好的kafka目錄復制到所有slave節(jié)點中:

scp -r /home/kafka/ root@slave1:/home/

(4)修改所有slave節(jié)點中server.properties中的broker.id=骑疆,host.name=田篇,listeners=。

三箍铭、啟動kafka:

  1. 啟動kafka集群,命令如下:
#從后臺啟動Kafka集群(所有機器都需要啟動)
cd
#進入到kafka的bin目錄 
cd /home/kafka/kafka_2.11-1.0.0/bin 
#啟動服務
./kafka-server-start.sh -daemon ../config/server.properties
  1. 使用命令:jps椎镣,檢查服務是否啟動

  2. 創(chuàng)建Topic來驗證是否創(chuàng)建成功

(1)創(chuàng)建Topic:

cd /home/kafka/kafka_2.11-1.0.0/bin 
./kafka-topics.sh --create --zookeeper master:2181 --replication-factor 3 --partitions 1 --topic test1

#解釋
--replication-factor 2   #復制3份
--partitions 1 #創(chuàng)建1個分區(qū)
--topic #主題為test1

(2)在一臺服務器上創(chuàng)建一個發(fā)布者诈火,這里我們選用slave1:

#創(chuàng)建一個broker,發(fā)布者
./kafka-console-producer.sh --broker-list slave1:9092 --topic test1

(3)在一臺服務器上創(chuàng)建一個訂閱者状答,這里我們選擇master:

./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1 --from-beginning

(4)測試

在發(fā)布者那里發(fā)布消息看看訂閱者那里是否能正常收到冷守。

如果收到,至此惊科,Kafka集群環(huán)境搭建完成拍摇!

四、補充:

大部分命令可以去官方文檔查看

  1. 查看topic
#就會顯示我們創(chuàng)建的所有topic
./kafka-topics.sh --list --zookeeper localhost:2181
  1. 查看topic狀態(tài)
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test1
#下面是顯示信息
Topic:test1 PartitionCount:1    ReplicationFactor:3 Configs:
    Topic: test1    Partition: 0    Leader: 0   Replicas: 0,1,2 Isr: 0,1,2
#分區(qū)為為1  復制因子為2   test1的分區(qū)為0 
#Replicas: 0,1   復制的為0馆截,1,充活,3
  1. 上面的大家你完成之后可以登錄zk來查看zk的目錄情況
#使用客戶端進入zk
./zkCli.sh -server 127.0.0.1:2181  #默認是不用加’-server‘參數(shù)的因為我們修改了他的端口

#標注一個重要的
[zk: 127.0.0.1:2181(CONNECTED) 1] get /brokers/ids/0
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://master:9092"],"jmx_port":-1,"host":"master","timestamp":"1519797571108","port":9092,"version":4}
cZxid = 0x700000055
ctime = Wed Feb 28 13:59:30 CST 2018
mZxid = 0x700000055
mtime = Wed Feb 28 13:59:30 CST 2018
pZxid = 0x700000055
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x361dafd39070000
dataLength = 182
numChildren = 0

#還有一個是查看partion
[zk: 127.0.0.1:2181(CONNECTED) 3] get /brokers/topics/test1/partitions/0  
null
cZxid = 0x700000066
ctime = Wed Feb 28 14:33:35 CST 2018
mZxid = 0x700000066
mtime = Wed Feb 28 14:33:35 CST 2018
pZxid = 0x700000067
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市蜡娶,隨后出現(xiàn)的幾起案子混卵,更是在濱河造成了極大的恐慌,老刑警劉巖窖张,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件幕随,死亡現(xiàn)場離奇詭異,居然都是意外死亡宿接,警方通過查閱死者的電腦和手機赘淮,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來睦霎,“玉大人梢卸,你說我怎么就攤上這事∷橛” “怎么了低剔?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我襟齿,道長姻锁,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任猜欺,我火速辦了婚禮位隶,結果婚禮上,老公的妹妹穿的比我還像新娘开皿。我一直安慰自己涧黄,他們只是感情好,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布赋荆。 她就那樣靜靜地躺著笋妥,像睡著了一般。 火紅的嫁衣襯著肌膚如雪窄潭。 梳的紋絲不亂的頭發(fā)上春宣,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機與錄音嫉你,去河邊找鬼月帝。 笑死,一個胖子當著我的面吹牛幽污,可吹牛的內容都是我干的嚷辅。 我是一名探鬼主播,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼距误,長吁一口氣:“原來是場噩夢啊……” “哼簸搞!你這毒婦竟也來了?” 一聲冷哼從身側響起深寥,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤攘乒,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后惋鹅,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體则酝,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年闰集,在試婚紗的時候發(fā)現(xiàn)自己被綠了沽讹。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡武鲁,死狀恐怖爽雄,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情沐鼠,我是刑警寧澤挚瘟,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布叹谁,位于F島的核電站,受9級特大地震影響乘盖,放射性物質發(fā)生泄漏焰檩。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一订框、第九天 我趴在偏房一處隱蔽的房頂上張望析苫。 院中可真熱鬧,春花似錦穿扳、人聲如沸衩侥。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽茫死。三九已至,卻和暖如春泽谨,著一層夾襖步出監(jiān)牢的瞬間璧榄,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工吧雹, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人涂身。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓雄卷,卻偏偏與公主長得像,于是被迫代替她去往敵國和親蛤售。 傳聞我的和親對象是個殘疾皇子丁鹉,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內容

  • 姓名:周小蓬 16019110037 轉載自:http://blog.csdn.net/YChenFeng/art...
    aeytifiw閱讀 34,721評論 13 425
  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn)悴能,斷路器揣钦,智...
    卡卡羅2017閱讀 134,654評論 18 139
  • ** 今天看了一下kafka官網(wǎng),嘗試著在自己電腦上安裝和配置漠酿,然后學一下官方document冯凹。** Introd...
    RainChang閱讀 5,003評論 1 30
  • kafka的定義:是一個分布式消息系統(tǒng),由LinkedIn使用Scala編寫炒嘲,用作LinkedIn的活動流(Act...
    時待吾閱讀 5,317評論 1 15
  • Kafka入門經(jīng)典教程-Kafka-about云開發(fā) http://www.aboutyun.com/threa...
    葡萄喃喃囈語閱讀 10,827評論 4 54