confluent platform是一个可靠、高性能的流平台,提供组织和管理来自不同数据源数据的功能。(这个说法太正式,反正我是简单粗暴地把它当成kafka和一些扩展kafka功能的一套组件~)
废话不多说,直接开搞~
这个很简单,就跳过吧,不会的请自行度娘~
vim /etc/hosts
192.168.20.240 host240
192.168.20.239 host239
192.168.20.238 host238
(ps: zookeeper至少需要三台机子,然后改hosts需要root权限~)
虽然confluent platform自带一个,但是还是推荐自己装一个更高版本的~
zookeeper
tar -zxf zookeeper-3.4.11.tar.gz
cd zookeeper-3.4.11
复制一份conf/zoo_sample.cfg,命名为zoo.cfg
cp conf/zoo_sample.cfg conf/zoo.cfg
我的配置(修改的会有中文说明)如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#zookeeper数据目录
dataDir=/data/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#根据机子数目做相应的配置,server.x中的x是下面myid需要的
server.240=host240:2888:3888
server.239=host239:2888:3888
server.238=host238:2888:3888
(ps:这个配置每台机子都一样~)
在上一步配置的zookeeper数据目录下新建文件myid,加入上一步对应配置的x(比如host240对应配置的是240)
cat /data/zookeeper/myid
240
分别在三台主机上启动
bin/zkServer.sh start
https://www.confluent.io/download/
(ps: 选择下载开源版本,邮件可以乱填,只要能通过邮件的正则校验即可,不用登陆邮件确认~)
tar -zxf confluent-oss-4.0.0-2.11.tar.gz
cd confluent-oss-4.0.0
至少需要配置etc/kafka目录下的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.
# kafka broker id,必须唯一
broker.id=240
# Switch to enable topic deletion or not, default value is false
# 这个默认是false,不过建议打开方便删除~
delete.topic.enable=true
############################# 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
# kafka 监听端口,默认是9092
listeners=PLAINTEXT://:9092
# 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
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092
# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3
# The number of threads that the server uses for processing requests, which may include disk I/O
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
############################# Log Basics #############################
# A comma seperated list of directories under which to store log files
# kafka 日志保存路径
log.dirs=/data/gameserver/bigdata/confluent
# 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.
# 默认分区数(创建topic不指定分区数目时)
num.partitions=32
# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1
############################# Internal Topic Settings #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
############################# 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 due to age
# 日志保存时长
log.retention.hours=48
# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#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=1073741824
# 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
############################# 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地址(没有/confluent的话会保存在zookeeper的根目录~)
zookeeper.connect=host240:2181,host239:2181,host238:2181/confluent
# Timeout in ms for connecting to zookeeper
# zookeeper超时时间
zookeeper.connection.timeout.ms=6000
##################### Confluent Metrics Reporter #######################
# Confluent Control Center and Confluent Auto Data Balancer integration
#
# Uncomment the following lines to publish monitoring data for
# Confluent Control Center and Confluent Auto Data Balancer
# If you are using a dedicated metrics cluster, also adjust the settings
# to point to your metrics kakfa cluster.
#metric.reporters=io.confluent.metrics.reporter.ConfluentMetricsReporter
#confluent.metrics.reporter.bootstrap.servers=localhost:9092
#
# Uncomment the following line if the metrics cluster has a single broker
#confluent.metrics.reporter.topic.replicas=1
##################### Confluent Proactive Support ######################
# If set to true, and confluent-support-metrics package is installed
# then the feature to collect and report support metrics
# ("Metrics") is enabled. If set to false, the feature is disabled.
confluent.support.metrics.enable=false
############################# 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
# The customer ID under which support metrics will be collected and
# reported.
#
# When the customer ID is set to "anonymous" (the default), then only a
# reduced set of metrics is being collected and reported.
#
# Confluent customers
# -------------------
# If you are a Confluent customer, then you should replace the default
# value with your actual Confluent customer ID. Doing so will ensure
# that additional support metrics will be collected and reported.
#
confluent.support.customer.id=anonymous
这里只展示kafka的配置,其他组件的配置也都在etc目录下,根据自己的需要选择相应的配置即可~
(ps:别忘了host239和host238两台机子也需要做相同的配置,除了broker.id之外~)
启动脚本都在bin目录下面,分别在三台机子上启动命令
nohup ./bin/kafka-server-start ./etc/kafka/server.properties &
先通过Java的jps命令查看是否存在SupportedKafka进程,再查看logs/server.log是否有报错信息。
(ps:其他的组件基本上都是修改配置,然后用上面类似的启动命令启动,就不一一展示了~)
如果启动没问题了,可以试着在一台机子新建topic
bin/kafka-topics --create --zookeeper host240:2181,host239:2181,host238:2181/confluent --replication-factor 1 --partitions 1 --topic test
然后在其他机子查看是否能看到新建的topic
bin/kafka-topics --list --zookeeper host240:2181,host239:2181,host238:2181/confluent
如果能看到的话基本就算装好了,可以试着往里面写点数据
bin/kafka-console-producer --broker-list host240:9092,host239:9092,host238:9092 --topic test
This is a message
然后读取看看
bin/kafka-console-consumer --bootstrap-server host240:9092,host239:9092,host238:9092 --topic test --from-beginning
如果能读取到写入的数据,kafka就算启动成功了。