「Confluent」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
本頁面具有訪問限制。如果您看見此訊息,這代表您沒有訪問本頁面的權限。
(未顯示同一使用者於中間所作的 8 次修訂)
行 13: 行 13:
== 安裝 ==
== 安裝 ==


 當然要先裝[[Java]]:
 當然要先裝[[Java]] ,然後安裝社群版本


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo apt install -y default-jre
sudo apt install -y default-jre
</syntaxhighlight>
這邊只安裝社群版本:
<syntaxhighlight lang="bash">
wget -qO - https://packages.confluent.io/deb/5.1/archive.key | sudo apt-key add -; sudo add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"; sudo apt install -y confluent-community-2.11
wget -qO - https://packages.confluent.io/deb/5.1/archive.key | sudo apt-key add -; sudo add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"; sudo apt install -y confluent-community-2.11
</syntaxhighlight>
</syntaxhighlight>
行 35: 行 30:
<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
#zookeeper.connect=localhost:2181
#zookeeper.connect=localhost:2181
zookeeper.connect=internal-test-gslin-confluent-xxxxxxxxx.us-east-1.elb.amazonaws.com:2181
zookeeper.connect=internal-test-kafka-zookeeper-123456789.us-east-1.elb.amazonaws.com:2181
</syntaxhighlight>
</syntaxhighlight>


行 43: 行 38:
#broker.id=0
#broker.id=0
broker.id.generation.enable=true
broker.id.generation.enable=true
</syntaxhighlight>
理論上就可以啟動了:
<syntaxhighlight lang="bash">
sudo service confluent-kafka start
sudo service confluent-kafka status
</syntaxhighlight>
</syntaxhighlight>


行 59: 行 47:
</syntaxhighlight>
</syntaxhighlight>


 設完後重
對應的指令:
 
<syntaxhighlight lang="bash">
sudo mkdir /lib/systemd/system/confluent-kafka.service.d/
echo -e '[Service]\nEnvironment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"' | sudo tee /lib/systemd/system/confluent-kafka.service.d/30-options.conf
</syntaxhighlight>
 
 設完後 就可以讓systemd 讀設定後啟動


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
行 66: 行 61:
sudo service confluent-kafka status
sudo service confluent-kafka status
</syntaxhighlight>
</syntaxhighlight>
== 基本操作 ==
=== topic ===
topic的操作都是透過<code>kafka-topics</code>處理,其中在較新的版本是使用<code>--bootstrap-server</code>指定Broker位置當作接口,在較舊版本則是使用<code>--zookeeper</code>指定ZooKeeper位置當作接口。
建立是<code>--create</code>:
<syntaxhighlight lang="bash">
kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --create --topic test --replication-factor 3 --partitions 1
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --create --topic test --replication-factor 3 --partitions 1
</syntaxhighlight>
觀看是透過<code>--list</code>(簡易)或是<code>--describe</code>(詳細):
<syntaxhighlight lang="bash">
kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --list
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --list
</syntaxhighlight>
<syntaxhighlight lang="bash">
kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --describe
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --describe
</syntaxhighlight>
刪除topic則是透過<code>--delete</code>:
<syntaxhighlight lang="bash">
kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --delete --topic test
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --delete --topic test
</syntaxhighlight>
預設值只會標記(<code>MarkedForDeletion</code>),而非實際刪除:
<pre>
Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
</pre>


== 設定其他套件 ==
== 設定其他套件 ==

於 2019年4月23日 (二) 09:15 的修訂

Confluent是一家公司,也是該公司的Apache Kafka產品線的產品名。

簡介

Confluent是Apache Kafka發明人出來開的公司,也是目前最知名的Kafka商業支援服務。同時Confluent也是該公司推出的軟體品牌,提供了眾多的Open Source套件用以管理Kafka Cluster(即社群版本元件),另外提供商用版本,包括Control Center(提供三十天試用)。

硬體

在PoC時我使用了三台t3.small(2 GB RAM,另外手動設定加上512 MB Swap),三台都安裝完整的套件並且跑起來,一開始不會有問題,但跑一陣子後會因為記憶體不足而異常。

建議在正式環境下ZooKeeper部分建議使用m5.large(8 GB RAM)或是更好的機器執行。

安裝

當然要先裝Java,然後安裝社群版本:

sudo apt install -y default-jre
wget -qO - https://packages.confluent.io/deb/5.1/archive.key | sudo apt-key add -; sudo add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"; sudo apt install -y confluent-community-2.11

設定ZooKeeper

設定Kafka

如果ZooKeeperKafka不同伺服器,需要修改/etc/kafka/server.propertieszookeeper.connect的值,像是這樣:

#zookeeper.connect=localhost:2181
zookeeper.connect=internal-test-kafka-zookeeper-123456789.us-east-1.elb.amazonaws.com:2181

修改/etc/kafka/server.propertiesbroker.id設定,讓他自動產生而不需要自己指定:

#broker.id=0
broker.id.generation.enable=true

另外可以設定/lib/systemd/system/confluent-kafka.service.d/30-options.conf(目錄可能會需要自己建立),讓Kafka吃滿記憶體(這邊假設是8 GB的記憶體,保留1 GB給系統與其他情境使用):

[Service]
Environment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"

對應的指令:

sudo mkdir /lib/systemd/system/confluent-kafka.service.d/
echo -e '[Service]\nEnvironment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"' | sudo tee /lib/systemd/system/confluent-kafka.service.d/30-options.conf

設完後就可以讓systemd重讀設定後啟動:

sudo systemctl daemon-reload
sudo service confluent-kafka start
sudo service confluent-kafka status

基本操作

topic

topic的操作都是透過kafka-topics處理,其中在較新的版本是使用--bootstrap-server指定Broker位置當作接口,在較舊版本則是使用--zookeeper指定ZooKeeper位置當作接口。

建立是--create

kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --create --topic test --replication-factor 3 --partitions 1
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --create --topic test --replication-factor 3 --partitions 1

觀看是透過--list(簡易)或是--describe(詳細):

kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --list
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --list
kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --describe
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --describe

刪除topic則是透過--delete

kafka-topics --bootstrap-server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com --delete --topic test
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --delete --topic test

預設值只會標記(MarkedForDeletion),而非實際刪除:

Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

設定其他套件

啟動Schema Registry:

sudo service confluent-schema-registry start
sudo service confluent-schema-registry status

啟動Kafka Connect:

sudo service confluent-kafka-connect start
sudo service confluent-kafka-connect status

啟動Kafka REST Proxy:

sudo service confluent-kafka-rest start
sudo service confluent-kafka-rest status

啟動KSQL:

sudo service confluent-ksql start
sudo service confluent-ksql status

相關連結

外部連結