{"id":59563,"date":"2024-10-12T22:58:14","date_gmt":"2024-10-12T14:58:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/59563\/"},"modified":"2024-10-12T22:58:14","modified_gmt":"2024-10-12T14:58:14","slug":"centos-%e4%b8%ad%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%ef%bc%9f-%e6%9f%a5%e7%9c%8bcentos-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/59563\/","title":{"rendered":"CentOS \u4e2d\u5982\u4f55\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\uff1f (\u67e5\u770bcentos \u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"centos-%e4%b8%ad%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%ef%bc%9f-zKJhQgLWeN\">CentOS \u4e2d\u5982\u4f55\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\uff1f<\/h1>\n<p>\u5728 CentOS \u7cfb\u7d71\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u76e3\u63a7\u662f\u78ba\u4fdd\u61c9\u7528\u7a0b\u5e8f\u7a69\u5b9a\u904b\u884c\u7684\u91cd\u8981\u74b0\u7bc0\u3002\u7121\u8ad6\u662f MySQL\u3001MariaDB \u9084\u662f PostgreSQL\uff0c\u4e86\u89e3\u5982\u4f55\u67e5\u770b\u6578\u64da\u5eab\u7684\u72c0\u614b\u5c0d\u65bc\u7dad\u8b77\u7cfb\u7d71\u7684\u5065\u5eb7\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5728 CentOS \u4e2d\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\u7684\u5e7e\u7a2e\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"1-%e6%9f%a5%e7%9c%8b-mysql-mariadb-%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b-zKJhQgLWeN\">1. \u67e5\u770b MySQL\/MariaDB \u6578\u64da\u5eab\u72c0\u614b<\/h2>\n<p>MySQL \u548c MariaDB \u662f\u6700\u5e38\u7528\u7684\u958b\u6e90\u6578\u64da\u5eab\u7cfb\u7d71\u4e4b\u4e00\u3002\u8981\u67e5\u770b\u5176\u72c0\u614b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>systemctl status mariadb\n<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u986f\u793a MariaDB \u670d\u52d9\u7684\u7576\u524d\u72c0\u614b\uff0c\u5305\u62ec\u662f\u5426\u6b63\u5728\u904b\u884c\u3001\u555f\u52d5\u6642\u9593\u4ee5\u53ca\u4efb\u4f55\u932f\u8aa4\u4fe1\u606f\u3002\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f MySQL\uff0c\u5247\u53ef\u4ee5\u5c07\u547d\u4ee4\u4e2d\u7684 &#8220;mariadb&#8221; \u66ff\u63db\u70ba &#8220;mysqld&#8221;\u3002<\/p>\n<h3 id=\"1-1-%e4%bd%bf%e7%94%a8-mysql-mariadb-%e5%ae%a2%e6%88%b6%e7%ab%af%e6%9f%a5%e7%9c%8b%e7%8b%80%e6%85%8b-zKJhQgLWeN\">1.1 \u4f7f\u7528 MySQL\/MariaDB \u5ba2\u6236\u7aef\u67e5\u770b\u72c0\u614b<\/h3>\n<p>\u9664\u4e86\u4f7f\u7528\u7cfb\u7d71\u547d\u4ee4\u5916\uff0c\u9084\u53ef\u4ee5\u901a\u904e MySQL\/MariaDB \u5ba2\u6236\u7aef\u4f86\u67e5\u770b\u6578\u64da\u5eab\u7684\u8a73\u7d30\u72c0\u614b\u3002\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304\u5230\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>mysql -u root -p\n<\/code><\/pre>\n<p>\u767b\u9304\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u67e5\u770b\u6578\u64da\u5eab\u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>SHOW STATUS;\n<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u4e00\u7cfb\u5217\u7684\u72c0\u614b\u8b8a\u91cf\uff0c\u5305\u62ec\u9023\u63a5\u6578\u3001\u67e5\u8a62\u6578\u7b49\u3002\u82e5\u8981\u67e5\u770b\u7279\u5b9a\u7684\u72c0\u614b\u8b8a\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SHOW STATUS LIKE 'Threads_connected';\n<\/code><\/pre>\n<h2 id=\"2-%e6%9f%a5%e7%9c%8b-postgresql-%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b-zKJhQgLWeN\">2. \u67e5\u770b PostgreSQL \u6578\u64da\u5eab\u72c0\u614b<\/h2>\n<p>PostgreSQL \u662f\u53e6\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7cfb\u7d71\u3002\u8981\u67e5\u770b\u5176\u72c0\u614b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>systemctl status postgresql\n<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a PostgreSQL \u670d\u52d9\u7684\u7576\u524d\u72c0\u614b\u3002\u5982\u679c PostgreSQL \u6b63\u5728\u904b\u884c\uff0c\u5247\u6703\u986f\u793a\u5176\u555f\u52d5\u6642\u9593\u548c\u904b\u884c\u72c0\u614b\u3002<\/p>\n<h3 id=\"2-1-%e4%bd%bf%e7%94%a8-postgresql-%e5%ae%a2%e6%88%b6%e7%ab%af%e6%9f%a5%e7%9c%8b%e7%8b%80%e6%85%8b-zKJhQgLWeN\">2.1 \u4f7f\u7528 PostgreSQL \u5ba2\u6236\u7aef\u67e5\u770b\u72c0\u614b<\/h3>\n<p>\u767b\u9304\u5230 PostgreSQL \u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>psql -U postgres\n<\/code><\/pre>\n<p>\u767b\u9304\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u67e5\u770b\u6578\u64da\u5eab\u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>SELECT * FROM pg_stat_activity;\n<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u7576\u524d\u6240\u6709\u6d3b\u52d5\u7684\u9023\u63a5\uff0c\u5305\u62ec\u7528\u6236\u3001\u6578\u64da\u5eab\u540d\u7a31\u548c\u67e5\u8a62\u72c0\u614b\u7b49\u4fe1\u606f\u3002<\/p>\n<h2 id=\"3-%e4%bd%bf%e7%94%a8%e7%9b%a3%e6%8e%a7%e5%b7%a5%e5%85%b7-zKJhQgLWeN\">3. \u4f7f\u7528\u76e3\u63a7\u5de5\u5177<\/h2>\n<p>\u9664\u4e86\u624b\u52d5\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\u5916\uff0c\u9084\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u76e3\u63a7\u5de5\u5177\u4f86\u81ea\u52d5\u5316\u9019\u4e00\u904e\u7a0b\u3002\u4f8b\u5982\uff0cPrometheus \u548c Grafana \u662f\u5e38\u7528\u7684\u76e3\u63a7\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u72c0\u614b\u3002<\/p>\n<h3 id=\"3-1-%e5%ae%89%e8%a3%9d%e5%92%8c%e9%85%8d%e7%bd%ae-prometheus-zKJhQgLWeN\">3.1 \u5b89\u88dd\u548c\u914d\u7f6e Prometheus<\/h3>\n<p>\u8981\u4f7f\u7528 Prometheus \u76e3\u63a7 MySQL \u6216 PostgreSQL\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd Prometheus \u548c\u76f8\u61c9\u7684\u6578\u64da\u5eab\u76e3\u63a7\u63d2\u4ef6\u3002\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u914d\u7f6e Prometheus \u4ee5\u6536\u96c6\u6578\u64da\u5eab\u7684\u6027\u80fd\u6307\u6a19\uff0c\u7136\u5f8c\u4f7f\u7528 Grafana \u4f86\u53ef\u8996\u5316\u9019\u4e9b\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-zKJhQgLWeN\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS \u4e2d\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\u662f\u78ba\u4fdd\u7cfb\u7d71\u7a69\u5b9a\u904b\u884c\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u7121\u8ad6\u662f\u4f7f\u7528\u7cfb\u7d71\u547d\u4ee4\u3001\u6578\u64da\u5eab\u5ba2\u6236\u7aef\u9084\u662f\u76e3\u63a7\u5de5\u5177\uff0c\u4e86\u89e3\u6578\u64da\u5eab\u7684\u904b\u884c\u72c0\u614b\u90fd\u80fd\u5e6b\u52a9\u7ba1\u7406\u54e1\u53ca\u6642\u767c\u73fe\u554f\u984c\u4e26\u9032\u884c\u8abf\u6574\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u80fd\u70ba\u60a8\u7684\u6578\u64da\u5eab\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728CentOS\u4e2d\u67e5\u770b\u6578\u64da\u5eab\u72c0\u614b\uff0c\u638c\u63e1\u547d\u4ee4\u548c\u5de5\u5177\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u904b\u884c\u6b63\u5e38\uff0c\u63d0\u5347\u7cfb\u7d71\u7ba1\u7406\u6548\u7387\u3002<\/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-59563","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59563","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=59563"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59563\/revisions"}],"predecessor-version":[{"id":59564,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59563\/revisions\/59564"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=59563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=59563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=59563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}