{"id":1983,"date":"2020-07-29T21:52:53","date_gmt":"2020-07-29T13:52:53","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1983"},"modified":"2020-07-29T21:52:53","modified_gmt":"2020-07-29T13:52:53","slug":"postgresql%e8%ae%bf%e9%97%ae%e6%8e%a7%e5%88%b6%ef%bc%8c%e5%85%81%e8%ae%b8%e7%a6%81%e6%ad%a2%e6%8c%87%e5%ae%9aip%e8%ae%bf%e9%97%ae-2","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1983","title":{"rendered":"PostgreSQL\u8bbf\u95ee\u63a7\u5236\uff0c\u5141\u8bb8&amp;\u7981\u6b62\u6307\u5b9aIP\u8bbf\u95ee"},"content":{"rendered":"<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div>\nPostgreSQL\u4e2d\u5141\u8bb8\u54ea\u4e9bIP\u7684\u673a\u5668\u80fd\u591f\u8bbf\u95ee\u6570\u636e\u5e93\u662f\u7531\u914d\u7f6e\u6587\u4ef6pg_hba.conf\u63a7\u5236\u7684\uff0c\u901a\u8fc7\u914d\u7f6e\u8be5\u6587\u4ef6\uff0c\u80fd\u591f\u6307\u5b9a\u54ea\u4e9bip\u53ef\u4ee5\u8bbf\u95ee\uff0c\u54ea\u4e9bip\u4e0d\u53ef\u4ee5\u8bbf\u95ee\uff0c\u4ee5\u53ca\u8bbf\u95ee\u7684\u8ba4\u8bc1\u65b9\u5f0f\u3002hba\u662fhost-based authentication\u7684\u7f29\u5199.<br \/>\ninitdb\u5728\u521d\u59cb\u5316\u6570\u636e\u76ee\u5f55\u7684\u65f6\u5019\uff0c\u4f1a\u751f\u6210\u4e00\u4e2a\u9ed8\u8ba4\u7684pg_hba.conf\u6587\u4ef6\u3002pg_hba.conf\u6587\u4ef6\u683c\u5f0f\u7531\u591a\u6761\u8bb0\u5f55\u7ec4\u6210\uff0c\u6bcf\u6761\u8bb0\u5f55\u5360\u4e00\u884c\uff0c#\u5f00\u5934\u4e3a\u6ce8\u91ca\uff0c\u8fd9\u4e9b\u8bb0\u5f55\u63a7\u5236\u7740\u5ba2\u6237\u7aef\u8bbf\u95ee\u6570\u636e\u5e93\u7684\u6743\u9650\u548c\u8ba4\u8bc1\u65b9\u5f0f\u3002<br \/>\n\u5148\u770b\u4e00\u4e2aPostgreSQL\u9ed8\u8ba4\u751f\u6210\u7684pg_hba.conf\u6587\u4ef6\u793a\u4f8b\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code># TYPE  DATABASE        USER            ADDRESS                 METHOD\n# \\\"local\\\" is for Unix domain socket connections only\nlocal   all             all                                     trust\n# IPv4 local connections:\nhost    all             all             127.0.0.1\/32            trust\n# IPv6 local connections:\nhost    all             all             ::1\/128                 trust\n# Allow replication connections from localhost, by a user with the\n# replication privilege.\nlocal   replication     all                                     trust\nhost    replication     all             127.0.0.1\/32            trust\nhost    replication     all             ::1\/128                 trust\n<\/code><\/pre>\n<h4>1. \u8bed\u6cd5<\/h4>\n<p>local &lt;dbname&gt; &lt;user&gt; &lt;auth-method&gt; [auth-options]<br \/>\nhost &lt;dbname&gt; &lt;user&gt; &lt;ip\/masklen&gt; &lt;auth-method&gt; [auth-options]<br \/>\n<strong>\u4f8b\u5b50\uff1a<\/strong><br \/>\n\u672c\u5730socket\u8fde\u63a5<br \/>\nlocal all all trust<br \/>\nIPv4\u672c\u5730\u8fde\u63a5<br \/>\nhost all all 127.0.0.1\/32\u00a0trust<br \/>\n\u5141\u8bb8\u6240\u6709IP\u4f7f\u7528md5\u52a0\u5bc6\u7684\u53e3\u4ee4\u8bbf\u95ee<br \/>\nhost all all 0.0.0.0\/0 md5<\/p>\n<h4>2. \u5b57\u6bb5\u53d6\u503c\u8be6\u89e3<\/h4>\n<h5>2.1 \u7b2c\u4e00\u4e2a\u5b57\u6bb5\uff0c\u4e3b\u673a\u7c7b\u578b<\/h5>\n<ul>\n<li>local\uff0c\u5339\u914d\u672c\u5730socket\u65b9\u5f0f\u8fde\u63a5\u6570\u636e\u5e93<\/li>\n<li>host\uff0c\u5339\u914dTCP\/IP\u7f51\u7edc\u534f\u8bae\u8fde\u63a5\uff0c\u5305\u62ecSSL\u548c\u975eSSL<\/li>\n<li>hostssl\uff0c\u5339\u914dTCP\/IP\u7f51\u7edc\u534f\u8bae\u8fde\u63a5\uff0c\u5fc5\u987b\u662fSSL\u52a0\u5bc6\u7684\u8fde\u63a5<\/li>\n<li>hostnossl\uff0c\u5339\u914dTCP\/IP\u7f51\u7edc\u534f\u8bae\u8fde\u63a5\uff0c\u5fc5\u987b\u975eSSL\u52a0\u5bc6\u7684<\/li>\n<\/ul>\n<h5>2.2 \u7b2c\u4e8c\u4e2a\u5b57\u6bb5\uff0c\u6570\u636e\u5e93\u540d\u79f0<\/h5>\n<p>\u4e00\u884c\u8bb0\u5f55\u7684\u7b2c\u4e8c\u4e2a\u5b57\u6bb5\uff0c&lt;dbname&gt;\u7528\u4e8e\u8bbe\u7f6e\u4e00\u4e2a\u6570\u636e\u5e93\u540d\u79f0\uff0c\u8bbe\u7f6eall\u8868\u793a\u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u6570\u636e\u5e93\uff0c\u8bbe\u7f6e\u4e3areplication\u8868\u793a\u5141\u8bb8\u6d41\u590d\u5236\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u540d\u53eb\u201creplication\u201d\u7684\u6570\u636e\u5e93\u3002<\/p>\n<h5>2.3 \u7b2c\u4e09\u4e2a\u5b57\u6bb5\uff0c\u7528\u6237\u540d\u79f0<\/h5>\n<p>\u4e00\u884c\u8bb0\u5f55\u7684\u7b2c\u4e09\u4e2a\u5b57\u6bb5\uff0c&lt;user&gt;\u8868\u793a\u4e00\u4e2a\u7528\u6237\u540d\u79f0\uff0c\u8bbe\u7f6e\u4e3aall\uff0c\u5339\u914d\u6240\u6709\u7528\u6237\u3002<\/p>\n<h5>2.4 \u7b2c\u56db\u4e2a\u5b57\u6bb5\uff0cIP\u5730\u5740<\/h5>\n<p>\u4e00\u884c\u8bb0\u5f55\u7684\u7b2c\u56db\u4e2a\u5b57\u6bb5\uff0c&lt;ip\/masklen&gt;\u8868\u793a\u5141\u8bb8\u54ea\u4e9bIP\u5730\u5740\u6765\u8bbf\u95ee\uff0c\u4e5f\u53ef\u4ee5\u5339\u914dip\u6bb5\uff0c\u5982192.168.56.0\/24\u3002\u914d\u7f6e\u4e3a0.0.0.0\/0 \u8868\u793a\u5339\u914d\u4efb\u610fIP\u3002<\/p>\n<h5>2.5 \u7b2c\u4e94\u4e2a\u5b57\u6bb5\uff0c\u8ba4\u8bc1\u65b9\u5f0f<\/h5>\n<p>\u4e00\u884c\u8bb0\u5f55\u7684\u7b2c\u4e94\u4e2a\u5b57\u6bb5\uff0c&lt;auth-method&gt;\u8868\u793a\u9a8c\u8bc1\u65b9\u6cd5\uff0c\u5e38\u7528\u7684\u6709trust,reject,md5,ident\u7b49\u3002<\/p>\n<ul>\n<li>trust\uff0c\u65e0\u6761\u4ef6\u7684\u5141\u8bb8\u8fde\u63a5\uff0c\u4e0d\u9700\u8981\u5bc6\u7801\u6216\u5176\u4ed6\u8ba4\u8bc1<\/li>\n<li>reject\uff0c\u65e0\u6761\u4ef6\u7684\u62d2\u7edd\u8fde\u63a5<\/li>\n<li>md5\uff0c\u8981\u6c42\u5ba2\u6237\u7aef\u63d0\u4f9b\u4e00\u4e2aMD5\u52a0\u5bc6\u7684\u53e3\u4ee4\u8fdb\u884c\u8ba4\u8bc1<\/li>\n<li>password\uff0c\u8981\u6c42\u5ba2\u6237\u7aef\u63d0\u4f9b\u4e00\u4e2a\u672a\u52a0\u5bc6\u7684\u53e3\u4ee4\u8fdb\u884c\u8ba4\u8bc1<\/li>\n<li>gss\uff0c\u7528GSSAPI\u8ba4\u8bc1\u7528\u6237<\/li>\n<li>sspi\uff0c\u7528SSPI\u8ba4\u8bc1\u7528\u6237<\/li>\n<li>krb5\uff0c\u7528Kerberos V5\u8ba4\u8bc1\u7528\u6237<\/li>\n<li>ident\uff0c\u5141\u8bb8\u5ba2\u6237\u7aef\u4e0a\u7684\u7279\u5b9a\u64cd\u4f5c\u7cfb\u7edf\u7528\u6237\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/li>\n<li>ldap\uff0c\u7528LDAP\u670d\u52a1\u5668\u8ba4\u8bc1<\/li>\n<li>radius\uff0c\u7528RADIUS\u670d\u52a1\u5668\u8ba4\u8bc1<\/li>\n<li>cert\uff0c\u7528SSL\u5ba2\u6237\u7aef\u8bc1\u4e66\u8ba4\u8bc1<\/li>\n<li>pam\uff0c\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u53ef\u63d2\u5165\u8ba4\u8bc1\u6a21\u5757\u670d\u52a1(PAM)\u6765\u8ba4\u8bc1<\/li>\n<\/ul>\n<h5>2.6 \u7b2c\u516d\u4e2a\u5b57\u6bb5\uff0c\u8ba4\u8bc1\u9009\u9879<\/h5>\n<p>\u4e00\u884c\u8bb0\u5f55\u7684\u7b2c\u516d\u4e2a\u5b57\u6bb5\uff0c[auth-options] \u8868\u793a\u8ba4\u8bc1\u9009\u9879\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u6307\u5b9a\u3002<\/p>\n<hr \/>\n<p><strong>\u6ce8\uff1a<\/strong><br \/>\n\u4fee\u6539pg_hba.conf\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u751f\u6548\u3002<br \/>\nservice postgresql\u00a0reload<br \/>\n\u6216\u8005<br \/>\npg_ctl reload -D data_dir<br \/>\n\u6216\u8005<br \/>\nselect pg_reload_conf();\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL\u4e2d\u5141\u8bb8\u54ea\u4e9bIP\u7684\u673a\u5668\u80fd\u591f\u8bbf\u95ee\u6570\u636e\u5e93\u662f\u7531\u914d\u7f6e\u6587\u4ef6pg_hba.conf\u63a7\u5236\u7684\uff0c\u901a\u8fc7\u914d\u7f6e\u8be5\u6587\u4ef6 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1983\"> <span class=\"screen-reader-text\">PostgreSQL\u8bbf\u95ee\u63a7\u5236\uff0c\u5141\u8bb8&amp;\u7981\u6b62\u6307\u5b9aIP\u8bbf\u95ee<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[134,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"PostgreSQL\u4e2d\u5141\u8bb8\u54ea\u4e9bIP\u7684\u673a\u5668\u80fd\u591f\u8bbf\u95ee\u6570\u636e\u5e93\u662f\u7531\u914d\u7f6e\u6587\u4ef6pg_hba.conf\u63a7\u5236\u7684\uff0c\u901a\u8fc7\u914d\u7f6e\u8be5\u6587\u4ef6&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1983"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1983"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1983\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1983"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}