Redis Creating Server TCP listening socket *:6379: unable to bind socket

本文介绍了在启动Redis服务时遇到的“CreatingServerTCPlisteningsocket*:6379:unabletobindsocket”错误及其解决方案。指出该问题通常是因为未正确指定配置文件路径导致,并提供了具体的步骤来解决这一问题。

解决Redis Creating Server TCP listening socket *:6379: unable to bind socket

如题,执行redis-server命令启动redis的时候,会报这个错误。google之后也没有明确的解决方法。最终发现是因为启动时没有指定配置文件。
redis安装目录下会有一个redis.conf文件,这个就是默认的配置文件。一般我们的配置文件都是放在/etc/目录下:

$ sudo mkdir /etc/redis/
$ sudo cp redis.conf /etc/redis/

启动时指定配置文件:

$ sudo src/redis-server /etc/redis/redis.conf

警告:如果当前不是root用户,则要使用root权限启动,否则启动后不能正常关闭redis服务(关闭时redis-server会写数据到文件,此时会出现没有权限的提示错误,导致不能正常关闭服务);

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379 at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:966) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:934) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:786) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:300) at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132) at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95) at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:211) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95) at org.springframework.data.redis.core.DefaultSetOperations.members(DefaultSetOperations.java:158) at org.springframework.data.redis.core.DefaultBoundSetOperations.members(DefaultBoundSetOperations.java:152) at org.springframework.session.data.redis.RedisSessionExpirationPolicy.cleanExpiredSessions(RedisSessionExpirationPolicy.java:132) at org.springframework.session.data.redis.RedisOperationsSessionRepository.cleanupExpiredSessions(RedisOperationsSessionRepository.java:430) at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.lambda$configureTasks$0(RedisHttpSessionConfiguration.java:248) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750) Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379 at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:233) at io.lettuce.core.RedisClient.connectStandalone(RedisClient.java:253) at io.lettuce.core.RedisClient.connect(RedisClient.java:202) at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:56) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:959) ... 24 common frames omitted Caused by: io.netty.channel.AbstractChannel$AnnotatedSocketException: Permission denied: no further information: /127.0.0.1:6379 at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:715) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:665) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ... 1 common frames omitted Caused by: java.net.SocketException: Permission denied: no further information ... 11 common frames omitted 2025-07-22 15:04:02.693 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-3] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:02.693 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-3] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:07.708 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-4] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:07.708 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-4] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:12.724 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-5] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:12.724 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-5] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:17.732 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-6] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:17.732 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-6] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:22.749 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-7] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:22.749 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-7] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:27.756 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-8] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:27.756 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-8] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:32.762 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-9] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:32.762 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-9] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:37.791 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-10] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:37.791 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-10] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:42.802 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-11] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:42.802 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-11] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:47.811 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-12] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:47.811 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-12] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:52.821 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-13] Connection failure occurred. Restarting subscription task after 5000 ms 2025-07-22 15:04:52.821 E [org.springframework.data.redis.listener.RedisMessageListenerContainer] [redisMessageListenerContainer-13] Connection failure occurred. Restarting subscription task after 5000 ms
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值