{"id":15933,"date":"2024-11-18T13:56:20","date_gmt":"2024-11-18T05:56:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/15933\/"},"modified":"2024-11-18T13:56:20","modified_gmt":"2024-11-18T05:56:20","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e4%b8%8a%e9%85%8d%e7%bd%ae%e9%ab%98%e5%8f%af%e7%94%a8%e7%9a%84%e5%ae%b9%e5%99%a8%e7%9b%91%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15933\/","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7"},"content":{"rendered":"<p>\u5982\u4f55\u5728\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7<\/p>\n<p>\u6982\u8ff0\uff1a<br \/>\u968f\u7740\u5bb9\u5668\u6280\u672f\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4f01\u4e1a\u5c06\u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5230\u5bb9\u5668\u4e2d\u3002\u800c\u9488\u5bf9\u8fd9\u4e9b\u5bb9\u5668\u7684\u76d1\u63a7\u5219\u6210\u4e3a\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u9700\u6c42\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728linux\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7\u3002\u6211\u4eec\u5c06\u4f7f\u7528Prometheus\u4f5c\u4e3a\u76d1\u63a7\u7cfb\u7edf\uff0cGrafana\u4f5c\u4e3a\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u5e76\u4f7f\u7528Docker Swarm\u6765\u5b9e\u73b0\u5bb9\u5668\u7684\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<p>\u6b65\u9aa41\uff1a\u5b89\u88c5Docker Swarm<br \/>Docker Swarm\u662fDocker\u5b98\u65b9\u63d0\u4f9b\u7684\u5bb9\u5668\u7f16\u6392\u5de5\u5177\uff0c\u7528\u4e8e\u5b9e\u73b0\u5bb9\u5668\u7684\u9ad8\u53ef\u7528\u6027\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Docker Swarm\u3002\u8bf7\u6309\u7167Docker Swarm\u5b98\u65b9\u6587\u6863\u7684\u6307\u5f15\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p>\u6b65\u9aa42\uff1a\u5b89\u88c5Prometheus\u548cGrafana<br \/>Prometheus\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u76d1\u63a7\u89e3\u51b3\u65b9\u6848\uff0c\u5176\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u529f\u80fd\u548c\u7075\u6d3b\u7684\u67e5\u8be2\u8bed\u8a00\u3002Grafana\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5c55\u793a\u548c\u5206\u6790\u76d1\u63a7\u6570\u636e\u3002<\/p>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Prometheus\u548cGrafana\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<pre>docker service create --name prometheus \n--publish 9090:9090 \n--mount type=bind,source=\/path\/to\/prometheus.yml,target=\/etc\/prometheus\/prometheus.yml \nprom\/prometheus\n\ndocker service create --name grafana \n--publish 3000:3000 \n--env \"GF_SECURITY_ADMIN_PASSWORD=yourpassword\" \ngrafana\/grafana<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5206\u522b\u57289090\u7aef\u53e3\u548c3000\u7aef\u53e3\u521b\u5efa\u4e24\u4e2a\u5bb9\u5668\uff0c\u4e00\u4e2a\u662fPrometheus\u5bb9\u5668\uff0c\u53e6\u4e00\u4e2a\u662fGrafana\u5bb9\u5668\u3002\u8bf7\u5c06\/path\/to\/prometheus.yml\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u8def\u5f84\uff0c\u5e76\u5c06yourpassword\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u8bbe\u5b9a\u7684\u5bc6\u7801\u3002<\/p>\n<p>\u6b65\u9aa43\uff1a\u914d\u7f6ePrometheus\u76d1\u63a7\u670d\u52a1<br \/>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6ePrometheus\u6765\u76d1\u63a7\u6211\u4eec\u7684\u5bb9\u5668\u3002\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aprometheus.yml\u7684\u6587\u4ef6\uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u793a\u4f8b\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<pre>global:\n  scrape_interval: 15s\n  evaluation_interval: 15s\n\nscrape_configs:\n- job_name: 'prometheus'\n  metrics_path: '\/metrics'\n  static_configs:\n  - targets: ['localhost:9090']\n\n- job_name: 'node_exporter'\n  metrics_path: '\/metrics'\n  static_configs:\n  - targets: ['localhost:9100', 'node1:9100', 'node2:9100']\n\n- job_name: 'docker'\n  metrics_path: '\/metrics'\n  static_configs:\n  - targets: ['localhost:9323']<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u8ff0\u914d\u7f6e\u6587\u4ef6\u5b9a\u4e49\u4e86\u4e09\u4e2a\u76d1\u63a7\u4efb\u52a1\uff0c\u5206\u522b\u662f\u5bf9Prometheus\u81ea\u8eab\u7684\u76d1\u63a7\u3001\u5bf9\u4e3b\u673a\u8282\u70b9\u7684\u76d1\u63a7\u548c\u5bf9Docker\u5bb9\u5668\u7684\u76d1\u63a7\u3002\u8bf7\u5c06\u5176\u4e2d\u7684node1\u548cnode2\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u8282\u70b9\u5730\u5740\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u542f\u52a8Prometheus\u5bb9\u5668\uff1a<\/p>\n<pre>docker service create --name prometheus \n--publish 9090:9090 \n--mount type=bind,source=\/path\/to\/prometheus.yml,target=\/etc\/prometheus\/prometheus.yml \nprom\/prometheus<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b65\u9aa44\uff1a\u914d\u7f6eGrafana<br \/>\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6eGrafana\u6765\u53ef\u89c6\u5316\u6211\u4eec\u7684\u76d1\u63a7\u6570\u636e\u3002\u9996\u5148\uff0c\u6253\u5f00\u4f60\u7684\u6d4f\u89c8\u5668\u5e76\u8bbf\u95eehttp:\/\/yourserverip:3000\uff0c\u4f7f\u7528\u4f60\u5728\u4e4b\u524d\u7684\u5b89\u88c5\u6b65\u9aa4\u4e2d\u8bbe\u7f6e\u7684\u5bc6\u7801\u767b\u5f55Grafana\u3002<\/p>\n<p>\u7136\u540e\uff0c\u524d\u5f80Grafana\u7684\u6570\u636e\u6e90\u754c\u9762\u5e76\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u6e90\u3002\u9009\u62e9Prometheus\u4f5c\u4e3a\u6570\u636e\u6e90\u7c7b\u578b\uff0c\u5e76\u914d\u7f6ePrometheus\u7684\u8bbf\u95ee\u5730\u5740\uff08\u4f8b\u5982\uff1ahttp:\/\/yourserverip:9090\uff09\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4eea\u8868\u677f\u5e76\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u9762\u677f\u6765\u5c55\u793a\u4f60\u611f\u5174\u8da3\u7684\u76d1\u63a7\u6307\u6807\u3002<\/p>\n<p>\u7ed3\u8bba\uff1a<br \/>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u6210\u529f\u5730\u5728Linux\u4e0a\u914d\u7f6e\u4e86\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7\u3002\u4f7f\u7528Prometheus\u548cGrafana\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u6536\u96c6\u3001\u5b58\u50a8\u548c\u53ef\u89c6\u5316\u5bb9\u5668\u7684\u76d1\u63a7\u6570\u636e\u3002\u8fd9\u5c06\u6709\u52a9\u4e8e\u6211\u4eec\u53ca\u65f6\u53d1\u73b0\u5e76\u89e3\u51b3\u5bb9\u5668\u8fd0\u884c\u4e2d\u7684\u95ee\u9898\uff0c\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u5bf9\u4e8e\u4f60\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728Linux\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7 \u6982\u8ff0\uff1a\u968f\u7740\u5bb9\u5668\u6280\u672f\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4f01\u4e1a\u5c06\u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5230\u5bb9\u5668\u4e2d\u3002\u800c\u9488\u5bf9\u8fd9\u4e9b\u5bb9\u5668\u7684\u76d1\u63a7\u5219\u6210\u4e3a\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u9700\u6c42\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728linux\u4e0a\u914d\u7f6e\u9ad8\u53ef\u7528\u7684\u5bb9\u5668\u76d1\u63a7\u3002\u6211\u4eec\u5c06\u4f7f\u7528Prometheus\u4f5c\u4e3a\u76d1\u63a7\u7cfb\u7edf\uff0cGrafana\u4f5c\u4e3a\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u5e76\u4f7f\u7528Docker Swarm\u6765\u5b9e\u73b0\u5bb9\u5668\u7684\u9ad8\u53ef\u7528\u6027\u3002 \u6b65\u9aa41\uff1a\u5b89\u88c5Docker SwarmDocker Swarm\u662fDocker\u5b98\u65b9\u63d0\u4f9b\u7684\u5bb9\u5668\u7f16\u6392\u5de5\u5177\uff0c\u7528\u4e8e\u5b9e\u73b0\u5bb9\u5668\u7684\u9ad8\u53ef\u7528\u6027\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Docker Swarm\u3002\u8bf7\u6309\u7167Docker Swarm\u5b98\u65b9\u6587\u6863\u7684\u6307\u5f15\u8fdb\u884c\u5b89\u88c5\u3002 \u6b65\u9aa42\uff1a\u5b89\u88c5Prometheus\u548cGrafanaPrometheus\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u76d1\u63a7\u89e3\u51b3\u65b9\u6848\uff0c\u5176\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u76d1\u63a7\u529f\u80fd\u548c\u7075\u6d3b\u7684\u67e5\u8be2\u8bed\u8a00\u3002Grafana\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5c55\u793a\u548c\u5206\u6790\u76d1\u63a7\u6570\u636e\u3002 \u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Prometheus\u548cGrafana\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a docker service create &#8211;name prometheus &#8211;publish 9090:9090 &#8211;mount type=bind,source=\/path\/to\/prometheus.yml,target=\/etc\/prometheus\/prometheus.yml prom\/prometheus docker service create &#8211;name grafana &#8211;publish 3000:3000 &#8211;env &#8220;GF_SECURITY_ADMIN_PASSWORD=yourpassword&#8221; grafana\/grafana \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u8ff0\u4ee3\u7801\u5c06\u5206\u522b\u57289090\u7aef\u53e3\u548c3000\u7aef\u53e3\u521b\u5efa\u4e24\u4e2a\u5bb9\u5668\uff0c\u4e00\u4e2a\u662fPrometheus\u5bb9\u5668\uff0c\u53e6\u4e00\u4e2a\u662fGrafana\u5bb9\u5668\u3002\u8bf7\u5c06\/path\/to\/prometheus.yml\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u8def\u5f84\uff0c\u5e76\u5c06yourpassword\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u8bbe\u5b9a\u7684\u5bc6\u7801\u3002 \u6b65\u9aa43\uff1a\u914d\u7f6ePrometheus\u76d1\u63a7\u670d\u52a1\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6ePrometheus\u6765\u76d1\u63a7\u6211\u4eec\u7684\u5bb9\u5668\u3002\u5728\u4f60\u7684Linux\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aprometheus.yml\u7684\u6587\u4ef6\uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u793a\u4f8b\u8fdb\u884c\u914d\u7f6e\uff1a global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: &#8211; job_name: &#8216;prometheus&#8217; metrics_path: &#8216;\/metrics&#8217; static_configs: &#8211; targets: [&#8216;localhost:9090&#8217;] &#8211; job_name: &#8216;node_exporter&#8217; metrics_path: &#8216;\/metrics&#8217; static_configs: &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-15933","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15933"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15933\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}