kafka集群搭建

来源:互联网 发布:天猫商城的网络推广 编辑:程序博客网 时间:2024/06/07 04:09

快速教程

http://kafka.apache.org/quickstart

下载kafka

进入下载页面:http://kafka.apache.org/downloads.html

也可以直接在linux终端下载:

wget -q http://apache.fayea.com/apache-mirror/kafka/0.8.1/kafka_2.8.0-0.8.1.tgz

解压,修改config下的server.properties

主要修改

broker.id=第几个节点hostname=本机ipzookeeper.connect=zk-ip1:clinet-port,zk-ip2:clinet-port,zk-ip3:clinet-port
# 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=2############################# Socket Server Settings ############################## The port the socket server listens onport=9092# Hostname the broker will bind to. If not set, the server will bind to all interfaces#host.name=localhosthost.name=10.100.6.177# 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=<hostname routable by clients># 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=<port accessible by clients># The number of threads handling network requestsnum.network.threads=2# The send buffer (SO_SNDBUF) used by the socket serversocket.send.buffer.bytes=1048576# The receive buffer (SO_RCVBUF) used by the socket serversocket.receive.buffer.bytes=1048576# The maximum size of a request that the socket server will accept (protection against OOM)socket.request.max.bytes=104857600############################# Log Basics ############################## A comma seperated list of directories under which to store log fileslog.dirs=/tmp/kafka-logs# 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############################# 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.#    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# 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 deletionlog.retention.hours=168# 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 policieslog.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############################# 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=10.100.6.147:2181,10.100.6.176:2181,10.100.6.177:2181# Timeout in ms for connecting to zookeeperzookeeper.connection.timeout.ms=1000000

测试

启动Kafka server:

bin/kafka-server-start.sh config/server.properties &

停止Kafka server

bin/kafka-server-stop.sh

停止Zookeeper server:

bin/zookeeper-server-stop.sh

jps查看进程

分布式连通性测试

Zookeeper Server, Kafka Server, Producer都放在服务器server1上,ip地址为192.168.1.10
Consumer放在服务器server2上,ip地址为192.168.1.12。

分别运行server1的producer和server2的consumer

bin/kafka-console-producer.sh --broker-list 192.168.1.10:9092 --topic test
bin/kafka-console-consumer.sh --zookeeper 192.168.1.10:2181 --topic test --from-beginning

在producer的console端输入字符串hello kafka,consumer报hello kafka

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 别人冒充我的微信名和头像怎么办 快餐店无证经营被工商局查了怎么办 买的圣才电子书只有在线版怎么办 吃了汤汤水水奶水还是少怎么办 粗肋草叶子和劲长白点怎么办 海鲜泡的时间长了有味了怎么办 富贵竹新长出来的叶子发黄怎么办 家里养的竹子的叶子发黄怎么办 发财树叶子发黄发黑怎么办打蔫 装修公司把衣柜型号弄错了怎么办 隔水炖锅里的陶瓷坏了怎么办? 色选大米带出比大怎么办? 做手足印如果漆刷到外面了怎么办 小区房子整租给民工影响邻居怎么办 种植牙植体中间的螺丝滑丝怎么办 宝宝1岁了牙齿表面脱落了怎么办 1岁3个月宝宝牙齿发黑脱落怎么办 种植牙中央螺栓断在牙根里怎么办 欧联杯冠军已经获得欧冠资格怎么办 孩子该上学了学校不收怎么办 帮室友带东西她忘给钱怎么办? 鸿合录播系统不会自动跟踪了怎么办 小米2s锁屏密码忘了怎么办 想用中国驾照去美国开车怎么办? 5座的车坐7个人怎么办 海尔电视机的设置调乱了怎么办 老公弟兄两个有个偏心的婆婆怎么办 农商银行u盾密码忘了怎么办 不熟的表弟表妹向你借钱怎么办 开货车撞到人家房子了怎么办 坐骨被摔跤后好多年没好怎么办 自动挡汽车电子手刹刹车失灵怎么办 买家拍了不包邮的宝贝付款了怎么办 包邮快递买家不要了运费怎么办 舞蹈劈叉练出肌肉劈不下去怎么办 腰间盘突出压迫神经腿疼怎么办盘 绑定了我身份证的微信被盗了怎么办 用身份证办的手机卡不用了怎么办 平安陆金所交易密码忘了怎么办 陆金所密码交易密码忘记怎么办 带介指手指月肿了拿不下来怎么办