{"id":13807,"date":"2024-11-15T21:41:46","date_gmt":"2024-11-15T13:41:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/13807\/"},"modified":"2024-11-15T21:41:46","modified_gmt":"2024-11-15T13:41:46","slug":"%e4%bd%bf%e7%94%a8docker%e5%ae%89%e8%a3%85grafana-loki%e7%9a%84%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/13807\/","title":{"rendered":"\u4f7f\u7528Docker\u5b89\u88c5Grafana Loki\u7684\u6559\u7a0b"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8docker%e5%ae%89%e8%a3%85grafana-loki%e7%9a%84%e6%95%99%e7%a8%8b-oyhFZTvkpO\">\u4f7f\u7528Docker\u5b89\u88c5Grafana Loki\u7684\u6559\u7a0b<\/h1>\n<p>Grafana Loki \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\uff0c\u65e8\u5728\u4e0e Grafana \u4e00\u8d77\u4f7f\u7528\uff0c\u63d0\u4f9b\u9ad8\u6548\u7684\u65e5\u5fd7\u7ba1\u7406\u548c\u67e5\u8be2\u529f\u80fd\u3002\u5b83\u7684\u8bbe\u8ba1\u7406\u5ff5\u662f\u4e0e Prometheus \u7c7b\u4f3c\uff0c\u4f46\u4e13\u6ce8\u4e8e\u65e5\u5fd7\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Docker \u5b89\u88c5 Grafana Loki\uff0c\u5e76\u8fdb\u884c\u57fa\u672c\u914d\u7f6e\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%8f%90%e6%9d%a1%e4%bb%b6-oyhFZTvkpO\">\u524d\u63d0\u6761\u4ef6<\/h2>\n<ul>\n<li>\u786e\u4fdd\u5df2\u5b89\u88c5 Docker \u548c Docker Compose\u3002<\/li>\n<li>\u5177\u5907\u57fa\u672c\u7684\u547d\u4ee4\u884c\u64cd\u4f5c\u80fd\u529b\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%ad%a5%e9%aa%a4%e4%b8%80%ef%bc%9a%e5%88%9b%e5%bb%ba%e9%a1%b9%e7%9b%ae%e7%9b%ae%e5%bd%95-oyhFZTvkpO\">\u6b65\u9aa4\u4e00\uff1a\u521b\u5efa\u9879\u76ee\u76ee\u5f55<\/h2>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\u6765\u5b58\u653e Loki \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u3002<\/p>\n<pre><code>mkdir loki-docker\ncd loki-docker\n<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%aa%a4%e4%ba%8c%ef%bc%9a%e5%88%9b%e5%bb%ba%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-oyhFZTvkpO\">\u6b65\u9aa4\u4e8c\uff1a\u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/h2>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>loki-config.yaml<\/code> \u7684\u914d\u7f6e\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>cat &gt; loki-config.yaml &lt;&lt; EOF\nauth_enabled: false\n\nserver:\n  http_listen_port: 3100\n\ningester:\n  wal:\n    enabled: true\n    dir: \/loki\/wal\n\nschema_config:\n  configs:\n    - from: 2020-10-24\n      store: boltdb-shipper\n      object_store: s3\n      schema: v11\n      index:\n        prefix: index_\n        period: 24h\n\nstorage_config:\n  boltdb-shipper:\n    active_index_directory: \/loki\/index\n    shared_store: filesystem\n    cache_location: \/loki\/cache\n\ncompactor:\n  working_directory: \/loki\/compactor\n  shared_store: filesystem\n\nhttp:\n  read_timeout: 5m\n  write_timeout: 5m\nEOF\n<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%aa%a4%e4%b8%89%ef%bc%9a%e5%88%9b%e5%bb%ba-docker-compose-%e6%96%87%e4%bb%b6-oyhFZTvkpO\">\u6b65\u9aa4\u4e09\uff1a\u521b\u5efa Docker Compose \u6587\u4ef6<\/h2>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>docker-compose.yml<\/code> \u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>version: '3'\n\nservices:\n  loki:\n    image: grafana\/loki:latest\n    ports:\n      - \"3100:3100\"\n    volumes:\n      - .\/loki-config.yaml:\/etc\/loki\/loki.yaml\n      - loki-data:\/loki\n    command: -config.file=\/etc\/loki\/loki.yaml\n\nvolumes:\n  loki-data:\n<\/code><\/pre>\n<h2 id=\"%e6%ad%a5%e9%aa%a4%e5%9b%9b%ef%bc%9a%e5%90%af%e5%8a%a8-loki-%e6%9c%8d%e5%8a%a1-oyhFZTvkpO\">\u6b65\u9aa4\u56db\uff1a\u542f\u52a8 Loki \u670d\u52a1<\/h2>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 Loki \u670d\u52a1\uff1a<\/p>\n<pre><code>docker-compose up -d\n<\/code><\/pre>\n<p>\u6b64\u547d\u4ee4\u5c06\u4e0b\u8f7d Loki \u955c\u50cf\u5e76\u5728\u540e\u53f0\u8fd0\u884c Loki \u670d\u52a1\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee <code>http:\/\/localhost:3100<\/code> \u6765\u68c0\u67e5\u670d\u52a1\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<h2 id=\"%e6%ad%a5%e9%aa%a4%e4%ba%94%ef%bc%9a%e4%bd%bf%e7%94%a8-grafana-%e8%bf%9e%e6%8e%a5-loki-oyhFZTvkpO\">\u6b65\u9aa4\u4e94\uff1a\u4f7f\u7528 Grafana \u8fde\u63a5 Loki<\/h2>\n<p>\u8981\u5728 Grafana \u4e2d\u4f7f\u7528 Loki\uff0c\u60a8\u9700\u8981\u5b89\u88c5 Grafana \u5e76\u6dfb\u52a0 Loki \u6570\u636e\u6e90\u3002\u4ee5\u4e0b\u662f\u8fde\u63a5\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee Grafana \u7684\u5730\u5740\uff08\u9ed8\u8ba4\u662f <code>http:\/\/localhost:3000<\/code>\uff09\u3002<\/li>\n<li>\u767b\u5f55 Grafana\uff08\u9ed8\u8ba4\u7528\u6237\u540d\u548c\u5bc6\u7801\u5747\u4e3a <code>admin<\/code>\uff09\u3002<\/li>\n<li>\u5728\u5de6\u4fa7\u83dc\u5355\u4e2d\u9009\u62e9 <strong>Configuration<\/strong> &gt; <strong>Data Sources<\/strong>\u3002<\/li>\n<li>\u70b9\u51fb <strong>Add data source<\/strong>\uff0c\u9009\u62e9 <strong>Loki<\/strong>\u3002<\/li>\n<li>\u5728 URL \u5b57\u6bb5\u4e2d\u8f93\u5165 <code>http:\/\/loki:3100<\/code>\uff0c\u7136\u540e\u70b9\u51fb <strong>Save &amp; Test<\/strong>\u3002<\/li>\n<\/ol>\n<h2 id=\"%e6%80%bb%e7%bb%93-oyhFZTvkpO\">\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u4f7f\u7528 Docker \u5b89\u88c5\u4e86 Grafana Loki\uff0c\u5e76\u5c06\u5176\u4e0e Grafana \u8fde\u63a5\u3002Grafana Loki \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u65e5\u5fd7\u7ba1\u7406\u529f\u80fd\uff0c\u9002\u5408\u7528\u4e8e\u76d1\u63a7\u548c\u5206\u6790\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u670d\u52a1\u5668\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7c73\u4e91\u63d0\u4f9b\u7684<a href=\"https:\/\/fwq.ai\">\u7f8e\u56fd\u4e91\u670d\u52a1\u5668<\/a>\uff0c\u4ee5\u6ee1\u8db3\u60a8\u7684\u4e1a\u52a1\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Docker\u5b89\u88c5Grafana Loki\u7684\u6559\u7a0b Grafana Loki \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u65e5\u5fd7\u805a\u5408\u7cfb\u7edf\uff0c\u65e8\u5728\u4e0e Grafana \u4e00\u8d77\u4f7f\u7528\uff0c\u63d0\u4f9b\u9ad8\u6548\u7684\u65e5\u5fd7\u7ba1\u7406\u548c\u67e5\u8be2\u529f\u80fd\u3002\u5b83\u7684\u8bbe\u8ba1\u7406\u5ff5\u662f\u4e0e Prometheus \u7c7b\u4f3c\uff0c\u4f46\u4e13\u6ce8\u4e8e\u65e5\u5fd7\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Docker \u5b89\u88c5 Grafana Loki\uff0c\u5e76\u8fdb\u884c\u57fa\u672c\u914d\u7f6e\u3002 \u524d\u63d0\u6761\u4ef6 \u786e\u4fdd\u5df2\u5b89\u88c5 Docker \u548c Docker Compose\u3002 \u5177\u5907\u57fa\u672c\u7684\u547d\u4ee4\u884c\u64cd\u4f5c\u80fd\u529b\u3002 \u6b65\u9aa4\u4e00\uff1a\u521b\u5efa\u9879\u76ee\u76ee\u5f55 \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\u6765\u5b58\u653e Loki \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u3002 mkdir loki-docker cd loki-docker \u6b65\u9aa4\u4e8c\uff1a\u521b\u5efa\u914d\u7f6e\u6587\u4ef6 \u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a loki-config.yaml \u7684\u914d\u7f6e\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u914d\u7f6e\u793a\u4f8b\uff1a cat &gt; loki-config.yaml &lt;&lt; EOF auth_enabled: false server: http_listen_port: 3100 ingester: wal: enabled: true dir: \/loki\/wal schema_config: configs: &#8211; from: 2020-10-24 store: boltdb-shipper [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-13807","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13807","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=13807"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13807\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=13807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=13807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=13807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}