From ad485e148d7ac104abe173687ba27dccff8e4d39 Mon Sep 17 00:00:00 2001 From: Joe Stein Date: Tue, 7 Jul 2015 10:09:11 -0700 Subject: [PATCH] KAFKA-2304 Supported enabling JMX in Kafka Vagrantfile patch by Stevo Slavic reviewed by Ewen Cheslack-Postava --- Vagrantfile | 7 +++++-- vagrant/broker.sh | 5 +++++ vagrant/zk.sh | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 55c67ddda45..1d7cc01b106 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -22,6 +22,7 @@ VAGRANTFILE_API_VERSION = "2" # General config enable_dns = false +enable_jmx = false num_zookeepers = 1 num_brokers = 3 num_workers = 0 # Generic workers that get the code, but don't start any services @@ -135,7 +136,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ip_address = "192.168.50." + (10 + i).to_s assign_local_ip(zookeeper, ip_address) zookeeper.vm.provision "shell", path: "vagrant/base.sh" - zookeeper.vm.provision "shell", path: "vagrant/zk.sh", :args => [i.to_s, num_zookeepers] + zk_jmx_port = enable_jmx ? (8000 + i).to_s : "" + zookeeper.vm.provision "shell", path: "vagrant/zk.sh", :args => [i.to_s, num_zookeepers, zk_jmx_port] end } @@ -151,7 +153,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # used to support clients running on the host. zookeeper_connect = zookeepers.map{ |zk_addr| zk_addr + ":2181"}.join(",") broker.vm.provision "shell", path: "vagrant/base.sh" - broker.vm.provision "shell", path: "vagrant/broker.sh", :args => [i.to_s, enable_dns ? name : ip_address, zookeeper_connect] + kafka_jmx_port = enable_jmx ? (9000 + i).to_s : "" + broker.vm.provision "shell", path: "vagrant/broker.sh", :args => [i.to_s, enable_dns ? name : ip_address, zookeeper_connect, kafka_jmx_port] end } diff --git a/vagrant/broker.sh b/vagrant/broker.sh index 63f2d4f30c5..bc040c92e33 100644 --- a/vagrant/broker.sh +++ b/vagrant/broker.sh @@ -22,6 +22,7 @@ set -e BROKER_ID=$1 PUBLIC_ADDRESS=$2 PUBLIC_ZOOKEEPER_ADDRESSES=$3 +JMX_PORT=$4 cd /opt/kafka @@ -35,4 +36,8 @@ echo "Killing server" bin/kafka-server-stop.sh || true sleep 5 # Because kafka-server-stop.sh doesn't actually wait echo "Starting server" +if [[ -n $JMX_PORT ]]; then + export JMX_PORT=$JMX_PORT + export KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=$PUBLIC_ADDRESS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " +fi bin/kafka-server-start.sh /opt/kafka/config/server-$BROKER_ID.properties 1>> /tmp/broker.log 2>> /tmp/broker.log & diff --git a/vagrant/zk.sh b/vagrant/zk.sh index 15517f82646..6fc4b7cfe8f 100644 --- a/vagrant/zk.sh +++ b/vagrant/zk.sh @@ -21,6 +21,7 @@ set -e ZKID=$1 NUM_ZK=$2 +JMX_PORT=$3 cd /opt/kafka @@ -37,6 +38,10 @@ echo "$ZKID" > /tmp/zookeeper/myid echo "Killing ZooKeeper" bin/zookeeper-server-stop.sh || true -sleep 5 # Because kafka-server-stop.sh doesn't actually wait +sleep 5 # Because zookeeper-server-stop.sh doesn't actually wait echo "Starting ZooKeeper" +if [[ -n $JMX_PORT ]]; then + export JMX_PORT=$JMX_PORT + export KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=zk$ZKID -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " +fi bin/zookeeper-server-start.sh config/zookeeper-$ZKID.properties 1>> /tmp/zk.log 2>> /tmp/zk.log &