centos下安装单机版kafka-0.10.0.1

1.环境说明

主机信息如下:
1
[root@test1 soft]# hostname
2
test1
3
[root@test1 soft]# cat /etc/hosts
4
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
5
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
6
192.168.56.91 test1 
7
192.168.56.92 test2 
8
192.168.56.93 test3 
9
192.168.56.1  PC-201306171517
10
操作系统版本如下:
1
[root@test1 soft]# cat /etc/redhat-release 
2
CentOS release 6.4 (Final)
3
[root@test1 soft]# uname -a
4
Linux test1 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
5

2.下载kafka

下载地址如下:
我这里使用 Scala 2.11  -  kafka_2.11-0.10.0.1.tgz  ( asc ,  md5 )版本

3.安装配置kafka

一.解压缩kafka

1
[root@test1 soft]# tar zxvf kafka_2.11-0.10.0.1.tgz -C /root/kafka

二.配置zookeeper

由于kafka需要使用到zookeeper来注册信息,因此需要首先配置zookeeper.在kafka的安装包中已经提供了zookeeper,不需要额外安装,直接配置一下即可.配置文件在config下的zookeeper. properties
1
[root@test1 config]# cat zookeeper.properties 
2
# Licensed to the Apache Software Foundation (ASF) under one or more
3
# contributor license agreements.  See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to You under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License.  You may obtain a copy of the License at
8
# 
9
#    http://www.apache.org/licenses/LICENSE-2.0
10
# 
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
# the directory where the snapshot is stored.
17
dataDir=/root/kafka/kafka_2.11-0.10.0.1/zoodata                       ###########这里修改zookeeper的快照目录,需要事先在文件系统上创建目录,其它默认即可.
18
# the port at which the clients will connect
19
clientPort=2181        #默认端口号2181
20
# disable the per-ip limit on the number of connections since this is a non-production config
21
maxClientCnxns=0
22

三.配置kafka

