You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/12/22 20:23:00 UTC

[jira] [Commented] (KAFKA-1566) Kafka environment configuration (kafka-env.sh)

    [ https://issues.apache.org/jira/browse/KAFKA-1566?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16301908#comment-16301908 ] 

ASF GitHub Bot commented on KAFKA-1566:
---------------------------------------

guozhangwang closed pull request #156: KAFKA-1566: Kafka environment configuration (kafka-env.sh)
URL: https://github.com/apache/kafka/pull/156
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bin/kafka-run-class.sh b/bin/kafka-run-class.sh
index 76d0b886262..682e5a127c6 100755
--- a/bin/kafka-run-class.sh
+++ b/bin/kafka-run-class.sh
@@ -40,6 +40,12 @@ should_include_file() {
 
 base_dir=$(dirname $0)/..
 
+# run kafka-env.sh
+KAFKA_ENV=$base_dir/config/kafka-env.sh
+if [ -f $KAFKA_ENV ]; then
+    . $KAFKA_ENV
+fi
+
 if [ -z "$SCALA_VERSION" ]; then
 	SCALA_VERSION=2.10.6
 fi
diff --git a/bin/windows/kafka-run-class.bat b/bin/windows/kafka-run-class.bat
index b16717c97fe..6c47b171e7e 100644
--- a/bin/windows/kafka-run-class.bat
+++ b/bin/windows/kafka-run-class.bat
@@ -1,155 +1,174 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one or more
-rem contributor license agreements.  See the NOTICE file distributed with
-rem this work for additional information regarding copyright ownership.
-rem The ASF licenses this file to You under the Apache License, Version 2.0
-rem (the "License"); you may not use this file except in compliance with
-rem the License.  You may obtain a copy of the License at
-rem
-rem     http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-setlocal enabledelayedexpansion
-
-IF [%1] EQU [] (
-	echo USAGE: %0 classname [opts]
-	EXIT /B 1
-)
-
-rem Using pushd popd to set BASE_DIR to the absolute path
-pushd %~dp0..\..
-set BASE_DIR=%CD%
-popd
-
-IF ["%SCALA_VERSION%"] EQU [""] (
-  set SCALA_VERSION=2.10.6
-)
-
-IF ["%SCALA_BINARY_VERSION%"] EQU [""] (
-  set SCALA_BINARY_VERSION=2.10
-)
-
-rem Classpath addition for kafka-core dependencies
-for %%i in (%BASE_DIR%\core\build\dependant-libs-%SCALA_VERSION%\*.jar) do (
-	call :concat %%i
-)
-
-rem Classpath addition for kafka-perf dependencies
-for %%i in (%BASE_DIR%\perf\build\dependant-libs-%SCALA_VERSION%\*.jar) do (
-	call :concat %%i
-)
-
-rem Classpath addition for kafka-clients
-for %%i in (%BASE_DIR%\clients\build\libs\kafka-clients-*.jar) do (
-	call :concat %%i
-)
-
-rem Classpath addition for kafka-examples
-for %%i in (%BASE_DIR%\examples\build\libs\kafka-examples-*.jar) do (
-	call :concat %%i
-)
-
-rem Classpath addition for release
-call :concat %BASE_DIR%\libs\*
-
-rem Classpath addition for core
-for %%i in (%BASE_DIR%\core\build\libs\kafka_%SCALA_BINARY_VERSION%*.jar) do (
-	call :concat %%i
-)
-
-rem JMX settings
-IF ["%KAFKA_JMX_OPTS%"] EQU [""] (
-	set KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false
-)
-
-rem JMX port to use
-IF ["%JMX_PORT%"] NEQ [""] (
-	set KAFKA_JMX_OPTS=%KAFKA_JMX_OPTS% -Dcom.sun.management.jmxremote.port=%JMX_PORT%
-)
-
-rem Log directory to use
-IF ["%LOG_DIR%"] EQU [""] (
-    set LOG_DIR=%BASE_DIR%/logs
-)
-
-rem Log4j settings
-IF ["%KAFKA_LOG4J_OPTS%"] EQU [""] (
-	set KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:%BASE_DIR%/config/tools-log4j.properties
-) ELSE (
-  # create logs directory
-  IF not exist %LOG_DIR% (
-      mkdir %LOG_DIR%
-  )
-)
-
-set KAFKA_LOG4J_OPTS=-Dkafka.logs.dir=%LOG_DIR% %KAFKA_LOG4J_OPTS%
-
-rem Generic jvm settings you want to add
-IF ["%KAFKA_OPTS%"] EQU [""] (
-	set KAFKA_OPTS=
-)
-
-set DEFAULT_JAVA_DEBUG_PORT=5005
-set DEFAULT_DEBUG_SUSPEND_FLAG=n
-rem Set Debug options if enabled
-IF ["%KAFKA_DEBUG%"] NEQ [""] (
-
-
-	IF ["%JAVA_DEBUG_PORT%"] EQU [""] (
-		set JAVA_DEBUG_PORT=%DEFAULT_JAVA_DEBUG_PORT%
-	)
-
-	IF ["%DEBUG_SUSPEND_FLAG%"] EQU [""] (
-		set DEBUG_SUSPEND_FLAG=%DEFAULT_DEBUG_SUSPEND_FLAG%
-	)
-	set DEFAULT_JAVA_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=!DEBUG_SUSPEND_FLAG!,address=!JAVA_DEBUG_PORT!
-
-	IF ["%JAVA_DEBUG_OPTS%"] EQU [""] (
-		set JAVA_DEBUG_OPTS=!DEFAULT_JAVA_DEBUG_OPTS!
-	)
-
-	echo Enabling Java debug options: !JAVA_DEBUG_OPTS!
-	set KAFKA_OPTS=!JAVA_DEBUG_OPTS! !KAFKA_OPTS!
-)
-
-rem Which java to use
-IF ["%JAVA_HOME%"] EQU [""] (
-	set JAVA=java
-) ELSE (
-	set JAVA="%JAVA_HOME%/bin/java"
-)
-
-rem Memory options
-IF ["%KAFKA_HEAP_OPTS%"] EQU [""] (
-	set KAFKA_HEAP_OPTS=-Xmx256M
-)
-
-rem JVM performance options
-IF ["%KAFKA_JVM_PERFORMANCE_OPTS%"] EQU [""] (
-	set KAFKA_JVM_PERFORMANCE_OPTS=-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.awt.headless=true
-)
-
-IF ["%CLASSPATH%"] EQU [""] (
-	echo Classpath is empty. Please build the project first e.g. by running 'gradlew jarAll'
-	EXIT /B 2
-)
-
-set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp %CLASSPATH% %KAFKA_OPTS% %*
-rem echo.
-rem echo %COMMAND%
-rem echo.
-
-%COMMAND%
-
-goto :eof
-:concat
-IF ["%CLASSPATH%"] EQU [""] (
-  set CLASSPATH="%1"
-) ELSE (
-  set CLASSPATH=%CLASSPATH%;"%1"
-)
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+setlocal enabledelayedexpansion
+
+IF [%1] EQU [] (
+	echo USAGE: %0 classname [opts]
+	EXIT /B 1
+)
+
+rem Using pushd popd to set BASE_DIR to the absolute path
+pushd %~dp0..\..
+set BASE_DIR=%CD%
+popd
+
+
+
+IF exist %BASE_DIR%\config\kafka-env.cmd (
+  call %BASE_DIR%\config\kafka-env.cmd
+)
+
+IF not exist "%JAVA_HOME%\bin\java.exe" (
+  echo Error: JAVA_HOME is incorrectly set.
+  goto :eof
+)
+
+
+IF ["%LOG_DIR%"] EQU [""] (
+  set LOG_DIR=%BASE_DIR%\logs
+)
+
+IF ["%SCALA_VERSION%"] EQU [""] (
+  set SCALA_VERSION=2.10.5
+)
+
+IF ["%SCALA_BINARY_VERSION%"] EQU [""] (
+  set SCALA_BINARY_VERSION=2.10
+)
+
+rem Classpath addition for kafka-core dependencies
+for %%i in (%BASE_DIR%\core\build\dependant-libs-%SCALA_VERSION%\*.jar) do (
+	call :concat %%i
+)
+
+rem Classpath addition for kafka-perf dependencies
+for %%i in (%BASE_DIR%\perf\build\dependant-libs-%SCALA_VERSION%\*.jar) do (
+	call :concat %%i
+)
+
+rem Classpath addition for kafka-clients
+for %%i in (%BASE_DIR%\clients\build\libs\kafka-clients-*.jar) do (
+	call :concat %%i
+)
+
+rem Classpath addition for kafka-examples
+for %%i in (%BASE_DIR%\examples\build\libs\kafka-examples-*.jar) do (
+	call :concat %%i
+)
+
+
+rem Classpath addition for release
+for %%i in (%BASE_DIR%\libs\*.jar) do (
+	call :concat %%i
+)
+
+rem Classpath addition for core
+for %%i in (%BASE_DIR%\core\build\libs\kafka_%SCALA_BINARY_VERSION%*.jar) do (
+	call :concat %%i
+)
+
+rem JMX settings
+IF ["%KAFKA_JMX_OPTS%"] EQU [""] (
+	set KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false
+)
+
+rem JMX port to use
+IF ["%JMX_PORT%"] NEQ [""] (
+	set KAFKA_JMX_OPTS=%KAFKA_JMX_OPTS% -Dcom.sun.management.jmxremote.port=%JMX_PORT%
+)
+
+rem Log directory to use
+IF ["%LOG_DIR%"] EQU [""] (
+    set LOG_DIR=%BASE_DIR%/logs
+)
+
+rem Log4j settings
+IF ["%KAFKA_LOG4J_OPTS%"] EQU [""] (
+	set KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:%BASE_DIR%/config/tools-log4j.properties
+) ELSE (
+  # create logs directory
+  IF not exist %LOG_DIR% (
+      mkdir %LOG_DIR%
+  )
+)
+
+set KAFKA_LOG4J_OPTS=-Dkafka.logs.dir=%LOG_DIR% %KAFKA_LOG4J_OPTS%
+
+rem Generic jvm settings you want to add
+IF ["%KAFKA_OPTS%"] EQU [""] (
+	set KAFKA_OPTS=
+)
+
+set DEFAULT_JAVA_DEBUG_PORT=5005
+set DEFAULT_DEBUG_SUSPEND_FLAG=n
+rem Set Debug options if enabled
+IF ["%KAFKA_DEBUG%"] NEQ [""] (
+
+
+	IF ["%JAVA_DEBUG_PORT%"] EQU [""] (
+		set JAVA_DEBUG_PORT=%DEFAULT_JAVA_DEBUG_PORT%
+	)
+
+	IF ["%DEBUG_SUSPEND_FLAG%"] EQU [""] (
+		set DEBUG_SUSPEND_FLAG=%DEFAULT_DEBUG_SUSPEND_FLAG%
+	)
+	set DEFAULT_JAVA_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=!DEBUG_SUSPEND_FLAG!,address=!JAVA_DEBUG_PORT!
+
+	IF ["%JAVA_DEBUG_OPTS%"] EQU [""] (
+		set JAVA_DEBUG_OPTS=!DEFAULT_JAVA_DEBUG_OPTS!
+	)
+
+	echo Enabling Java debug options: !JAVA_DEBUG_OPTS!
+	set KAFKA_OPTS=!JAVA_DEBUG_OPTS! !KAFKA_OPTS!
+)
+
+rem Which java to use
+IF ["%JAVA_HOME%"] EQU [""] (
+	set JAVA=java
+) ELSE (
+	set JAVA="%JAVA_HOME%/bin/java"
+)
+
+rem Memory options
+IF ["%KAFKA_HEAP_OPTS%"] EQU [""] (
+	set KAFKA_HEAP_OPTS=-Xmx256M
+)
+
+rem JVM performance options
+IF ["%KAFKA_JVM_PERFORMANCE_OPTS%"] EQU [""] (
+	set KAFKA_JVM_PERFORMANCE_OPTS=-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+DisableExplicitGC -Djava.awt.headless=true
+)
+
+IF ["%CLASSPATH%"] EQU [""] (
+	echo Classpath is empty. Please build the project first e.g. by running 'gradlew jarAll'
+	EXIT /B 2
+)
+
+set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp %CLASSPATH% %KAFKA_OPTS% %*
+rem echo.
+rem echo %COMMAND%
+rem echo.
+
+%COMMAND%
+
+goto :eof
+:concat
+IF ["%CLASSPATH%"] EQU [""] (
+  set CLASSPATH="%1"
+) ELSE (
+  set CLASSPATH=%CLASSPATH%;"%1"
+)
diff --git a/config/kafka-env.cmd b/config/kafka-env.cmd
new file mode 100644
index 00000000000..d419d239175
--- /dev/null
+++ b/config/kafka-env.cmd
@@ -0,0 +1,22 @@
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+rem The kafka env config command script
+rem It allows users to override JAVA_HOME, LOG_DIR etc..
+
+rem Set Kafka specific environment variables here.
+
+rem  The java implementation to use.
diff --git a/config/kafka-env.sh b/config/kafka-env.sh
new file mode 100644
index 00000000000..0aadf46d7d0
--- /dev/null
+++ b/config/kafka-env.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright 2014 The Apache Software Foundation
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set Kafka specific environment variables here.
+
+#export JAVA_HOME=/usr/jdk1.7/
+#export LOG_DIR="/tmp/logs/
+#export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false"
+#export JMX_PORT="9999"
+#export KAFKA_HEAP_OPTS="-Xmx300M"
+#export KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true"
+#export KAFKA_GC_LOG_OPTS="-Xloggc:$LOG_DIR/kafka-gc.txt -XX:+PrintGCDetails"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Kafka environment configuration (kafka-env.sh)
> ----------------------------------------------
>
>                 Key: KAFKA-1566
>                 URL: https://issues.apache.org/jira/browse/KAFKA-1566
>             Project: Kafka
>          Issue Type: Improvement
>          Components: tools
>            Reporter: Cosmin Lehene
>            Assignee: Sriharsha Chintalapani
>              Labels: newbie
>         Attachments: KAFKA-1566.patch, KAFKA-1566_2015-02-21_21:57:02.patch, KAFKA-1566_2015-03-17_17:01:38.patch, KAFKA-1566_2015-03-17_17:19:23.patch
>
>
> It would be useful (especially for automated deployments) to have an environment configuration file that could be sourced from the launcher files (e.g. kafka-run-server.sh). 
> This is how this could look like kafka-env.sh 
> {code}
> export KAFKA_JVM_PERFORMANCE_OPTS="-XX:+UseCompressedOops -XX:+DisableExplicitGC -Djava.awt.headless=true \ -XX:+UseG1GC -XX:PermSize=48m -XX:MaxPermSize=48m -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35' %>" 
> export KAFKA_HEAP_OPTS="'-Xmx1G -Xms1G' %>" 
> export KAFKA_LOG4J_OPTS="-Dkafka.logs.dir=/var/log/kafka" 
> {code} 
> kafka-server-start.sh 
> {code} 
> ... 
> source $base_dir/config/kafka-env.sh 
> ... 
> {code} 
> This approach is consistent with Hadoop and HBase. However the idea here is to be able to set these values in a single place without having to edit startup scripts.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)