{"id":201635,"date":"2025-05-10T10:45:33","date_gmt":"2025-05-10T02:45:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201635\/"},"modified":"2025-05-10T10:45:33","modified_gmt":"2025-05-10T02:45:33","slug":"redis%e4%b8%adcouldnotgetaresourcefromthepool%e5%bc%82%e5%b8%b8%e5%8f%8a%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201635\/","title":{"rendered":"redis\u4e2dCouldnotgetaresourcefromthepool\u5f02\u5e38\u53ca\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>redis\u4e2dCouldnotgetaresourcefromthepool\u5f02\u5e38\u53ca\u89e3\u51b3\u65b9\u6848<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #FF6600;font-family:\">\u6570\u636e\u5e93<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;font-family:\">\u300aredis\u4e2dCouldnotgetaresourcefromthepool\u5f02\u5e38\u53ca\u89e3\u51b3\u65b9\u6848\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;font-family:\">pool\u3001redisCould\u3001resource<\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<h2>\u63cf\u8ff0<\/h2>\n<p>\u8fd9\u4e2a\u9519\u8bef\u4ea7\u751f\u7684\u524d\u63d0\u662f\u8fd9\u6837\u7684\uff0c\u5c06\u6570\u636e\u5b58\u5165redis\uff08\u65b0\u5b89\u88c5\u7684\uff09\u4e2d\uff0c\u5728\u901a\u8fc7\u8fde\u63a5\u6c60\u83b7\u53d6jedis\u5b9e\u4f8b\u65f6\uff0c\u4ea7\u751f\u5982\u4e0b\u9519\u8bef\uff08 Could not get a resource from the pool\uff09\u3002<\/p>\n<h2>\u5206\u6790<\/h2>\n<p>\u7531\u4e8e\u662f\u65b0\u5b89\u88c5\u7684redis\uff0c\u914d\u7f6e\u6587\u4ef6\u6ca1\u6709\u66f4\u6539\uff0c\u4f4e\u7ea7\u7684\u9519\u8bef\u6d6a\u8d39\u4e0d\u5c11\u65f6\u95f4\uff0c\u5199\u4e00\u7bc7\u6587\u7ae0\uff0c\u8ba9\u540c\u6837\u72af\u8fd9\u79cd\u9519\u8bef\u7684\u670b\u53cb\u522b\u518d\u6d6a\u8d39\u65f6\u95f4\u3002<\/p>\n<h2>\u89e3\u51b3<\/h2>\n<p>\u66f4\u6539\u914d\u7f6e\u6587\u4ef6 redis.conf \u4e2d\u4e24\u5904<\/p>\n<p>1.\u5c06 bind 127.0.0.1 \u6ce8\u91ca\u6389<\/p>\n<p>2.\u5c06 protected-mode \u6539\u4e3a no<\/p>\n<table>\n<thead>\n<tr>\n<th>bind 127.0.0.1<\/th>\n<th>protected-mode<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u9ed8\u8ba4\u60c5\u51b5bind=127.0.0.1\u53ea\u80fd\u63a5\u53d7\u672c\u673a\u7684\u8bbf\u95ee\u8bf7\u6c42\u4e0d\u5199\u7684\u60c5\u51b5\u4e0b\uff0c\u65e0\u9650\u5236\u63a5\u53d7\u4efb\u4f55ip\u5730\u5740\u7684\u8bbf\u95ee<\/td>\n<td>\u5982\u679c\u5f00\u542f\u4e86protected-mode\uff0c\u90a3\u4e48\u5728\u6ca1\u6709\u8bbe\u5b9abind ip\u4e14\u6ca1\u6709\u8bbe\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\uff0cRedis\u53ea\u5141\u8bb8\u63a5\u53d7\u672c\u673a\u7684\u76f8\u5e94<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167729243263f97390d8008.jpg\" class=\"aligncenter\"><\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167729243363f973916ca15.jpg\" class=\"aligncenter\"><\/p>\n<h2>\u8fd0\u884c\u4ee3\u7801<\/h2>\n<pre>\/\/\u521b\u5efajedis\u914d\u7f6e\u6587\u4ef6\u5bf9\u8c61\nval jedisPoolConfig = new JedisPoolConfig()\n\/\/\u6dfb\u52a0\u914d\u7f6e\u4fe1\u606f\njedisPoolConfig.setMaxTotal(100)\njedisPoolConfig.setMaxIdle(20)\njedisPoolConfig.setMinIdle(0)\njedisPoolConfig.setBlockWhenExhausted(true)\njedisPoolConfig.setMaxWaitMillis(500)\njedisPoolConfig.setTestOnBorrow(true)\n\/\/\u521b\u5efa\u8fde\u63a5\u6c60\u5bf9\u8c61\nvar jedisPool\uff1aJedisPool = new JedisPool(jedisPoolConfig,\"linux1\",6379)\n\/\/\u83b7\u53d6\u5b9e\u4f8b\njedisPool.getResource<\/pre>\n<h2>\u62a5\u9519\u5185\u5bb9<\/h2>\n<blockquote>\n<p>ERROR &#8212; [ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Executor task launch worker for task 15] &nbsp;org.apache.spark.executor.Executor &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(line: &nbsp; 91) &nbsp;: &nbsp;Exception in task 7.0 in stage 2.0 (TID 15)<br \/>redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.util.Pool.getResource(Pool.java:53)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)<br \/>&nbsp;&nbsp; &nbsp;at com.atguigu.bigdata.sparkmall.common.RedisUtil$.getJedisClient(RedisUtil.scala:26)<br \/>&nbsp;&nbsp; &nbsp;at com.atguigu.bigdata.sparkmall.realtime.Req7TimeAdvertClickTrendApplication$$anonfun$main$1$$anonfun$apply$2.apply(Req7TimeAdvertClickTrendApplication.scala:54)<br \/>&nbsp;&nbsp; &nbsp;at com.atguigu.bigdata.sparkmall.realtime.Req7TimeAdvertClickTrendApplication$$anonfun$main$1$$anonfun$apply$2.apply(Req7TimeAdvertClickTrendApplication.scala:53)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$29.apply(RDD.scala:926)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1951)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1951)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.scheduler.Task.run(Task.scala:99)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:322)<br \/>&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)<br \/>&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)<br \/>&nbsp;&nbsp; &nbsp;at java.lang.Thread.run(Thread.java:748)<br \/>Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.Connection.connect(Connection.java:207)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)<br \/>&nbsp;&nbsp; &nbsp;at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.util.Pool.getResource(Pool.java:49)<br \/>&nbsp;&nbsp; &nbsp;&#8230; 14 more<br \/>Caused by: java.net.ConnectException: Connection refused: connect<br \/>&nbsp;&nbsp; &nbsp;at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)<br \/>&nbsp;&nbsp; &nbsp;at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)<br \/>&nbsp;&nbsp; &nbsp;at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)<br \/>&nbsp;&nbsp; &nbsp;at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)<br \/>&nbsp;&nbsp; &nbsp;at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)<br \/>&nbsp;&nbsp; &nbsp;at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)<br \/>&nbsp;&nbsp; &nbsp;at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)<br \/>&nbsp;&nbsp; &nbsp;at java.net.Socket.connect(Socket.java:589)<br \/>&nbsp;&nbsp; &nbsp;at redis.clients.jedis.Connection.connect(Connection.java:184)<br \/>&nbsp;&nbsp; &nbsp;&#8230; 21 more<\/p>\n<\/blockquote>\n<h2>\u5176\u4ed6\u539f\u56e0<\/h2>\n<p>1.\u6700\u5927\u94fe\u63a5\u6570\u91cf\u8d85\u6807\uff0c\u8d44\u6e90\u672a\u56de\u6536jedis.close();\/\/\u91ca\u653e\u8d44\u6e90<\/p>\n<p>2.<strong>\u538b\u6839redis\u670d\u52a1\u6ca1\u6709\u8d77 \uff08\u5f88\u591a\u4eba\u662f\u8fd9\u79cd\uff09<\/strong><\/p>\n<p>3.\u53ef\u80fd\u662flinux\u9632\u706b\u5899\u95ee\u9898\u9020\u6210\u7684 \u68c0\u67e5\u7f51\u7edc\u662f\u5426\u7545\u901a<\/p>\n<p>4.\u68c0\u67e5IP\u5730\u5740\u6216\u7aef\u53e3\u662f\u5426\u9519\u8bef<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u4ee5\u4e0a\u4e3a\u4e2a\u4eba\u7ecf\u9a8c\uff0c\u5e0c\u671b\u80fd\u7ed9\u5927\u5bb6\u4e00\u4e2a\u53c2\u8003\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u591a\u591a\u652f\u6301golang\u5b66\u4e60\u7f51\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>redis\u4e2dCouldnotge&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201635","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201635"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201635\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}