kafka的配置文件在config下的server.properties文件.下面是一个配置实例:
1
[root@test1 config]# pwd
2
/root/kafka/kafka_2.11-0.10.0.1/config
3
[root@test1 config]# cat server.properties 
4
# Licensed to the Apache Software Foundation (ASF) under one or more
5
# contributor license agreements.  See the NOTICE file distributed with
6
# this work for additional information regarding copyright ownership.
7
# The ASF licenses this file to You under the Apache License, Version 2.0
8
# (the "License"); you may not use this file except in compliance with
9
# the License.  You may obtain a copy of the License at
10
#
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS,
15
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
# See the License for the specific language governing permissions and
17
# limitations under the License.
18
# see kafka.server.KafkaConfig for additional details and defaults
19
20
############################# Server Basics #############################
21
22
# The id of the broker. This must be set to a unique integer for each broker.
23
broker.id=0                                                                                    ############################这里是主机的id,类似于zookeeper的id
24
25
############################# Socket Server Settings #############################
26
27
# The address the socket server listens on. It will get the value returned from 
28
# java.net.InetAddress.getCanonicalHostName() if not configured.
29
#   FORMAT:
30
#     listeners = security_protocol://host_name:port
31
#   EXAMPLE:
32
#     listeners = PLAINTEXT://your.host.name:9092
33
#listeners=PLAINTEXT://:9092
34
35
# Hostname and port the broker will advertise to producers and consumers. If not set, 
36
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
37
# returned from java.net.InetAddress.getCanonicalHostName().
38
#advertised.listeners=PLAINTEXT://your.host.name:9092                                         ###########默认的端口是9092,如果需要修改端口,需要添加port参数port=9093.再将advertised.listeners同时修改
39
40
# The number of threads handling network requests
41
num.network.threads=3
42
43
# The number of threads doing disk I/O
44
num.io.threads=8
45
46
# The send buffer (SO_SNDBUF) used by the socket server
47
socket.send.buffer.bytes=102400
48
49
# The receive buffer (SO_RCVBUF) used by the socket server
50
socket.receive.buffer.bytes=102400
51
52
# The maximum size of a request that the socket server will accept (protection against OOM)
53
socket.request.max.bytes=104857600
54
55
56
############################# Log Basics #############################
57
58
# A comma seperated list of directories under which to store log files
59
log.dirs=/root/kafka/kafka_2.11-0.10.0.1/logs                                                  ####################################这里是kafka的log目录,根据需要修改.
60
61
# The default number of log partitions per topic. More partitions allow greater
62
# parallelism for consumption, but this will also result in more files across
63
# the brokers.
64
num.partitions=1
65
66
# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
67
# This value is recommended to be increased for installations with data dirs located in RAID array.
68
num.recovery.threads.per.data.dir=1
69
70
############################# Log Flush Policy #############################
71
72
# Messages are immediately written to the filesystem but by default we only fsync() to sync
73
# the OS cache lazily. The following configurations control the flush of data to disk.
74
# There are a few important trade-offs here:
75
#    1. Durability: Unflushed data may be lost if you are not using replication.
76
#    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.
77
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.
78
# The settings below allow one to configure the flush policy to flush data after a period of time or
79
# every N messages (or both). This can be done globally and overridden on a per-topic basis.
80
81
# The number of messages to accept before forcing a flush of data to disk
82
#log.flush.interval.messages=10000
83
84
# The maximum amount of time a message can sit in a log before we force a flush
85
#log.flush.interval.ms=1000
86
87
############################# Log Retention Policy #############################
88
89
# The following configurations control the disposal of log segments. The policy can
90
# be set to delete segments after a period of time, or after a given size has accumulated.
91
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
92
# from the end of the log.
93
94
# The minimum age of a log file to be eligible for deletion
95
log.retention.hours=168
96
97
# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
98
# segments don't drop below log.retention.bytes.
99
#log.retention.bytes=1073741824
100
101
# The maximum size of a log segment file. When this size is reached a new log segment will be created.
102
log.segment.bytes=1073741824
103
104
# The interval at which log segments are checked to see if they can be deleted according
105
# to the retention policies
106
log.retention.check.interval.ms=300000
107
108
############################# Zookeeper #############################
109
110
# Zookeeper connection string (see zookeeper docs for details).
111
# This is a comma separated host:port pairs, each corresponding to a zk
112
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
113
# You can also append an optional chroot string to the urls to specify the
114
# root directory for all kafka znodes.
115
zookeeper.connect=localhost:2181
116
117
# Timeout in ms for connecting to zookeeper
118
zookeeper.connection.timeout.ms=6000
119
120

4.启动kafka

为了方便可以将kafka的运行目录添加到PATH环境变量中.
首先使用命令 bin/zookeeper-server-start.sh config/zookeeper.properties
启动zookeeper.
1
[root@test1 kafka_2.11-0.10.0.1]# nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties &
2
[1] 1888
3
[root@test1 kafka_2.11-0.10.0.1]# nohup: ignoring input and appending output to `nohup.out'
4
5
[root@test1 kafka_2.11-0.10.0.1]# jps
6
1888 QuorumPeerMain
7
2118 Jps
8
再使用命令 bin/kafka-server-start.sh config/server.properties
启动kafka
1
[root@test1 kafka_2.11-0.10.0.1]# nohup ./bin/kafka-server-start.sh config/server.properties &
2
[2] 2146
3
[root@test1 kafka_2.11-0.10.0.1]# nohup: ignoring input and appending output to `nohup.out'
4
5
[root@test1 kafka_2.11-0.10.0.1]# jps
6
1888 QuorumPeerMain
7
2146 Kafka
8
2411 Jps
9

5.模拟测试kafka发布订阅

新建一个窗口模拟producer,执行:
kafka-console-producer.sh --broker-list localhost:9092 --topic
然后在窗口中随便输入
1
[root@test1 kafka]# kafka-console-producer.sh --broker-list localhost:9092 --topic test
2
aaaa
3
bbbb
4
在另外一个窗口中模拟consumer,执行:
[root@test1 ~]# kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1 --from-beginning
然后会发现producer的输入会实时的发布到consumer中
1
[root@test1 ~]# kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1 --from-beginning
2
aaaa
3
bbbb
4
创建主题:
1
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看主题:
1
 bin/kafka-topics.sh --list --zookeeper localhost:2181

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值