JEESZ-kafka集群安裝

1. 在根目錄創(chuàng)建kafka文件夾(service1虾标、service2焙蹭、service3都創(chuàng)建)

[root@localhost /]# mkdir kafka

2.通過(guò)Xshell上傳文件到service1服務(wù)器:上傳kafka_2.9.2-0.8.1.1.tgz到/software文件夾

3.遠(yuǎn)程copy將service1下的/software/kafka_2.9.2-0.8.1.1.tgz到service2撑柔、service3

[root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz root@192.168.2.212:/software/

[root@localhost software]# scp -r /software/kafka_2.9.2-0.8.1.1.tgz root@192.168.2.213:/software/

3.copy /software/kafka_2.9.2-0.8.1.1.tgz到/kafka/目錄(service1囱淋、service2剃毒、service3都執(zhí)行)

[root@localhost software]# cp /software/kafka_2.9.2-0.8.1.1.tgz /kafka/

4.安裝解壓kafka_2.9.2-0.8.1.1.tgz(service1宝剖、service2洁闰、service3都執(zhí)行)

[root@localhost /]# cd /kafka/

[root@localhost kafka]# tar -zxvf kafka_2.9.2-0.8.1.1.tgz

5.創(chuàng)建kafka消息目錄(service1,service2,service3都要?jiǎng)?chuàng)建)

[root@localhost kafka]# mkdir kafkaLogs

6. 修改kafka的配置文件(service1,service2,service3都要配置)

[root@localhost /]# cd /kafka/kafka_2.9.2-0.8.1.1/

[root@localhost kafka_2.9.2-0.8.1.1]# cd config/

[root@localhost config]# ls

consumer.properties ?log4j.properties ?producer.properties ?server.properties ?test-log4j.properties ?tools-log4j.properties ?zookeeper.properties

[root@localhost config]# vi server.properties

# 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 ?---唯一標(biāo)識(shí)

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

# The port the socket server listens on

port=19092 ?--當(dāng)前broker對(duì)外提供的TCP端口,默認(rèn)9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces

host.name=192.168.2.213 ?--一般是關(guān)閉狀態(tài),我們要將它打開(kāi)万细,如果dns解析失敗扑眉,會(huì)出現(xiàn)文件句柄泄露,不要小看dns解析失敗率赖钞,如果dns解析失敗率為萬(wàn)分之一腰素,由于kafka的性能非常高,每個(gè)topic的每個(gè)分區(qū)雪营,每秒可以處理十萬(wàn)多條的數(shù)據(jù)弓千,即使萬(wàn)分之一的失敗率,每秒也要泄露10個(gè)文件句柄献起,很快句柄數(shù)就會(huì)泄露完畢洋访,就會(huì)超過(guò)linux打開(kāi)文件的數(shù),就會(huì)出現(xiàn)異常谴餐,所以我們配置ip姻政,就不會(huì)進(jìn)行dns解析

# Hostname the broker will advertise to producers and consumers. If not set, it uses the

# value for "host.name" if configured. ?Otherwise, it will use the value returned from

# java.net.InetAddress.getCanonicalHostName().

#advertised.host.name=

# The port to publish to ZooKeeper for clients to use. If this is not set,

# it will publish the same port that the broker binds to.

#advertised.port=

# The number of threads handling network requests

num.network.threads=2 ? --broker網(wǎng)絡(luò)處理的線程數(shù),一般不做處理

# The number of threads doing disk I/O

num.io.threads=8 ?--broker io處理的線程數(shù)岂嗓,這個(gè)數(shù)量一定要比log.dirs的目錄數(shù)要大

# The send buffer (SO_SNDBUF) used by the socket server

socket.send.buffer.bytes=1048576 ?--將發(fā)送的消息先放到緩沖區(qū)汁展,當(dāng)?shù)竭_(dá)一定量的時(shí)候再一次性發(fā)出

# The receive buffer (SO_RCVBUF) used by the socket server

socket.receive.buffer.bytes=1048576 ?--kafka接受消息的緩沖區(qū),當(dāng)接受的數(shù)量達(dá)到一定量的時(shí)候再寫入磁盤

# The maximum size of a request that the socket server will accept (protection against OOM)

socket.request.max.bytes=104857600 ? --像kafka發(fā)送或者請(qǐng)求消息的最大數(shù),此設(shè)置不能超過(guò)java堆棧大小

############################# Log Basics #############################

# A comma seperated list of directories under which to store log files

log.dirs=/kafka/kafkaLogs ?--多個(gè)目錄可以用食绿,隔開(kāi)

# The default number of log partitions per topic. More partitions allow greater

# parallelism for consumption, but this will also result in more files across

# the brokers.

num.partitions=2 ?--一個(gè)topic默認(rèn)分區(qū)數(shù)

############################# 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.

# ? ?2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.

# ? ?3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.

# The settings below allow one to configure the flush policy to flush data after a period of time or

# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# 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

