相关文章推荐
从未表白的眼镜  ·  Optimum + ONNX ...·  1 年前    · 
温柔的柳树  ·  解决StackExchange.Redis ...·  1 年前    · 
着急的台灯  ·  python - Inserting ...·  1 年前    · 
kafka 创建 topic 报错
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 9988; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
I have no name!@kafka-0:/$ kafka-topics.sh --create --topic test --zookeeper zookeeper-0.zk-headless.infra.svc.cluster.local:2181,zookeeper-1.zk-headless.infra.svc.cluster.local:2181,zookeeper-2.zk-headless.infra.svc.cluster.local:2181 --partitions 3 --replication-factor 2
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 9988; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
sun.management.AgentConfigurationError: java.rmi.server.ExportException: Port already in use: 9988; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
	at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:480)
	at sun.management.Agent.startAgent(Agent.java:262)
	at sun.management.Agent.startAgent(Agent.java:452)
Caused by: java.rmi.server.ExportException: Port already in use: 9988; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
	at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:346)
	at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:254)
	at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411)
	at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147)
	at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:237)
	at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:213)
	at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:173)
	at sun.management.jmxremote.SingleEntryRegistry.<init>(SingleEntryRegistry.java:49)
	at sun.management.jmxremote.ConnectorBootstrap.exportMBeanServer(ConnectorBootstrap.java:816)
	at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:468)
	... 2 more
Caused by: java.net.BindException: Address already in use (Bind failed)
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
	at java.net.ServerSocket.bind(ServerSocket.java:375)
	at java.net.ServerSocket.<init>(ServerSocket.java:237)
	at java.net.ServerSocket.<init>(ServerSocket.java:128)
	at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMIDirectSocketFactory.java:45)
	at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMIMasterSocketFactory.java:345)
	at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:666)
	at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:335)
	... 11 more

参考 https://github.com/apache/kafka/pull/1983/commits/2c5d40e946bcc149b1a9b2c01eced4ae47a734c5

[root@es-master21 mnt]# vim /mnt/kafka/kafka-run-class.sh
 ......
 40   file=$1
 41   if [ -z "$(echo "$file" | egrep "$regex")" ] ; then
 42     return 0
 43   else
 44     return 1
 45   fi
 ------加入以下4行配置------
ISKAFKASERVER="false"
if [[ "$*" =~ "kafka.Kafka" ]]; then
    ISKAFKASERVER="true"
 ------------以上-----------
 51 base_dir=$(dirname $0)/..
 192 # JMX port to use
#if [  $JMX_PORT ]; then       #注释掉这一行
if [  $JMX_PORT ] && [ -z "$ISKAFKASERVER" ]; then     #添加这一行新的配置进去
 195   KAFKA_JMX_OPTS="$KAFKA_JMX_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT "
 196 fi
 198 # Log directory to use
 199 if [ "x$LOG_DIR" = "x" ]; then
 200   LOG_DIR="$base_dir/logs"
 201 fi
 ......

重新制作镜像

docker run --name kafka001 -d -it docker.io/bitnami/kafka:2.3.0-debian-9-r4 bash
docker cp kafka001:/opt/bitnami/kafka/bin/kafka-run-class.sh kafka-run-class.sh
docker rm -f kafka001
vim kafka-run-class.sh
cat <<"EOF"> Dockerfile
FROM docker.io/bitnami/kafka:2.3.0-debian-9-r4
ADD kafka-run-class.sh /opt/bitnami/kafka/bin/kafka-run-class.sh
chmod +x kafka-run-class.sh
imageName="harbor.test.com/tools/kafka:2.3.0-debian-9-r4-run-2"
docker build -t ${imageName} .
docker push ${imageName}
# 将 kafka 的镜像修改为 harbor.test.com/tools/kafka:2.3.0-debian-9-r4-run-2