{"id":183518,"date":"2024-11-10T05:29:19","date_gmt":"2024-11-09T21:29:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183518\/"},"modified":"2024-11-10T05:29:20","modified_gmt":"2024-11-09T21:29:20","slug":"%e4%bd%bf%e7%94%a8-bitnami-postgresql-repmgr-%e9%8f%a1%e5%83%8f%e5%bf%ab%e9%80%9f%e8%a8%ad%e7%bd%ae-postgresql-ha","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183518\/","title":{"rendered":"\u4f7f\u7528 Bitnami\/Postgresql-Repmgr \u93e1\u50cf\u5feb\u901f\u8a2d\u7f6e PostgreSQL HA"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8-bitnami-postgresql-repmgr-%e9%8f%a1%e5%83%8f%e5%bf%ab%e9%80%9f%e8%a8%ad%e7%bd%ae-postgresql-ha-uJkcOClPcT\">\u4f7f\u7528 Bitnami\/Postgresql-Repmgr \u93e1\u50cf\u5feb\u901f\u8a2d\u7f6e PostgreSQL HA<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u9ad8\u53ef\u7528\u6027\uff08HA\uff09\u5c0d\u65bc\u78ba\u4fdd\u696d\u52d9\u9023\u7e8c\u6027\u81f3\u95dc\u91cd\u8981\u3002PostgreSQL \u4f5c\u70ba\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u3002\u5176\u4e2d\uff0c\u4f7f\u7528 Bitnami \u63d0\u4f9b\u7684 PostgreSQL-Repmgr \u93e1\u50cf\u662f\u4e00\u500b\u5feb\u901f\u4e14\u6709\u6548\u7684\u9078\u64c7\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528\u9019\u4e00\u93e1\u50cf\u4f86\u8a2d\u7f6e PostgreSQL \u7684\u9ad8\u53ef\u7528\u6027\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-postgresql-repmgr%ef%bc%9f-uJkcOClPcT\">\u4ec0\u9ebc\u662f PostgreSQL-Repmgr\uff1f<\/h2>\n<p>PostgreSQL-Repmgr \u662f\u4e00\u500b\u7528\u65bc\u7ba1\u7406 PostgreSQL \u4e3b\u5f9e\u8907\u88fd\u7684\u5de5\u5177\u3002\u5b83\u63d0\u4f9b\u4e86\u7c21\u55ae\u7684\u547d\u4ee4\u884c\u754c\u9762\u4f86\u914d\u7f6e\u548c\u76e3\u63a7 PostgreSQL \u7684\u8907\u88fd\u96c6\u7fa4\u3002Repmgr \u4f7f\u5f97\u5728\u4e3b\u6578\u64da\u5eab\u6545\u969c\u6642\u80fd\u5920\u5feb\u901f\u5207\u63db\u5230\u5099\u7528\u6578\u64da\u5eab\uff0c\u5f9e\u800c\u5be6\u73fe\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87-bitnami-%e9%8f%a1%e5%83%8f%ef%bc%9f-uJkcOClPcT\">\u70ba\u4ec0\u9ebc\u9078\u64c7 Bitnami \u93e1\u50cf\uff1f<\/h2>\n<p>Bitnami \u63d0\u4f9b\u7684 PostgreSQL-Repmgr \u93e1\u50cf\u7c21\u5316\u4e86\u5b89\u88dd\u548c\u914d\u7f6e\u904e\u7a0b\u3002\u9019\u4e9b\u93e1\u50cf\u5df2\u7d93\u9810\u5148\u914d\u7f6e\u597d\uff0c\u4e26\u5305\u542b\u4e86\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8cf4\u9805\uff0c\u8b93\u7528\u6236\u80fd\u5920\u5feb\u901f\u4e0a\u624b\u3002\u4f7f\u7528 Bitnami \u93e1\u50cf\u7684\u597d\u8655\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u7c21\u5316\u7684\u5b89\u88dd\u904e\u7a0b<\/li>\n<li>\u81ea\u52d5\u914d\u7f6e\u9ad8\u53ef\u7528\u6027<\/li>\n<li>\u6301\u7e8c\u66f4\u65b0\u548c\u5b89\u5168\u6027\u4fee\u88dc<\/li>\n<\/ul>\n<h2 id=\"%e8%a8%ad%e7%bd%ae-postgresql-ha-%e7%9a%84%e6%ad%a5%e9%a9%9f-uJkcOClPcT\">\u8a2d\u7f6e PostgreSQL HA \u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e9%83%a8%e7%bd%b2-bitnami-postgresql-repmgr-%e9%8f%a1%e5%83%8f-uJkcOClPcT\">\u6b65\u9a5f 1\uff1a\u90e8\u7f72 Bitnami PostgreSQL-Repmgr \u93e1\u50cf<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\u90e8\u7f72 Bitnami PostgreSQL-Repmgr \u93e1\u50cf\u3002\u9019\u53ef\u4ee5\u901a\u904e Docker \u6216\u8005\u76f4\u63a5\u5728\u96f2\u4f3a\u670d\u5668\u4e0a\u9032\u884c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Docker \u7684\u793a\u4f8b\u547d\u4ee4\uff1a<\/p>\n<pre><code>docker run -d --name postgresql-repmgr -p 5432:5432 bitnami\/postgresql-repmgr<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e9%85%8d%e7%bd%ae%e4%b8%bb%e5%be%9e%e8%a4%87%e8%a3%bd-uJkcOClPcT\">\u6b65\u9a5f 2\uff1a\u914d\u7f6e\u4e3b\u5f9e\u8907\u88fd<\/h3>\n<p>\u5728\u90e8\u7f72\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u914d\u7f6e\u4e3b\u5f9e\u8907\u88fd\u3002\u9019\u53ef\u4ee5\u901a\u904e\u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6\u4f86\u5b8c\u6210\u3002\u9996\u5148\uff0c\u9032\u5165\u5bb9\u5668\u5167\u90e8\uff1a<\/p>\n<pre><code>docker exec -it postgresql-repmgr bash<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u7de8\u8f2f PostgreSQL \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>nano \/opt\/bitnami\/postgresql\/conf\/postgresql.conf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\uff0c\u78ba\u4fdd\u4ee5\u4e0b\u53c3\u6578\u5df2\u6b63\u78ba\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>wal_level = replica\nmax_wal_senders = 3\nhot_standby = on<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e5%95%9f%e7%94%a8-repmgr-uJkcOClPcT\">\u6b65\u9a5f 3\uff1a\u555f\u7528 Repmgr<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u914d\u7f6e Repmgr\u3002\u7de8\u8f2f Repmgr \u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>nano \/opt\/bitnami\/repmgr\/etc\/repmgr.conf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\uff0c\u8a2d\u7f6e\u4ee5\u4e0b\u53c3\u6578\uff1a<\/p>\n<pre><code>node_id=1\nnode_name='primary'\nconninfo='host=localhost user=repmgr dbname=repmgr'\ndata_directory='\/opt\/bitnami\/postgresql\/data'<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4%ef%bc%9a%e5%95%9f%e5%8b%95-repmgr-%e6%9c%8d%e5%8b%99-uJkcOClPcT\">\u6b65\u9a5f 4\uff1a\u555f\u52d5 Repmgr \u670d\u52d9<\/h3>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u555f\u52d5 Repmgr \u670d\u52d9\u4ee5\u958b\u59cb\u76e3\u63a7\u548c\u7ba1\u7406\u8907\u88fd\uff1a<\/p>\n<pre><code>repmgr primary start<\/code><\/pre>\n<h2 id=\"%e7%9b%a3%e6%8e%a7%e5%92%8c%e6%95%85%e9%9a%9c%e8%bd%89%e7%a7%bb-uJkcOClPcT\">\u76e3\u63a7\u548c\u6545\u969c\u8f49\u79fb<\/h2>\n<p>\u4e00\u65e6\u8a2d\u7f6e\u5b8c\u6210\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Repmgr \u63d0\u4f9b\u7684\u547d\u4ee4\u4f86\u76e3\u63a7\u96c6\u7fa4\u72c0\u614b\u548c\u57f7\u884c\u6545\u969c\u8f49\u79fb\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u96c6\u7fa4\u72c0\u614b\uff1a<\/p>\n<pre><code>repmgr cluster show<\/code><\/pre>\n<p>\u5728\u4e3b\u6578\u64da\u5eab\u6545\u969c\u7684\u60c5\u6cc1\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u6545\u969c\u8f49\u79fb\uff1a<\/p>\n<pre><code>repmgr standby promote<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-uJkcOClPcT\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528 Bitnami\/Postgresql-Repmgr \u93e1\u50cf\u8a2d\u7f6e PostgreSQL \u7684\u9ad8\u53ef\u7528\u6027\u74b0\u5883\u662f\u4e00\u500b\u9ad8\u6548\u4e14\u7c21\u55ae\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u90e8\u7f72\u548c\u914d\u7f6e PostgreSQL \u7684\u4e3b\u5f9e\u8907\u88fd\uff0c\u4e26\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u6301\u7e8c\u53ef\u7528\u6027\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\u5c07\u662f\u5be6\u73fe\u9019\u4e00\u76ee\u6a19\u7684\u95dc\u9375\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Bitnami\/Postgresql-Repmgr \u93e1\u50cf\uff0c\u5feb\u901f\u8a2d\u7f6e\u9ad8\u53ef\u7528\u6027 PostgreSQL \u74b0\u5883\uff0c\u78ba\u4fdd\u6578\u64da\u6301\u4e45\u6027\u8207\u7cfb\u7d71\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-183518","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183518","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=183518"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183518\/revisions"}],"predecessor-version":[{"id":183519,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183518\/revisions\/183519"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}