# be set to delete segments after a period of time, or after a given size has accumulated.

# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens

# from the end of the log.

# The minimum age of a log file to be eligible for deletion

log.retention.hours=168

message.max.byte=5048576 ? --kafka每條消息容納的最大大小

default.replication.factor=2 ?--默認(rèn)的復(fù)制因子侈咕,默認(rèn)消息只有一個(gè)副本,不太安全器紧,所以設(shè)置為2耀销,如果某個(gè)分區(qū)的消息失敗了,我們可以使用另一個(gè)分區(qū)的消息服務(wù)

replica.fetch.max.byte=5048576 --kafka每條消息容納的最大大小

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining

# segments don't drop below log.retention.bytes.

#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.

log.segment.bytes=536870912 ?--消息持久化的最大大小

# 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=60000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.

# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.

log.cleaner.enable=false ?--不使用log壓縮

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

# Zookeeper connection string (see zookeeper docs for details).

# This is a comma separated host:port pairs, each corresponding to a zk

# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".

# You can also append an optional chroot string to the urls to specify the

# root directory for all kafka znodes.

zookeeper.connect=192.168.2.211:2181,192.168.2.212:2181,192.168.2.213:2181 ? --zk地址

# Timeout in ms for connecting to zookeeper

zookeeper.connection.timeout.ms=1000000

7.啟動(dòng)kafka服務(wù)

[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server.properties

[root@localhost bin]# jps

27413 Kafka

27450 Jps

17884 QuorumPeerMain

8.驗(yàn)證kafka集群

[root@localhost bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic test

Created topic "test".

9.在service1上開(kāi)啟producer程序

./kafka-console-producer.sh --broker-list 192.168.2.211:9092 --topic test

[root@localhost bin]# ./kafka-console-producer.sh --broker-list 192.168.2.211:9092 --topic test

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.

10. 在service2上開(kāi)啟consumer程序

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.

11.在producer中發(fā)送消息:hello jeesz

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.

hello jeesz

12. 在consumer中接受到消息

[root@localhost bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor further details.

hello jeesz

源碼來(lái)源:http://minglisoft.cn/technology

歡迎大家一起學(xué)習(xí)研究相關(guān)技術(shù)品洛,源碼獲取請(qǐng)加求求(企鵝): 2042849237

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末树姨,一起剝皮案震驚了整個(gè)濱河市摩桶,隨后出現(xiàn)的幾起案子桥状,更是在濱河造成了極大的恐慌,老刑警劉巖硝清,帶你破解...
    沈念sama閱讀 206,126評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件辅斟,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡芦拿,警方通過(guò)查閱死者的電腦和手機(jī)士飒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)蔗崎,“玉大人酵幕,你說(shuō)我怎么就攤上這事』嚎粒” “怎么了芳撒?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,445評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)未桥。 經(jīng)常有香客問(wèn)我笔刹,道長(zhǎng),這世上最難降的妖魔是什么冬耿? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,185評(píng)論 1 278
  • 正文 為了忘掉前任舌菜,我火速辦了婚禮,結(jié)果婚禮上亦镶,老公的妹妹穿的比我還像新娘日月。我一直安慰自己,他們只是感情好缤骨,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評(píng)論 5 371
  • 文/花漫 我一把揭開(kāi)白布山孔。 她就那樣靜靜地躺著,像睡著了一般荷憋。 火紅的嫁衣襯著肌膚如雪台颠。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 48,970評(píng)論 1 284
  • 那天,我揣著相機(jī)與錄音串前,去河邊找鬼瘫里。 笑死,一個(gè)胖子當(dāng)著我的面吹牛荡碾,可吹牛的內(nèi)容都是我干的谨读。 我是一名探鬼主播,決...
    沈念sama閱讀 38,276評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼坛吁,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼劳殖!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起拨脉,我...
    開(kāi)封第一講書(shū)人閱讀 36,927評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤哆姻,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后玫膀,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體矛缨,經(jīng)...
    沈念sama閱讀 43,400評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評(píng)論 2 323
  • 正文 我和宋清朗相戀三年帖旨,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了箕昭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 37,997評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡解阅,死狀恐怖落竹,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情货抄,我是刑警寧澤述召,帶...
    沈念sama閱讀 33,646評(píng)論 4 322
  • 正文 年R本政府宣布,位于F島的核電站碉熄,受9級(jí)特大地震影響桨武,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜锈津,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評(píng)論 3 307
  • 文/蒙蒙 一呀酸、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧琼梆,春花似錦性誉、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,204評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至煌往,卻和暖如春倾哺,著一層夾襖步出監(jiān)牢的瞬間轧邪,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,423評(píng)論 1 260
  • 我被黑心中介騙來(lái)泰國(guó)打工羞海, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留忌愚,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,423評(píng)論 2 352
  • 正文 我出身青樓却邓,卻偏偏與公主長(zhǎng)得像硕糊,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子腊徙,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容