CassandraDaemon.java:808 - Port already in use: 7199; nested exception is: java.net.BindException: Address already in use: JVM_Bind

时间: 2025-08-28 20:55:52 AIGC 浏览: 16
<think> 我们正在处理一个关于Cassandra节点启动时端口冲突的错误,具体是7199端口被占用。 根据错误信息:CassandraDaemon.java:808 - Port already in use: 7199; nested exception is: java.net.BindException: Address already in use: JVM_Bind 我们需要解决端口7199被占用的问题,以便Cassandra能够正常启动。 解决方案如下: ### 解决端口7199被占用的问题 #### 1. **找出占用7199端口的进程** ```bash # Linux/Mac sudo lsof -i :7199 # 或者使用 sudo netstat -tulnp | grep :7199 # Windows netstat -ano | findstr :7199 ``` 找到占用该端口的进程ID(PID),然后根据PID结束进程。 #### 2. **终止占用进程** ```bash # Linux/Mac sudo kill -9 <PID> # Windows taskkill /F /PID <PID> ``` #### 3. **修改Cassandra的JMX端口(可选)** 如果无法终止占用7199端口的进程(例如,该进程是另一个Cassandra实例),则可以修改当前节点的JMX端口: - 编辑`conf/cassandra-env.sh`(或`cassandra-env.ps1` for Windows) ```bash # 找到并修改JMX端口设置 JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=7200" ``` - 同时,确保在`nodetool`连接时指定新端口(或配置nodetool属性文件)。 #### 4. **检查Cassandra配置** 确保没有多个Cassandra实例配置了相同的JMX端口。在集群中,每个节点应该使用不同的JMX端口,尤其是在同一主机上运行多个节点时。 #### 5. **重启Cassandra** 修改配置后,重启Cassandra服务: ```bash # 如果以前台方式运行 ./bin/cassandra -f ``` #### 6. **验证端口监听** 启动后,检查新配置的端口是否被监听: ```bash # Linux/Mac netstat -tuln | grep <新端口号> # Windows netstat -ano | findstr <新端口号> ``` #### 7. **常见问题** - **问题:** 修改配置后仍然提示7199端口被占用。 **解决:** 检查配置文件中是否有多处设置JMX端口的地方,确保全部修改。 - **问题:** Windows系统下,即使进程已结束,端口仍被占用(可能由于TIME_WAIT状态)。 **解决:** 等待几分钟再启动,或重启系统。 ### 预防措施 - 在运行多个Cassandra节点于同一台机器时,为每个节点分配不同的JMX端口(以及存储端口、CQL端口等)。 - 使用配置管理工具(如Ansible)统一管理端口配置,避免冲突。 §§相关问题§§ 1. 在Cassandra中,除了JMX端口(7199),还有哪些关键端口需要特别注意以避免冲突? 2. 如何永久修改Cassandra节点的多个端口(如CQL端口、存储端口等)? 3. 当遇到端口冲突时,除了终止进程和修改端口,还有哪些解决方法? 4. 在Linux系统中,如何防止某个端口被意外占用(例如设置防火墙规则)? 5. 如何配置Cassandra集群以确保每个节点在启动时自动使用不同的端口范围? </think> ### 解决 Cassandra 端口 7199 被占用的问题 当启动 Cassandra 时出现 `Port already in use: 7199` 错误,表示 JMX 端口被其他进程占用。以下是完整的解决方案: --- #### **1. 查找占用端口的进程** ```bash # Windows netstat -ano | findstr :7199 # 输出示例:TCP 0.0.0.0:7199 0.0.0.0:0 LISTENING 12345 # Linux/Mac sudo lsof -i :7199 # 输出示例:java 12345 user 46u IPv6 0xffff 0t0 TCP *:7199 (LISTEN) ``` #### **2. 终止占用进程** ```bash # Windows(根据上一步的PID) taskkill /F /PID 12345 # Linux/Mac sudo kill -9 12345 ``` #### **3. 修改 JMX 端口(推荐永久方案)** 编辑 Cassandra 配置文件: ```bash # 文件位置:conf/cassandra-env.sh(Linux/Mac)或 conf\cassandra-env.ps1(Windows) # 找到并修改这行: JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=7200" # 改为新端口 ``` #### **4. 临时解决方案(无需重启)** ```bash # 启动时动态指定端口(适用于测试) bin/cassandra -f -Dcassandra.jmx.local.port=7200 ``` --- #### **端口冲突深度处理表** | **场景** | **解决方案** | |---------|-------------| | 僵尸进程占用端口 | 1. 重启操作系统<br>2. 执行 `net stop winrm`(Windows特有) | | 其他 Cassandra 实例占用 | 修改所有节点的端口配置:<br>`sed -i 's/7199/72xx/g' conf/cassandra-env.sh` | | 端口被系统服务占用 | 在 `cassandra.yaml` 中添加:<br>`jmx_port: 7200` | | Windows 端口清理失败 | 使用 `TCPView` 工具强制释放端口 | --- #### **5. 验证修复** 成功启动后检查日志: ```log INFO [main] 2023-08-01 12:00:00,000 CassandraDaemon.java:789 - Starting listening for CQL clients on 127.0.0.1:9042 INFO [main] 2023-08-01 12:00:01,000 JMXServerUtils.java:142 - Configured JMX server at: service:jmx:rmi://127.0.0.1:7200/jndi/rmi://127.0.0.1:7200/jmxrmi ``` --- #### **预防措施** 1. **端口规划原则**: - 单机多节点:为每个节点分配独立端口段(如 7200-7299) - 集群部署:使用标准偏移量(`7199 + 节点编号`) 2. **启动前检查脚本**: ```bash # Windows 检查脚本 if (netstat -ano | findstr :7199) { exit 1 } else { bin\cassandra.bat } ```
阅读全文

