Categories
DevOps

How to provide additional JVM options to ZooKeeper instance

Provide additional JVM options to the ZooKeeper instance.

Assuming that configuration is located in /opt/zookeeper/zookeeper/conf directory.

$ /opt/zookeeper/zookeeper/bin/zkServer.sh --config /opt/zookeeper/zookeeper/conf start 

Create zookeeper-env.sh shell script.

$ sudo -u zookeeper cat /opt/zookeeper/zookeeper/conf/zookeeper-env.sh
# additional JVM FLAGS
JVMFLAGS="-Dzookeeper.tcpKeepAlive=true"

# HEAP SIZE (M)
ZK_SERVER_HEAP="512"

Display ZooKeeper command.

$ sudo -u zookeeper /opt/zookeeper/zookeeper/bin/zkServer.sh --config /opt/zookeeper/zookeeper/conf print-cmd
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/zookeeper/conf/zoo.cfg
"java"  -Dzookeeper.log.dir="/opt/zookeeper/zookeeper/bin/../logs"     
-Dzookeeper.log.file="zookeeper-root-server-zookeeper1.log" -Dzookeeper.root.logger="INFO,CONSOLE"     
-XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p'     
-cp "/opt/zookeeper/zookeeper/bin/../zookeeper-server/target/classes:/opt/zookeeper/zookeeper/bin/../build/classes:/opt/zookeeper/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/opt/zookeeper/zookeeper/bin/../build/lib/*.jar:/opt/zookeeper/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/opt/zookeeper/zookeeper/bin/../lib/zookeeper-jute-3.7.0.jar:/opt/zookeeper/zookeeper/bin/../lib/zookeeper-3.7.0.jar:/opt/zookeeper/zookeeper/bin/../lib/snappy-java-1.1.7.7.jar:/opt/zookeeper/zookeeper/bin/../lib/slf4j-log4j12-1.7.30.jar:/opt/zookeeper/zookeeper/bin/../lib/slf4j-api-1.7.30.jar:/opt/zookeeper/zookeeper/bin/../lib/simpleclient_servlet-0.9.0.jar:/opt/zookeeper/zookeeper/bin/../lib/simpleclient_hotspot-0.9.0.jar:/opt/zookeeper/zookeeper/bin/../lib/simpleclient_common-0.9.0.jar:/opt/zookeeper/zookeeper/bin/../lib/simpleclient-0.9.0.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-transport-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-resolver-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-handler-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-common-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-codec-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/netty-buffer-4.1.59.Final.jar:/opt/zookeeper/zookeeper/bin/../lib/metrics-core-4.1.12.1.jar:/opt/zookeeper/zookeeper/bin/../lib/log4j-1.2.17.jar:/opt/zookeeper/zookeeper/bin/../lib/jline-2.14.6.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-util-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-server-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-security-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-io-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/jetty-http-9.4.38.v20210224.jar:/opt/zookeeper/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/zookeeper/zookeeper/bin/../lib/jackson-databind-2.10.5.1.jar:/opt/zookeeper/zookeeper/bin/../lib/jackson-core-2.10.5.jar:/opt/zookeeper/zookeeper/bin/../lib/jackson-annotations-2.10.5.jar:/opt/zookeeper/zookeeper/bin/../lib/commons-cli-1.4.jar:/opt/zookeeper/zookeeper/bin/../lib/audience-annotations-0.12.0.jar:/opt/zookeeper/zookeeper/bin/../zookeeper-*.jar:/opt/zookeeper/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/zookeeper/zookeeper/conf:" 
-Xmx512m  -Dzookeeper.tcpKeepAlive=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain "/opt/zookeeper/zookeeper/conf/zoo.cfg" > "/opt/zookeeper/zookeeper/bin/../logs/zookeeper-root-server-zookeeper1.out" 2>&1 < /dev/null

Restart ZooKeeper service to apply these options.

Also, inspect bin/zkEnv.sh shell script for some useful insights.