「Confluent」:修訂間差異
第83行: | 第83行: | ||
接下來可以將TCP Port 2181建立對應的TCP Load Balancer(像是用ELB)。 | 接下來可以將TCP Port 2181建立對應的TCP Load Balancer(像是用ELB)。 | ||
=== 認證 === | |||
如果需要讓ZooKeeper啟用認證,需要先建立對應的帳號與密碼字串(這個例子裡面是<code>admin</code>與<code>password</code>): | |||
<syntaxhighlight lang="bash"> | |||
java -cp "$(echo /usr/share/java/kafka/* | sed 's/ /:/g')" org.apache.zookeeper.server.auth.DigestAuthenticationProvider admin:password | |||
</syntaxhighlight> | |||
會產生像是這樣的輸出,其中後面的那串值是重點: | |||
<syntaxhighlight lang="text"> | |||
admin:password->admin:bjkZ9W+M82HUZ9xb8/Oy4cmJGfg= | |||
</syntaxhighlight> | |||
== 設定Kafka == | == 設定Kafka == |
於 2019年3月12日 (二) 01:18 的修訂
Confluent是一家公司,也是該公司的Apache Kafka產品名。
簡介
Confluent是Apache Kafka發明人出來開的公司,也是目前最知名的Kafka商業支援服務。同時Confluent也是該公司推出的軟體品牌,提供了眾多的Open Source套件用以管理Kafka Cluster(即社群版本元件),另外提供商用版本,包括Control Center(提供三十天試用)。
硬體
在PoC時我使用了三台t3.small
(2 GB RAM,另外手動設定加上512 MB Swap),三台都安裝完整的套件並且跑起來,一開始不會有問題,但跑一陣子後會因為記憶體不足而異常。建議在正式環境下建議使用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
修改/etc/kafka/zookeeper.properties
,其中IP address需要填寫對應的位置:
#
tickTime=2000
dataDir=/var/lib/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=1.2.3.4:2888:3888
server.2=5.6.7.8:2888:3888
server.3=9.10.11.12:2888:3888
autopurge.snapRetainCount=3
autopurge.purgeInterval=24
新增/var/lib/zookeeper/myid
,每一台都需要不同,1
或2
或3
:
1
然後修改檔案擁有人:
sudo chown cp-kafka:confluent /var/lib/zookeeper/myid
目前的ZooKeeper(Confluent 2.11版內的ZooKeeper)預設值是使用512 MB的記憶體,但主機有7.5 GB的記憶體,所以會想要讓ZooKeeper可以用7 GB,因此需要修改ZooKeeper的JVM參數。這邊需要新增/lib/systemd/system/confluent-zookeeper.service.d/30-options.conf
(目錄可能需要自己建立):
[Service]
Environment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"
理論上就可以啟動了:
sudo systemctl daemon-reload
sudo service confluent-zookeeper start
sudo service confluent-zookeeper status
可以看輸出的資訊判斷系統狀態:
echo stat | nc 127.0.0.1 2181
或是直接透過指令操作測試:
zookeeper-shell 127.0.0.1:2181
接下來可以將TCP Port 2181建立對應的TCP Load Balancer(像是用ELB)。
認證
如果需要讓ZooKeeper啟用認證,需要先建立對應的帳號與密碼字串(這個例子裡面是admin
與password
):
java -cp "$(echo /usr/share/java/kafka/* | sed 's/ /:/g')" org.apache.zookeeper.server.auth.DigestAuthenticationProvider admin:password
會產生像是這樣的輸出,其中後面的那串值是重點:
admin:password->admin:bjkZ9W+M82HUZ9xb8/Oy4cmJGfg=
設定Kafka
如果ZooKeeper與Kafka不同伺服器,需要修改/etc/kafka/server.properties
的zookeeper.connect
的值,像是這樣:
#zookeeper.connect=localhost:2181
zookeeper.connect=internal-test-gslin-confluent-xxxxxxxxx.us-east-1.elb.amazonaws.com:2181
修改/etc/kafka/server.properties
的broker.id
設定,讓他自動產生而不需要自己指定:
#broker.id=0
broker.id.generation.enable=true
理論上就可以啟動了:
sudo service confluent-confluent start
sudo service confluent-confluent status
設定其他套件
啟動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