{"id":2538,"date":"2021-05-05T19:05:18","date_gmt":"2021-05-05T11:05:18","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=2538"},"modified":"2021-05-05T19:09:41","modified_gmt":"2021-05-05T11:09:41","slug":"apache-tomcat-mod_jk-conn-failure","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/apache-tomcat-mod_jk-conn-failure\/","title":{"rendered":"Apache Tomcat: mod_jk \u8fde\u63a5\u8d85\u65f6cping\/cpong timeout"},"content":{"rendered":"<p>\u57fa\u4e8e\u65b0\u7248\u7684Apache-2.4.46+\u548cTomcat-9.0.45+\u914d\u7f6e\u4e00\u4f8b\u65b0\u7684Web\u5e94\u7528\u65f6\uff0c\u4f7f\u7528Mod_jk\u8fdb\u884c\u8fde\u63a5\u65f6\uff0c\u4f7f\u7528\u4e0e\u4e4b\u524d\u7248\u672c\u76f8\u540c\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5404\u81ea\u8fd0\u884c\u8d77\u6765\u540e\uff0cApache\u7684JSP\u6587\u4ef6\u8bf7\u6c42\u89e6\u53d1\u5230Mod_jk\u5e76\u8fdb\u4e00\u6b65\u5730\u524d\u4f20\u7ed9Tomcat\u5904\u7406\u65f6\uff0c\u5f00\u59cb\u62a5\u9519\uff0c\u62a5\u9519\u4fe1\u606f\u662fconnection failed to backend service\u4e4b\u7c7b\u3002<\/p>\n<p>\u5927\u81f4\u662fApache\u65e0\u6cd5\u901a\u8fc7mod_jk\u8fde\u63a5\u5230Tomcat\u7684\u670d\u52a1\u3002\u800c\u5355\u72ec\u6d4b\u8bd5Apache\u7684\u8fd0\u884c\u548cTomcat\u7684\u8fd0\u884c\uff0c\u6bd4\u5982\u5355\u72ec\u8bf7\u6c42\u975eJSP\u6587\u4ef6\uff0c\u6216\u8005\u5728Tomcat\u76848080\u7aef\u53e3\u8bf7\u6c42\u76f8\u5e94\u7684JSP\u6587\u4ef6\uff0c\u5747\u80fd\u591f\u6b63\u5e38\u5904\u7406\u76f8\u5e94\u7684\u8bf7\u6c42\u3002\u57fa\u4e8e\u6b64\uff0c\u6211\u4eec\u5224\u65ad\u95ee\u9898\u5c31\u51fa\u5728mod_jk\u4e0a\uff0c\u5230\u5e95\u54ea\u91cc\u51fa\u9519\u4e86\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u5728\u00a0apache\/conf\/extra\/httpd-jk.conf \u4e2d\u6253\u5f00\u76f8\u5e94\u7684\u8be6\u7ec6\u65e5\u5fd7\u8bb0\u5f55\u3002<\/p>\n<p># Our JK log level (trace,debug,info,warn,error)<br \/> JkLogLevel trace<\/p>\n<p>\u8f93\u51fa\u6240\u6709\u6b65\u9aa4\u7684\u8fc7\u7a0b\u8bb0\u5f55\u3002\u65e5\u5fd7\u8bb0\u5f55\u5f88\u5feb\u53cd\u9988\u56de\u6765\uff0c\u662f\u65e0\u6cd5\u8fde\u63a5\u5230 ::1:8009 \u8fd9\u4e2a\u670d\u52a1\u3002<\/p>\n<p>\u95ee\u9898\u4f3c\u4e4e\u4e00\u4e0b\u5b50\u663e\u73b0\u51fa\u6765\u4e86\u3002\u7531\u4e8e\u914d\u7f6e\u4e86IPv4\u548cIPv6\u53cc\u6808\u7f51\u7edc\u5730\u5740\uff0c\u5728\u4e00\u4e9b\u670d\u52a1\u5c42\u9762\u5bf9 localhost \u7684\u89e3\u6790\uff0c\u53ef\u80fd\u662f ipv4\u5730\u5740:127.0.0.1 \u6216\u8005 ipv6\u5730\u5740 ::1 \u3002\u53ef\u80fd\u7531\u4e8e\u67d0\u79cd\u539f\u56e0\uff0clocalhost \u8fd9\u4e2ahostname\u5728Apache\u7684mod_jk\u4e2d\u89e3\u6790\u51fa\u662f ipv6\u5730\u5740\uff0c\u800cTomcat\u7684\u7a0b\u5e8f\u4e2d\u5219\u89e3\u6790\u51fa ipv4\u5730\u5740\u3002<\/p>\n<p>\u76f8\u5f53\u4e8e\u662fmod_jk\u4e2d\u7684worker\u914d\u7f6e\u4e2d\uff1a\u00a0apache\/conf\/extra\/workers.properties \uff1a<\/p>\n<p>worker.balancer.balance_workers=node1<br \/>worker.node1.reference=worker.template<br \/>worker.node1.host=localhost\u00a0<br \/>#worker.node1.host=127.0.0.1<br \/>worker.node1.port=8009<\/p>\n<p>\u8fd9\u91cc\u542f\u52a8\u540e\u53bb\u8fde\u63a5 ::1:8009 \u670d\u52a1\uff0c \u800c\u5728 Tomcat\u4e2d\u670d\u52a1\u53ef\u80fd\u542f\u52a8\u5728 127.0.0.1:8009\u4e0a\uff0c\u4e8e\u662f\u4e24\u8fb9\u5c31\u8fd9\u4e48\u56e0\u4e3aip\u5730\u5740\u7684v4\u6216\u8005v6\u800c\u9519\u8fc7\u4e86\u3002\u95ee\u9898\u82e5\u662f\u5982\u6b64\uff0c\u4f3c\u4e4e\u4e5f\u597d\u89e3\u51b3\uff1a1\uff09\u4fee\u6539\u7cfb\u7edf\u7684hosts\u6587\u4ef6\uff0c\u4fee\u6539\u6d88\u9664\u4e3b\u673a\u540d localhost\u7684\u6b67\u4e49\uff0c\u53ea\u7528\u5728\u4f20\u7edf\u7684127.0.0.1\u4e0a\uff0c\u800c\u9488\u5bf9 ::1 \u5730\u5740\uff0c\u53e6\u5916\u547d\u540d\u4e3a localhost-ipv6\uff1b\u6216\u80052\uff09\u5728Apache\u548cTomcat\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4e0d\u518d\u4f7f\u7528\u4e3b\u673a\u540d\uff0c\u90fd\u4f7f\u7528\u660e\u786e\u800c\u5177\u4f53\u7684IP\u5730\u5740\u3002 \u7ecf\u8fc7\u4e00\u756a\u6298\u817e\uff0c\u6211\u4eec\u6d88\u9664\u4e86 localhost\u7684\u6b67\u4e49\uff0c\u53ea\u6307\u5411 127.0.0.1, \u540c\u65f6\u5728 Tomcat\/conf\/server.xml \u4e2d\uff1a<\/p>\n<p>&lt;Connector protocol=&#8221;AJP\/1.3&#8243;<br \/>\u00a0 \u00a0 port=&#8221;8009&#8243;<br \/>\u00a0 \u00a0address=&#8221;127.0.0.1&#8243;<br \/>\u00a0 \u00a0redirectPort=&#8221;8443&#8243;\/&gt;<\/p>\n<p>\u4e5f\u505a\u4e86\u5177\u4f53\u7684IPv4\u5730\u5740\u7684\u6307\u5b9a\uff0c\u8fd9\u6837\u6309\u9884\u671f\u5e94\u8be5\u662f\u80fd\u591f\u8fde\u901a\u7684\u3002<br \/>\u679c\u7136\uff0c\u7ecf\u8fc7\u8fd9\u4e48\u4e00\u756a\u64cd\u4f5c\uff0cmod_jk\u4e0d\u518d\u62a5\u9519\u8bf4\u65e0\u6cd5\u8fde\u63a5\u00a0 ::1:8009 \u6216\u8005 127.0.0.1:8009\u7684\u9519\u8bef\uff0c\u4f46\u4f9d\u7136\u65e0\u6cd5\u8fdb\u884c\u8fde\u63a5\uff01 \u65b0\u7684\u9519\u8bef\u7ed3\u679c\u4f9d\u7136\u662f connection failed to backend service&#8230;. in error state or wrong port&#8230;.<\/p>\n<p>\u4e0e\u6b64\u524d\u6240\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u6b21\u660e\u786e\u663e\u793a\u51fa\u4e86 socket connected\uff0c\u8fde\u63a5\u5df2\u7ecf\u88ab\u521b\u5efa\uff0c\u4e0d\u518d\u662f\u7f51\u7edc\u5c42\u7684\u95ee\u9898\u3002\u8fd9\u6b21\u7684\u9519\u8bef\uff0c\u589e\u52a0\u4e86 timeout during cping\/cpong &#8230;. \uff0c\u6839\u636e\u8fd9\u4e9b\u65b0\u7684\u62a5\u9519\u4fe1\u606f\uff0c\u7ee7\u7eed\u4f9d\u9760\u641c\u7d22\u5f15\u64ce\u7684\u5e2e\u52a9\uff0c\u6316\u6398\u76f8\u5173\u4fe1\u606f\u3002<br \/>\u679c\u7136\uff0c\u5df2\u7ecf\u6709\u540c\u5b66\u9047\u5230\u7c7b\u4f3c\u95ee\u9898\uff0c\u539f\u6765\u662f\u7531\u4e8e \u65b0\u7248\u7684Tomcat\u9ed8\u8ba4\u542f\u7528\u4e86\u65b0\u7684\u914d\u7f6e\uff0c\u4f46\u672a\u80fd\u5728\u65e5\u5fd7\u4fe1\u606f\u4e2d\u7ed9\u51fa\u5177\u4f53\u800c\u660e\u786e\u7684\u6307\u793a\u3002<\/p>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\">\n<p>(\u00a0<b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/naturedns\/search?q=-R\/v2SS\" target=\"_blank\">-R\/v2SS<\/a><\/b> ) There was a change in Tomcat last year (from version\u00a0<a href=\"https:\/\/tomcat.apache.org\/tomcat-8.5-doc\/changelog.html#Tomcat_8.5.51_(markt)\" rel=\"nofollow noreferrer\">8.5.51<\/a>\u00a0and version\u00a0<a href=\"https:\/\/tomcat.apache.org\/tomcat-9.0-doc\/changelog.html#Tomcat_9.0.31_(markt)\" rel=\"nofollow noreferrer\">9.0.31<\/a>), which introduced a\u00a0<code>secretRequired<\/code>\u00a0attribute to the AJP connector with a default of\u00a0<code>true<\/code>\u00a0(cf.\u00a0<a href=\"http:\/\/tomcat.apache.org\/tomcat-8.5-doc\/config\/ajp.html#Standard_Implementations\" rel=\"nofollow noreferrer\">documentation<\/a>). Hence you can either:<\/p>\n<ul>\n<li>\n<p>add a shared secret between the AJP connector and\u00a0<code>mod_jk<\/code><\/p>\n<\/li>\n<li>\n<p>or add\u00a0<code>secretRequired=\"false\"<\/code>\u00a0to the AJP connector.<\/p>\n<\/li>\n<\/ul>\n<p>\u76f4\u767d\u5730\u8bf4\uff0cTomcat-9.0.31+\uff0c \u9ed8\u8ba4\u542f\u7528 secretRequired=true, \u4f46\u5728\u76f8\u5e94\u7684\u6837\u4f8b\u914d\u7f6e\u9ed8\u8ba4\u8bbe\u7f6e\u4e2d\u5374\u6ca1\u6709\u63d0\u53ca\u3002\u800c\u4e14\u5728\u9519\u8bef\u65e5\u5fd7\u4e2d\u4e5f\u6ca1\u6709\u63d0\u53ca\u662f\u7531\u4e8esecretRequired\u7684\u95ee\u9898\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5c31\u9700\u8981\u624b\u5de5\u914d\u7f6e\uff1a1\uff09\u589e\u52a0\u4e00\u4e2a\u5171\u4eab\u7684\u5b89\u5168key\u5728 AJP\u548cmod_jk\u4e4b\u95f4\uff0c \u6216\u80052\uff09\u901a\u8fc7\u5728AJP\u8bbe\u7f6e secretRequired=false\uff0c\u505c\u7528\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n<p>\u5947\u602a\u7684\u662f\u8fd9\u4e2aAJP\u9ed8\u8ba4\u542f\u7528\u4e86secretRequired=true, \u800c mod_jk \u5219\u662f\u9ed8\u8ba4\u4e0d\u542f\u7528\uff0c\u8bbe\u7f6e secretRequired=false\uff0c\u4e24\u8fb9\u81ea\u7136\u5c31\u65e0\u6cd5\u8fdb\u884c\u901a\u4fe1\u3002\u9057\u61be \u8fd9\u6837\u7684\u9519\u914d\uff0c\u5728\u8f6f\u4ef6\u5c42\u9762\u53d1\u751f\u4e86\uff0c\u800c\u5728\u9519\u8bef\u4fe1\u606f\u91cc\u4e5f\u6307\u4ee3\u4e0d\u660e\uff0c\u5e94\u8be5\u5728\u540e\u7eed\u4e88\u4ee5\u4fee\u6b63\u3002<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e\u65b0\u7248\u7684Apache-2.4.46+\u548cTomcat-9.0.45+\u914d\u7f6e\u4e00\u4f8b\u65b0\u7684 &hellip; <a href=\"https:\/\/ufqi.com\/blog\/apache-tomcat-mod_jk-conn-failure\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,2],"tags":[417,227,230,229],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2538"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=2538"}],"version-history":[{"count":3,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2538\/revisions"}],"predecessor-version":[{"id":2541,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2538\/revisions\/2541"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=2538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=2538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=2538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}