Apache Kafka:修订间差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
第20行: 第20行:
== 設定 ==
== 設定 ==


* 修改<code>/opt/kafka/config/server.properties</code>內的<code>broker.id</code>,這邊一台設<code>1</code>,另外一台設<code>2</code>。
  修改<code>/opt/kafka/config/server.properties</code>內的 一些設定:
* 修改<code>/opt/kafka/config/server.properties</code>內的<code>zookeeper.connect</code>:
 
** 改成三台ZooKeeper主機的位置,像是<code>zookeeper.connect=1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181</code>。
<syntaxhightlight lang="ini">
** 或是改成對應的TCP load balancer,像是<code>test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com:2181</code>。
# 每一台都要不同
** 其中<code>:2181</code>是預設TCP Port,可以省略。
broker.id=1
* 修改<code>log.dirs</code>,預設是寫到<code>/tmp/kafka-logs</code>下,改成寫到<code>/var/lib/kafka-logs</code> ,並且 建立對應 目錄與權限 (像是<code>sudo install -d -o nobody -g nogroup -m 0700 /var/lib/kafka-logs</code> )。
 
* 安裝systemd設定(<code>/lib/systemd/system/kafka.service</code>) ,並且使用<code>sudo systemctl daemon-reload; sudo systemctl enable kafka; sudo service kafka start</code>啟動
#
log.dir=/var/lib/kafka-logs
 
# w/o TCP load balancer (ELB in this case) and w/. ":2181" can be implicit due to default port.
zookeeper.connect=1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181
zookeeper.connect=1.2.3.4,5.6.7.8,9.10.11.12
zookeeper.connect=test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com:2181
zookeeper.connect=test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com
</syntaxhighlight>
 
建立對應 的log 目錄與權限
 
<syntaxhighlight lang="bash">
sudo install -d -o nobody -g nogroup -m 0700 /var/lib/kafka-logs
</syntaxhighlight>
 
 
 安裝systemd設定(<code>/lib/systemd/system/kafka.service</code>):
<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
[Unit]
[Unit]
第44行: 第61行:
[Install]
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
</syntaxhighlight>
使用下面指令設定在開機時啟動,並且馬上啟動:
<syntaxhighlight lang="bash">
sudo systemctl daemon-reload
sudo systemctl enable kafka
sudo service kafka start
</syntaxhighlight>
</syntaxhighlight>



2019年3月5日 (二) 05:14的版本

Apache Kafka是一套基于JavaScala,提供Streaming架构的软件。

介绍

Kafka本身不过多处理多节点之间的效能问题,而是透过ZooKeeper处理。可以从“#测试”的章节看到操作时都是指定ZooKeeper当作API Endpoint。在Production环境上,一般我们会用TCP load balancer放在前面,让用户端架构比较简单(仅需设定单一名称)。

安装

目前在Ubuntu上没有系统套件或是PPA可以安装,一般是自行下载后装到/opt下。最新版的资讯可以在Kafka的Download页面得到,这边使用2.1.1版:

cd /tmp
wget https://ftp.jaist.ac.jp/pub/apache/kafka/2.1.1/kafka_2.12-2.1.1.tgz
cd /opt
sudo tar zxvf /tmp/kafka_2.12-2.1.1.tgz
sudo chown -R nobody:nogroup kafka_2.12-2.1.1/
sudo ln -fs kafka_2.12-2.1.1 kafka

设定

先修改/opt/kafka/config/server.properties内的一些设定:

<syntaxhightlight lang="ini">

  1. 每一台都要不同

broker.id=1

log.dir=/var/lib/kafka-logs

  1. w/o TCP load balancer (ELB in this case) and w/. ":2181" can be implicit due to default port.

zookeeper.connect=1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181 zookeeper.connect=1.2.3.4,5.6.7.8,9.10.11.12 zookeeper.connect=test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com:2181 zookeeper.connect=test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com </syntaxhighlight>

建立对应的log目录与权限:

sudo install -d -o nobody -g nogroup -m 0700 /var/lib/kafka-logs


安装systemd设定(/lib/systemd/system/kafka.service):

[Unit]
Description=Apache Kafka server (broker)
Documentation=https://kafka.apache.org/documentation.html
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=nobody
Group=nogroup
Environment=JAVA_HOME=/usr
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

使用下面指令设定在开机时启动,并且马上启动:

sudo systemctl daemon-reload
sudo systemctl enable kafka
sudo service kafka start

测试

没有TCP load balancer时可以直接指定所有的ZooKeeper主机:

/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181
/opt/kafka/bin/kafka-topics.sh --create --zookeeper 1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181 --replication-factor 2 --partitions 1 --topic my-replicated-topic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 1.2.3.4:2181,5.6.7.8:2181,9.10.11.12:2181

其中所有的:2181都可以简化省略,因为ZooKeeper的预设Port就是Port 2181:

/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 1.2.3.4,5.6.7.8,9.10.11.12
/opt/kafka/bin/kafka-topics.sh --create --zookeeper 1.2.3.4,5.6.7.8,9.10.11.12 --replication-factor 2 --partitions 1 --topic my-replicated-topic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 1.2.3.4,5.6.7.8,9.10.11.12

有TCP load balancer时:

/opt/kafka/bin/kafka-topics.sh --describe --zookeeper test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com
/opt/kafka/bin/kafka-topics.sh --create --zookeeper test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com --replication-factor 2 --partitions 1 --topic my-replicated-topic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper test-gslin-zookeeper-xxxxxxxxx.us-east-1.elb.amazonaws.com

外部链接