• UID20479
  • 登录2018-03-26
  • 粉丝0
  • 关注0
  • 发帖29
  • 主页
  • 金币127枚
公园 发布于2018-03-26 16:04
0/179

kafka集群安装

楼层直达
1. 在根目录创建kafka文件夹(service1、service2、service3都创建)
[root@localhost /]# mkdir kafka
2.通过Xshell上传文件到service1服务器:上传kafka_2.9.2-0.8.1.1.tgz到/software文件夹
3.远程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都执行)
[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都执行)
[root@localhost /]# cd /kafka/
[root@localhost kafka]# tar -zxvf kafka_2.9.2-0.8.1.1.tgz
5.创建kafka消息目录(service1,service2,service3都要创建)
[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  ---唯一标识
############################# Socket Server Settings #############################
# The port the socket server listens on
port=19092  --当前broker对外提供的TCP端口,默认9092
# Hostname the broker will bind to. If not set, the server will bind to all interfaces
host.name=192.168.2.213  --一般是关闭状态,我们要将它打开,如果dns解析失败,会出现文件句柄泄露,不要小看dns解析失败率,如果dns解析失败率为万分之一,由于kafka的性能非常高,每个topic的每个分区,每秒可以处理十万多条的数据,即使万分之一的失败率,每秒也要泄露10个文件句柄,很快句柄数就会泄露完毕,就会超过Linux打开文件的数,就会出现异常,所以我们配置ip,就不会进行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网络处理的线程数,一般不做处理
# The number of threads doing disk I/O
num.io.threads=8  --broker io处理的线程数,这个数量一定要比log.dirs的目录数要大
# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=1048576  --将发送的消息先放到缓冲区,当到达一定量的时候再一次性发出
# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=1048576  --kafka接受消息的缓冲区,当接受的数量达到一定量的时候再写入磁盘
# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600   --像kafka发送或者请求消息的最大数,此设置不能超过java堆栈大小
############################# Log Basics #############################
# A comma seperated list of directories under which to store log files
log.dirs=/kafka/kafkaLogs  --多个目录可以用,隔开
# 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  --一个topic默认分区数
############################# 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  --默认的复制因子,默认消息只有一个副本,不太安全,所以设置为2,如果某个分区的消息失败了,我们可以使用另一个分区的消息服务
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.启动kafka服务
[root@localhost bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@localhost bin]# jps
27413 Kafka
27450 Jps
17884 QuorumPeerMain
8.验证kafka集群
[root@localhost bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic test
Created topic "test".
9.在service1上开启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上开启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中发送消息: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
愿意了解框架技术或者源码的朋友直接求求2042849237
更多详细源码参考来源:http://minglisoft.cn/technology

0人打赏
您需要登录后才可以回帖
发表回复
极贡献
技术问答
专题荟萃
程序人生
视觉设计
Android开发
iOS开发
编程语言
前端开发
后端开发
服务器架构
软件测试
运维方案
创业路上



最热文章墙

  • 88746/384   【精品推荐】200多种Android动画效果的强悍框架,太全了,不看这个,再有动画的问题,不理你了^@^

  • 50870/191   情人节福利,程序员表白的正确姿势:改几行代码就变成自己的表白了

  • 48557/0   Python爬虫:常用浏览器的useragent

  • 46063/261   【精品推荐】Android版产品级的音乐播放器源码,功能太强大了,最好的产品原型有木有?

  • 42359/145   省时省力的Android组件群来了,非常棒的原型参考

  • 33635/143   2016抢红包软件及源码

  • 31478/71   原创表白APP,以程序员的姿势备战新年后的7夕,持续完善中!

  • 30210/2   超全!整理常用的iOS第三方资源

  • 27766/161   Android版类似UC浏览器:非常赞,产品级的源码

  • 24250/31   麻省理工的一帮疯子,真的实现了随意操控万物!(绝对黑科技)

  • 24025/27   2016程序员跳槽全攻略

  • 23925/26   Android工程师面试题大全

  • 22927/10   GitHub上排名前50的iOS项目:总有一款你用得着

  • 22171/21   码魂:程序员的牛B漫画

  • 21205/74   【持续更新中】Android福利贴(二):资料源码大放送

  • 20822/85   Android小而全的博客源码:非常适合全面掌握开发技巧

  • 20680/43   一个绚丽的loading动效分析与实现!

  • 19802/10   2016年最全的Android面试考题+答案 精编版

  • 19768/104   Android带弹幕的视频播放器源码,来自大名鼎鼎的Bilibili弹幕网站

  • 19720/3   吐槽那些程序员的搞笑牛逼注释

  • 19379/82   仿京东商城客户端Android最新版,不错的原型和学习资料

  • 19335/45   惊艳的App引导页:背景图片切换加各个页面动画效果

  • 18681/23   Android福利第三波【Android电子书】

  • 18597/25   个人收集的Android 各类功能源代码

  • 18537/81   【精品推荐】类似360安全卫士安Android源码:非常赞的产品原型

  • 18477/1   iOS 动画总结

  • 18252/1   iOS中文版资源库,非常全

  • 18074/5   新一代Android渠道打包工具:1000个渠道包只需要5秒

  • 18023/54   基于瀑布流的美女图片浏览App,有注释的源代码

  • 17661/18   用JavaScript 来开发iOS和Android 原生应用:React Native开源框架中文版来啦

  • 17465/19   65条最常用正则表达式,你要的都在这里了

  • 17407/23   珍藏多年的素材,灵感搜寻网站

  • 17183/10   女程序员的梦,众网友的神回复

  • 17030/11   年会上现场review代码是怎么样的体验!

  • 15836/16   基于Android支付宝支付设计和开发方案

  • 15660/62   【技巧一】搭配Android Studio,如何实现App远程真机debug?

  • 15560/18   什么是真正的黑客:收获12200+Stars,人气远超微软开源VS

  • 15482/47   在线音乐播放器完整版(商用级的源码):非常赞,可听免费高品质专辑

  • 15356/4   46 个非常有用的 PHP 代码片段

  • 15348/11   有木有这样一张酷图帮你集齐所有git命令超实用

  • 14648/0   GitHub iOS 库和框架Top100 

  • 14434/7   一张图搞定iOS学习路线,非常全面

  • 14384/7   用程序员的姿势抢过年的火车票

  • 14003/10   成为Java顶尖程序员 ,看这11本书就够了

  • 13974/10   微信支付终于成功了(安卓,iOS),在此分享

  • 13960/29   【持续更新中】Android福利贴(一):资料源码

  • 13946/18   一张图搞定Android学习路线,非常全面

  • 13861/1   基于node-webkit跨平台应用案例集之(一)

  • 13720/4   基于Node.js的强大爬虫,能直接发布抓取的文章哦

  • 12879/3   即时通信第三方库

  • 12501/9   流媒体视频直播方案

  • 12470/18   八个最优秀的Android Studio插件

  • 12331/2   【精品推荐】高质量PHP代码的50个实用技巧:非常值得收藏

  • 12176/1   过上惬意生活的精华资源:创业、工作、生活成长

  • 12168/9   B站建开源工作组:APP想支持炫酷弹幕的看过来

  • 11783/9   烧了5亿美金,这家神秘的公司即将颠覆人类未来!

  • 11761/12   中国黑客的隐秘江湖:攻守对立,顶尖高手月入千万美元

  • 11296/2   Android性能优化视频,文档以及工具

  • 11082/6   开箱即用!Android四款系统架构工具

  • 10861/4   10款GitHub上最火爆的国产开源项目——可以媲美西半球

  • 返回顶部