相关推荐

2025-08-26 17:34:36.210 ERROR 27004 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.context.ApplicationContextException: Failed to start bean 'shadedNettyGrpcServerLifecycle'; nested exception is java.lang.IllegalStateException: Failed to start the grpc server at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:357) ~[spring-context-5.3.31.jar:5.3.31] at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_362-362] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:156) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:124) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:946) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:594) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289) [spring-boot-2.7.18.jar:2.7.18] at com.tplink.nbu.demo.basicspringboot.BasicSpringBootApplication.main(BasicSpringBootApplication.java:13) [classes/:na] Caused by: java.lang.IllegalStateException: Failed to start the grpc server at net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle.start(GrpcServerLifecycle.java:74) ~[grpc-server-spring-boot-autoconfigure-2.14.0.RELEASE.jar:2.14.0.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:179) ~[spring-context-5.3.31.jar:5.3.31] ... 14 common frames omitted Caused by: java.io.IOException: Failed to bind to address /127.0.0.0:8091 at io.grpc.netty.shaded.io.grpc.netty.NettyServer.start(NettyServer.java:328) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.internal.ServerImpl.start(ServerImpl.java:184) ~[grpc-core-1.51.0.jar:1.51.0] at io.grpc.internal.ServerImpl.start(ServerImpl.java:93) ~[grpc-core-1.51.0.jar:1.51.0] at net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle.createAndStartGrpcServer(GrpcServerLifecycle.java:113) ~[grpc-server-spring-boot-autoconfigure-2.14.0.RELEASE.jar:2.14.0.RELEASE] at net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle.start(GrpcServerLifecycle.java:72) ~[grpc-server-spring-boot-autoconfigure-2.14.0.RELEASE.jar:2.14.0.RELEASE] ... 15 common frames omitted Caused by: java.net.BindException: Cannot assign requested address: bind at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_362-362] at sun.nio.ch.Net.bind(Net.java:461) ~[na:1.8.0_362-362] at sun.nio.ch.Net.bind(Net.java:453) ~[na:1.8.0_362-362] at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:222) ~[na:1.8.0_362-362] at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:141) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:600) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:579) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.AbstractChannel.bind(AbstractChannel.java:260) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[grpc-netty-shaded-1.56.1.jar:1.56.1] at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_362-362]