「Confluent/ZooKeeper」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
本頁面具有訪問限制。如果您看見此訊息,這代表您沒有訪問本頁面的權限。
行 70: 行 70:
</syntaxhighlight>
</syntaxhighlight>


 可以看輸出的資訊判斷系統狀態:
 可以看輸出的資訊判斷系統狀態 ,可以看<code>Mode</code>與<code>Node count</code>資訊簡單確認cluster的情況


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">

於 2019年12月30日 (一) 11:47 的修訂

Confluent/ZooKeeper指的是Confluent所包裝的Apache ZooKeeper,裡面有些路徑與設定檔的設法與官方版本不同。

防火牆

ZooKeeper的主機之間需要對開這些Port:

  • 2888/tcp
  • 3888/tcp

ZooKeeper的主機對外需要開這些Port:

  • 2181/tcp

設定ZooKeeper

修改/etc/kafka/zookeeper.properties,其中IP address需要填寫對應的位置:

#
tickTime=2000
dataDir=/var/lib/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=10.1.1.1:2888:3888
server.2=10.2.2.2:2888:3888
server.3=10.3.3.3:2888:3888
autopurge.snapRetainCount=3
autopurge.purgeInterval=24

新增/var/lib/zookeeper/myid,每一台都需要不同,123

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參數。

另外是增加JMX的監控機制,使用Port 32181。

這兩個需要新增/lib/systemd/system/confluent-zookeeper.service.d/30-options.conf(目錄可能需要自己建立):

[Service]
Environment=JMX_PORT=32181
Environment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"
Environment=KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=${hostip} -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=32181 -Dcom.sun.management.jmxremote.port=32181 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

對應的指令:

sudo mkdir /lib/systemd/system/confluent-zookeeper.service.d
echo -e '[Service]\nEnvironment=JMX_PORT=32181\nEnvironment=KAFKA_HEAP_OPTS="-Xmx7g -Xms7g"\nEnvironment=KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=${hostip} -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=32181 -Dcom.sun.management.jmxremote.port=32181 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"' | sudo tee /lib/systemd/system/confluent-zookeeper.service.d/30-options.conf

理論上就可以啟動了:

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

可以看輸出的資訊判斷系統狀態,可以看ModeNode count資訊簡單確認cluster的情況:

echo stat | nc 127.0.0.1 2181

或是直接透過指令操作測試:

zookeeper-shell 127.0.0.1:2181

接下來可以將TCP Port 2181建立對應的TCP Load Balancer(像是用ELB)。

認證

如果需要讓ZooKeeper啟用認證,需要先建立對應的帳號與密碼字串(這個例子裡面是adminpassword):

java -cp "$(echo /usr/share/java/kafka/* | sed 's/ /:/g')" org.apache.zookeeper.server.auth.DigestAuthenticationProvider admin:password

會產生像是這樣的輸出,其中後面的那串值是重點:

admin:password->admin:bjkZ9W+M82HUZ9xb8/Oy4cmJGfg=

->後面是將密碼處理過的字串,直接放進設定內:

KAKFA_OPTS=-Dzookeeper.DigestAuthenticationProvider.superDigest=admin:bjkZ9W+M82HUZ9xb8/Oy4cmJGfg=

這樣就可以在zookeeper-shell裡面認證:

addauth digest admin:password

相關連結

外部連結