istio.io/archive/v1.2/zh/blog/2018/export-logs-through-stackdr.../index.html

133 lines
32 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html><html lang=zh itemscope itemtype=https://schema.org/WebPage><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=theme-color content=#466BB0><meta name=title content="通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub"><meta name=description content="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。"><meta name=author content="Nupur Garg and Douglas Reid"><meta name=keywords content=microservices,services,mesh><meta property=og:title content="通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub"><meta property=og:type content=website><meta property=og:description content="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。"><meta property=og:url content=/v1.2/zh/blog/2018/export-logs-through-stackdriver/><meta property=og:image content=/v1.2/img/istio-whitelogo-bluebackground-framed.svg><meta property=og:image:alt content="Istio Logo"><meta property=og:image:width content=112><meta property=og:image:height content=150><meta property=og:site_name content=Istio><meta name=twitter:card content=summary><meta name=twitter:site content=@IstioMesh><title>Istioldie 1.2 / 通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</title><script async src="https://www.googletagmanager.com/gtag/js?id=UA-98480406-2"></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}
gtag('js',new Date());gtag('config','UA-98480406-2');</script><link rel=alternate type=application/rss+xml title="Istio Blog" href=/v1.2/feed.xml><link rel="shortcut icon" href=/v1.2/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.2/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.2/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.2/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.2/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.2/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.2/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.2/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.2/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.2/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.2/manifest.json><meta name=apple-mobile-web-app-title content=Istio><meta name=application-name content=Istio><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Work+Sans:400|Chivo:400|Work+Sans:500,300,600,300italic,400italic,500italic,600italic|Chivo:500,300,600,300italic,400italic,500italic,600italic"><link rel=stylesheet href=/v1.2/css/all.css><script src=/v1.2/js/themes_init.min.js></script></head><body class="language-unknown archive-site"><script>const branchName="release-1.2";const docTitle="通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub\/Sub";const iconFile="\/v1.2/img/icons.svg";const buttonCopy='复制到剪切板';const buttonPrint='打印';const buttonDownload='下载';</script><script src="https://www.google.com/cse/brand?form=search-form" defer></script><script src=/v1.2/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.2/zh/><span class=logo><svg viewBox="0 0 300 300"><circle cx="150" cy="150" r="146" stroke-width="2" /><path d="M65 240H225L125 270z"/><path d="M65 230l60-10V110z"/><path d="M135 220l90 10L135 30z"/></svg></span><span class=name>Istioldie 1.2</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.2/zh/docs/>文档</a>
<span title="关于使用 Istio 的博客文章。">博客</span>
<a title=关于Istio的常见问题。 href=/v1.2/zh/faq/>FAQ</a>
<a title=关于Istio的说明。 href=/v1.2/zh/about/>关于</a><div class=menu><button id=gearDropdownButton class=menu-trigger title=选项和设置 aria-label="Options and Settings" aria-controls=gearDropdownContent><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#gear"/></svg></button><div id=gearDropdownContent class=menu-content aria-labelledby=gearDropdownButton role=menu><a tabindex=-1 role=menuitem lang=en id=switch-lang-en>English</a>
<a tabindex=-1 role=menuitem lang=zh id=switch-lang-zh class=active>中文</a><div role=separator></div><a tabindex=-1 role=menuitem class=active id=light-theme-item>亮主题</a>
<a tabindex=-1 role=menuitem id=dark-theme-item>暗主题</a><div role=separator></div><a tabindex=-1 role=menuitem id=syntax-coloring-item>代码高亮</a><div role=separator></div><h6>本站的其它版本</h6><a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://istio.io/blog\/2018\/export-logs-through-stackdriver\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/blog\/2018\/export-logs-through-stackdriver\/');return false;">下个版本</a>
<a tabindex=-1 role=menuitem href=https://archive.istio.io>旧版本</a></div></div><button id=search-show title=搜索istio.io aria-label=Search><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#magnifier"/></svg></button></div><form id=search-form name=cse role=search><input type=hidden name=cx value=013699703217164175118:iwwf17ikgf4>
<input type=hidden name=ie value=utf-8>
<input type=hidden name=hl value=en>
<input type=hidden id=search-page-url value=/v1.2/search.html>
<input id=search-textbox class=form-control name=q type=search aria-label=搜索istio.io>
<button id=search-close title="Cancel search" type=reset aria-label="Cancel search"><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#cancel-x"/></svg></button></form></nav></header><main class=primary><div id=sidebar-container class="sidebar-container sidebar-offcanvas"><nav id=sidebar aria-label="Section Navigation"><div class=directory><div class=card><button class="header dynamic" id=card0 title="2019 年的博客文章。" aria-controls=card0-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2019 年的博客文章</button><div class=body aria-labelledby=card0 role=region id=card0-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card0><li role=none><a role=treeitem title="Istio 1.1.3。" href=/v1.2/zh/blog/2019/announcing-1.1.3/>安全更新:发布 Istio 1.1.3</a></li><li role=none><a role=treeitem title="Istio 1.0.7 的补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.0.7/>安全更新:发布 Istio 1.0.7</a></li><li role=none><a role=treeitem title="Istio 1.1.2 的补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.1.2/>安全更新:发布 Istio 1.1.2</a></li><li role=none><a role=treeitem title="Istio 1.1 发布声明。" href=/v1.2/zh/blog/2019/announcing-1.1/>宣布 Istio 1.1 发布</a></li><li role=none><a role=treeitem title="Istio 1.1 性能概览." href=/v1.2/zh/blog/2019/istio1.1_perf/>面向性能而架构的 Istio 1.1</a></li><li role=none><a role=treeitem title="Istio 1.0.6 补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.0.6/>Istio 1.0.6 发布</a></li><li role=none><a role=treeitem title="在多集群服务网格环境中配置 Istio 的路由规则。" href=/v1.2/zh/blog/2019/multicluster-version-routing/>多集群服务网格中的分版本路由</a></li><li role=none><a role=treeitem title=宣布新的博客策略。 href=/v1.2/zh/blog/2019/sail-the-blog/>博客策略更新</a></li><li role=none><a role=treeitem title="评估加入 Egress gateway 对性能造成的影响。" href=/v1.2/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></li><li role=none><a role=treeitem title="Istio 将数据面组件注入到现存部署之中的过程。" href=/v1.2/zh/blog/2019/data-plane-setup/>Istio Sidecar 注入过程解密</a></li><li role=none><a role=treeitem title="使用 AppSwitch 解决应用程序启动顺序和启动延迟。" href=/v1.2/zh/blog/2019/appswitch/>使用 AppSwitch 进行 Sidestepping 依赖性排序</a></li><li role=none><a role=treeitem title="如何使用 cert-manager 手工部署一个自定义 Ingress 网关。" href=/v1.2/zh/blog/2019/custom-ingress-gateway/>使用 Cert-Manager 部署一个自定义 Ingress 网关</a></li><li role=none><a role=treeitem title="Istio 推出新的讨论板。" href=/v1.2/zh/blog/2019/announcing-discuss.istio.io/>宣布 discuss.istio.io</a></li></ul></div></div><div class=card><button class="header dynamic" id=card1 title="2017 年的博客文章。" aria-controls=card1-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2017 年的博客文章</button><div class=body aria-labelledby=card1 role=region id=card1-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card1><li role=none><a role=treeitem title=提高可用,降低延迟。 href=/v1.2/zh/blog/2017/mixer-spof-myth/>Mixer 和 SPOF 神话</a></li><li role=none><a role=treeitem title="概要说明 Mixer 的插件架构。" href=/v1.2/zh/blog/2017/adapter-model/>Mixer 适配器模型</a></li><li role=none><a role=treeitem title="Istio 0.2 公告。" href=/v1.2/zh/blog/2017/0.2-announcement/>宣布 Istio 0.2</a></li><li role=none><a role=treeitem title="Istio 的策略如何关联 Kubernetes 的网络策略 。" href=/v1.2/zh/blog/2017/0.1-using-network-policy/>Istio 使用网络策略</a></li><li role=none><a role=treeitem title="使用 Istio 创建自动缩放的金丝雀部署。" href=/v1.2/zh/blog/2017/0.1-canary/>使用 Istio 进行金丝雀部署</a></li><li role=none><a role=treeitem title="Istio Auth 0.1 公告。" href=/v1.2/zh/blog/2017/0.1-auth/>使用 Istio 增强端到端安全</a></li><li role=none><a role=treeitem title="Istio 0.1 宣布。" href=/v1.2/zh/blog/2017/0.1-announcement/>初次了解 Istio</a></li></ul></div></div><div class=card><button class="header dynamic" id=card2 title="2018 年的博客文章。" aria-controls=card2-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2018 年的博客文章</button><div class="body default" aria-labelledby=card2 role=region id=card2-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card2><li role=none><a role=treeitem title="Istio 1.0.5 补丁版本发布。" href=/v1.2/zh/blog/2018/announcing-1.0.5/>Istio 1.0.5 发布</a></li><li role=none><a role=treeitem title="Istio 1.0.4 补丁版本发布。" href=/v1.2/zh/blog/2018/announcing-1.0.4/>Istio 1.0.4 发布</a></li><li role=none><a role=treeitem title="如何在不部署 Sidecar 代理的情况下使用 Istio 进行流量管理。" href=/v1.2/zh/blog/2018/incremental-traffic-management/>增量式应用 Istio 第一部分,流量管理</a></li><li role=none><a role=treeitem title="描述了一个基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></li><li role=none><a role=treeitem title="Istio 1.0.3 修补版本。" href=/v1.2/zh/blog/2018/announcing-1.0.3/>宣布 Istio 1.0.3</a></li><li role=none><a role=treeitem title="Istio 1.0.2 补丁版本." href=/v1.2/zh/blog/2018/announcing-1.0.2/>Istio 1.0.2 发布</a></li><li role=none><a role=treeitem title="Istio 1.0.1 补丁版本。" href=/v1.2/zh/blog/2018/announcing-1.0.1/>Istio 1.0.1 发布</a></li><li role=none><a role=treeitem title="Istio 在 Twitch 举办了为期一天的直播庆祝 1.0 的发布。" href=/v1.2/zh/blog/2018/istio-twitch-stream/>Istio 在 Twitch 上全天直播</a></li><li role=none><a role=treeitem title="惠普如何在 Istio 上构建其下一代鞋类个性化平台。" href=/v1.2/zh/blog/2018/hp/>Istio 是惠普 FitStation 平台的改变者</a></li><li role=none><a role=treeitem title="Istio 1.0 已生产就绪。" href=/v1.2/zh/blog/2018/announcing-1.0/>宣布 Istio 1.0</a></li><li role=none><a role=treeitem title="使用 AppSwitch 自动接入应用并降低延迟。" href=/v1.2/zh/blog/2018/delayering-istio/>使用 AppSwitch 精简 Istio 层次</a></li><li role=none><a role=treeitem title="描述 Istio 的授权功能以及如何在各种用例中使用它。" href=/v1.2/zh/blog/2018/istio-authorization/>基于 Istio 的 Micro-Segmentation 授权</a></li><li role=none><span role=treeitem class=current title="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。">通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</span></li><li role=none><a role=treeitem title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。" href=/v1.2/zh/blog/2018/egress-monitoring-access-control/>HTTP Egress 流量监控和访问策略</a></li><li role=none><a role=treeitem title="Istio v1alpha3 路由 API 介绍,动机及其设计原则。" href=/v1.2/zh/blog/2018/v1alpha3-routing/>Istio v1aplha3 路由 API 介绍</a></li><li role=none><a role=treeitem title="描述如何在AWS上使用网络负载均衡器配置 Istio Ingress。" href=/v1.2/zh/blog/2018/aws-nlb/>使用AWS NLB 配置 Istio Ingress</a></li><li role=none><a role=treeitem title="使用 Kubernetes 命名空间和 RBAC 为 Istio 构建软性多租户环境。" href=/v1.2/zh/blog/2018/soft-multitenancy/>Istio 的软性多租户支持</a></li><li role=none><a role=treeitem title=介绍更安全,低风险的部署和发布到生产。 href=/v1.2/zh/blog/2018/traffic-mirroring/>用于在生产环境进行测试的 Istio 流量镜像功能</a></li><li role=none><a role=treeitem title="描述基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-tcp/>使用外部 TCP 服务</a></li><li role=none><a role=treeitem title="描述基于 Istio Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-https/>使用外部 Web 服务</a></li></ul></div></div></div></nav></div><div class=article-container><button tabindex=-1 id=sidebar-toggler title=折叠导航栏><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.2/zh/>Istio</a></li><li><a href=/v1.2/zh/blog/ title="关于使用 Istio 的博客文章。">博客</a></li><li><a href=/v1.2/zh/blog/2018/ title="2018 年的博客文章。">2018 年的博客文章</a></li><li>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</h1><p class=byline><span>作者</span>
<span class=attribution>Nupur Garg and Douglas Reid</span><span> | </span><span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#calendar"/></svg><span>&nbsp;</span>2018年7月9日</span><span> | </span><span title="485 字"><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#clock"/></svg><span>&nbsp;</span>阅读大约需要 3 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=开始前><a href=#%e5%bc%80%e5%a7%8b%e5%89%8d>开始前</a><li role=none aria-label="配置 Istio 导出日志"><a href=#%e9%85%8d%e7%bd%ae-istio-%e5%af%bc%e5%87%ba%e6%97%a5%e5%bf%97>配置 Istio 导出日志</a><ol><li role=none aria-label=设置各种日志接收器><a href=#%e8%ae%be%e7%bd%ae%e5%90%84%e7%a7%8d%e6%97%a5%e5%bf%97%e6%8e%a5%e6%94%b6%e5%99%a8>设置各种日志接收器</a><ol><li role=none aria-label=BigQuery><a href=#bigquery>BigQuery</a><li role=none aria-label="Google Cloud Storage (GCS)"><a href=#google-cloud-storage-gcs>Google Cloud Storage (GCS)</a><li role=none aria-label="Google Cloud Pub/Sub"><a href=#google-cloud-pub-sub>Google Cloud Pub/Sub</a></ol></li><li role=none aria-label="设置 Stackdriver"><a href=#%e8%ae%be%e7%bd%ae-stackdriver>设置 Stackdriver</a></ol></li><li role=none aria-label=了解发生了什么><a href=#%e4%ba%86%e8%a7%a3%e5%8f%91%e7%94%9f%e4%ba%86%e4%bb%80%e4%b9%88>了解发生了什么</a><li role=none aria-label=清理><a href=#%e6%b8%85%e7%90%86>清理</a><li role=none aria-label=日志导出的可用性><a href=#%e6%97%a5%e5%bf%97%e5%af%bc%e5%87%ba%e7%9a%84%e5%8f%af%e7%94%a8%e6%80%a7>日志导出的可用性</a></ol><hr></div></nav><p>这篇文章展示了如何将 Istio 日志指向 <a href=https://cloud.google.com/stackdriver/><code>Stackdriver</code></a> 并将这些日志导出到各种配置的接收器,例如 <a href=https://cloud.google.com/bigquery/><code>BigQuery</code></a><a href=https://cloud.google.com/storage/><code>Google Cloud Storage(GCS)</code></a><a href=https://cloud.google.com/pubsub/><code>Cloud Pub/Sub</code></a>。在这篇文章的最后,可以从喜欢的地方(如 BigQuery、GCS 或 Cloud Pub/Sub对 Istio 数据进行分析。</p><p><a href=/v1.2/zh/docs/examples/bookinfo/><code>Bookinfo</code></a> 示例应用程序在整个任务中用作示例应用程序。</p><h2 id=开始前>开始前</h2><p>在集群中<a href=/v1.2/zh/docs/setup/><code>安装 Istio</code></a> 并部署应用程序。</p><h2 id=配置-istio-导出日志>配置 Istio 导出日志</h2><p>Istio 使用 <code>logentry</code> <a href=/v1.2/docs/reference/config/policy-and-telemetry/templates/logentry><code>模板</code></a>导出日志。这里指定了可用于分析的所有变量。它包含源服务、目标服务、<code>auth</code> 指标(即将实现&hellip;&hellip;)等信息。以下是示意图:</p><figure style=width:75%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:75%><a data-skipendnotes=true href=/v1.2/blog/2018/export-logs-through-stackdriver/istio-analytics-using-stackdriver.png title="导出日志到 Stackdriver 进行分析的图释"><img class=element-to-stretch src=/v1.2/blog/2018/export-logs-through-stackdriver/istio-analytics-using-stackdriver.png alt="导出日志到 Stackdriver 进行分析的图释"></a></div><figcaption>导出日志到 Stackdriver 进行分析的图释</figcaption></figure><p>Istio 支持将日志导出到 Stackdriver而 Stackdriver 又可以配置为将日志导出到喜欢的接收器,如 BigQuery、Pub/Sub 或 GCS。请按照以下步骤设置喜欢的接收器首先导出日志然后在 Istio 中使用 Stackdriver。</p><h3 id=设置各种日志接收器>设置各种日志接收器</h3><p>所有接收器的通用设置:</p><ol><li>为项目启动 <a href=https://cloud.google.com/monitoring/api/enable-api><code>Stackdriver Monitoring API</code></a></li><li>确保配置的接收器的 <code>principalEmail</code> 具有对项目写入权限和日志管理员角色的权限。</li><li>确保已设置 <code>GOOGLE_APPLICATION_CREDENTIALS</code> 环境变量。请按照<a href=https://cloud.google.com/docs/authentication/getting-started><code>此处</code></a>的说明进行设置。</li></ol><h4 id=bigquery>BigQuery</h4><ol><li><a href=https://cloud.google.com/bigquery/docs/datasets><code>创建 BigQuery 数据集</code></a>作为日志导出的目标。</li><li>记录数据集的 ID。 这里需要设置 Stackdriver 处理程序。它的格式为 <code>bigquery.googleapis.com/projects/[PROJECT_ID]/datasets/[DATASET_ID]</code></li><li><a href=https://cloud.google.com/logging/docs/api/tasks/exporting-logs#writing_to_the_destination><code>接收器授权</code></a>cloud-logs@system.gserviceaccount.com。它具有 IAM 中的 BigQuery Data Editor 的角色。</li><li>如果使用 <a href=/v1.2/zh/docs/setup/kubernetes/prepare/platform-setup/gke/><code>Google Kubernetes Engine</code></a>,请确保在集群上启用了 <code>bigquery</code> <a href=https://cloud.google.com/sdk/gcloud/reference/container/clusters/create><code>Scope</code></a></li></ol><h4 id=google-cloud-storage-gcs>Google Cloud Storage (GCS)</h4><ol><li><a href=https://cloud.google.com/storage/docs/creating-buckets><code>创建 GCS 存储桶</code></a>,希望导出日志到 GCS 中。</li><li>记录存储桶的 ID。这里需要配置 Stackdriver。它的形式为 <code>storage.googleapis.com/[BUCKET_ID]</code></li><li><a href=https://cloud.google.com/logging/docs/api/tasks/exporting-logs#writing_to_the_destination><code>接收器授权</code></a><code>cloud-logs @ system.gserviceaccount.com</code>。它具有 IAM 中的 Storage Object Creator 的角色。</li></ol><h4 id=google-cloud-pub-sub>Google Cloud Pub/Sub</h4><ol><li><a href=https://cloud.google.com/pubsub/docs/admin><code>创建主题</code></a>希望导出日志到Google Cloud Pub/Sub 中。</li><li>记录主题的 ID。这里需要配置 Stackdriver。它的形式为<code>pubsub.googleapis.com/projects/[PROJECT_ID]/topics/[TOPIC_ID]</code></li><li><a href=https://cloud.google.com/logging/docs/api/tasks/exporting-logs#writing_to_the_destination><code>接收器授权</code></a><code>cloud-logs @ system.gserviceaccount.com</code>。它具有 IAM 中的 Pub/Sub Publisher 角色。</li><li>如果使用 <a href=/v1.2/zh/docs/setup/kubernetes/prepare/platform-setup/gke/><code>Google Kubernetes Engine</code></a>,请确保在集群中启动了 <code>pubsub</code> <a href=https://cloud.google.com/sdk/gcloud/reference/container/clusters/create><code>Scope</code></a></li></ol><h3 id=设置-stackdriver>设置 Stackdriver</h3><p>必须创建 Stackdriver 处理程序,将数据导出到 Stackdriver。Stackdriver 处理程序的配置在<a href=/v1.2/docs/reference/config/policy-and-telemetry/adapters/stackdriver/><code>此处</code></a>描述。</p><ol><li><p>保存如下的yaml文件为 <code>stackdriver.yaml</code> 。并替换 <code>&lt;project_id&gt;,
&lt;sink_id&gt;, &lt;sink_destination&gt;, &lt;log_filter&gt;</code> 为相应的值。</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: &#34;config.istio.io/v1alpha2&#34;
kind: stackdriver
metadata:
name: handler
namespace: istio-system
spec:
# 设置 pushInterval 值。默认值是每分钟一次,不设置使用默认值。
# pushInterval: 1m
# 必须设置 Stacldriver 适配器 project_id 的值。
project_id: &#34;&lt;project_id&gt;&#34;
# apiCredentials 和 apiKey 必须设置之一; 首选方法是`appCredentials`,它对应于 Google 应用程序默认凭据。
# 如果没有提供,我们使用默认应用凭据。
# appCredentials:
# apiKey:
# serviceAccountPath:
# 描述如何将 Istio 日志映射到 Stackdriver。
logInfo:
accesslog.logentry.istio-system:
payloadTemplate: &#39;{{or (.sourceIp) &#34;-&#34;}} - {{or (.sourceUser) &#34;-&#34;}} [{{or (.timestamp.Format &#34;02/Jan/2006:15:04:05 -0700&#34;) &#34;-&#34;}}] &#34;{{or (.method) &#34;-&#34;}} {{or (.url) &#34;-&#34;}} {{or (.protocol) &#34;-&#34;}}&#34; {{or (.responseCode) &#34;-&#34;}} {{or (.responseSize) &#34;-&#34;}}&#39;
httpMapping:
url: url
status: responseCode
requestSize: requestSize
responseSize: responseSize
latency: latency
localIp: sourceIp
remoteIp: destinationIp
method: method
userAgent: userAgent
referer: referer
labelNames:
- sourceIp
- destinationIp
- sourceService
- sourceUser
- sourceNamespace
- destinationIp
- destinationService
- destinationNamespace
- apiClaims
- apiKey
- protocol
- method
- url
- responseCode
- responseSize
- requestSize
- latency
- connectionMtls
- userAgent
- responseTimestamp
- receivedBytes
- sentBytes
- referer
sinkInfo:
id: &#39;&lt;sink_id&gt;&#39;
destination: &#39;&lt;sink_destination&gt;&#39;
filter: &#39;&lt;log_filter&gt;&#39;
---
apiVersion: &#34;config.istio.io/v1alpha2&#34;
kind: rule
metadata:
name: stackdriver
namespace: istio-system
spec:
match: &#34;true&#34; # 缺省 match 为 true
actions:
- handler: handler.stackdriver
instances:
- accesslog.logentry
---
</code></pre></li><li><p>创建配置</p><pre><code class=language-bash data-expandlinks=true>$ kubectl apply -f stackdriver.yaml
stackdriver &#34;handler&#34; created
rule &#34;stackdriver&#34; created
logentry &#34;stackdriverglobalmr&#34; created
metric &#34;stackdriverrequestcount&#34; created
metric &#34;stackdriverrequestduration&#34; created
metric &#34;stackdriverrequestsize&#34; created
metric &#34;stackdriverresponsesize&#34; created
</code></pre></li><li><p>访问示例应用程序。
对于 <code>Bookinfo</code> 示例,请使用浏览器访问 <code>http://$GATEWAY_URL/productpage</code> 或发出以下命令:</p><pre><code class=language-bash data-expandlinks=true>$ curl http://$GATEWAY_URL/productpage
</code></pre></li><li><p>验证日志是否正在通过 Stackdriver 流向配置的接收器。</p></li></ol><ul><li>Stackdriver导航到项目的 <a href=https://pantheon.corp.google.com/logs/viewer><code>Stackdriver Logs Viewer</code></a>,查看 “GKE Container” -&gt; “Cluster Name” -&gt; “Namespace Id” , 查看 Istio 访问日志。</li><li>BigQuery导航到项目的 <a href=https://bigquery.cloud.google.com/><code>BigQuery Interface</code></a>,在接收器的数据集中找到一个前缀为 <code>accesslog_logentry_istio</code> 的表。</li><li>GCS导航到项目的 <a href=https://pantheon.corp.google.com/storage/browser/><code>Storage Brower</code></a>,在接收器的桶中找到一个名为 <code>accesslog.logentry.istio-system</code> 的桶。</li><li>Pub/Sub导航到项目的 <a href=https://pantheon.corp.google.com/cloudpubsub/topicList><code>Pub/Sub 主题列表</code></a>, 在接收器的主题中找到 <code>accesslog</code> 主题。</li></ul><h2 id=了解发生了什么>了解发生了什么</h2><p>上面的 <code>Stackdriver.yaml</code> 文件配置了 Istio 将访问日志发送到 Stackdriver然后添加了一个接收器配置将日志导出。具体如下</p><ol><li><p>添加一个 <code>stackdriver</code> 类型的处理程序:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: &#34;config.istio.io/v1alpha2&#34;
kind: stackdriver
metadata:
name: handler
namespace: &lt;your defined namespace&gt;
</code></pre></li><li><p><code>spec</code> 上增加 <code>logInfo</code></p><pre><code class=language-yaml data-expandlinks=true>spec:
logInfo: accesslog.logentry.istio-system:
labelNames:
- sourceIp
- destinationIp
...
...
sinkInfo:
id: &#39;&lt;sink_id&gt;&#39;
destination: &#39;&lt;sink_destination&gt;&#39;
filter: &#39;&lt;log_filter&gt;&#39;
</code></pre></li></ol><p>在上面的配置中sinkInfo 包含有关日志导出到所需接收器的信息。有关如何填写不同接收器的更多信息,请参阅<a href=https://cloud.google.com/logging/docs/export/#sink-terms><code>此处</code></a>
 
1. 为 Stackdriver 添加规则</p><pre><code><pre><code class=language-yaml data-expandlinks=true>apiVersion: &#34;config.istio.io/v1alpha2&#34;
kind: rule
metadata:
name: stackdriver
namespace: istio-system spec:
match: &#34;true&#34; # 缺省 match 为 true
actions:
- handler: handler.stackdriver
instances:
- accesslog.logentry
</code></pre></code></pre><h2 id=清理>清理</h2><ul><li><p>删除新的 Stackdriver 配置:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl delete -f stackdriver.yaml
</code></pre></li><li><p>如果不打算任何后续任务,请参阅 <a href=/v1.2/zh/docs/examples/bookinfo/#清理><code>Bookinfo cleanup</code></a> 指令关闭应用程序。</p></li></ul><h2 id=日志导出的可用性>日志导出的可用性</h2><p>导出到 BigQuery 只需几分钟可以认为几乎是瞬间的GCS 要延迟 2 至 12 小时Pub/Sub 几乎立即的。</p></article><nav class=pagenav><div class=left><a title="描述 Istio 的授权功能以及如何在各种用例中使用它。" href=/v1.2/zh/blog/2018/istio-authorization/><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#left-arrow"/></svg>基于 Istio 的 Micro-Segmentation 授权</a></div><div class=right><a title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。" href=/v1.2/zh/blog/2018/egress-monitoring-access-control/>HTTP Egress 流量监控和访问策略<svg class="icon"><use xlink:href="/v1.2/img/icons.svg#right-arrow"/></svg></a></div></nav><div id=endnotes-container aria-hidden=true><h2>链接</h2><ol id=endnotes></ol></div></div><div class=toc-container><nav class=toc aria-label="Table of Contents"><div id=toc><ol><li role=none aria-label=开始前><a href=#%e5%bc%80%e5%a7%8b%e5%89%8d>开始前</a><li role=none aria-label="配置 Istio 导出日志"><a href=#%e9%85%8d%e7%bd%ae-istio-%e5%af%bc%e5%87%ba%e6%97%a5%e5%bf%97>配置 Istio 导出日志</a><ol><li role=none aria-label=设置各种日志接收器><a href=#%e8%ae%be%e7%bd%ae%e5%90%84%e7%a7%8d%e6%97%a5%e5%bf%97%e6%8e%a5%e6%94%b6%e5%99%a8>设置各种日志接收器</a><ol><li role=none aria-label=BigQuery><a href=#bigquery>BigQuery</a><li role=none aria-label="Google Cloud Storage (GCS)"><a href=#google-cloud-storage-gcs>Google Cloud Storage (GCS)</a><li role=none aria-label="Google Cloud Pub/Sub"><a href=#google-cloud-pub-sub>Google Cloud Pub/Sub</a></ol></li><li role=none aria-label="设置 Stackdriver"><a href=#%e8%ae%be%e7%bd%ae-stackdriver>设置 Stackdriver</a></ol></li><li role=none aria-label=了解发生了什么><a href=#%e4%ba%86%e8%a7%a3%e5%8f%91%e7%94%9f%e4%ba%86%e4%bb%80%e4%b9%88>了解发生了什么</a><li role=none aria-label=清理><a href=#%e6%b8%85%e7%90%86>清理</a><li role=none aria-label=日志导出的可用性><a href=#%e6%97%a5%e5%bf%97%e5%af%bc%e5%87%ba%e7%9a%84%e5%8f%af%e7%94%a8%e6%80%a7>日志导出的可用性</a></ol></div></nav></div></main><footer><div class=user-links><a class=channel title="Go download Istio 1.2.5 now" href=https://github.com/istio/istio/releases/tag/1.2.5 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#download"/></svg>
</a><a class=channel title="加入 Istio discussion board 参与讨论获取帮助" href=https://discuss.istio.io aria-label="Istio discussion board"><span>discuss</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#discourse"/></svg></a>
<a class=channel title="Stack Overflow 中列举了针对实际问题以及部署、配置和使用 Istio 的各项回答" href=https://stackoverflow.com/questions/tagged/istio aria-label="Stack Overflow"><span>stack overflow</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#stackoverflow"/></svg></a>
<a class=channel title="在 Slack 上与 Istio 社区交互讨论开发问题(仅限邀请)" href=https://istio.slack.com aria-label=slack><span>slack</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#slack"/></svg></a>
<a class=channel title="关注我们的 Twitter 来获取最新信息" href=https://twitter.com/IstioMesh aria-label=Twitter><span>twitter</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
1.2.5<br>&copy; 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年9月12日</p></div><div class=dev-links><a class=channel title="Istio 的代码在 GitHub 上开发" href=https://github.com/istio/community aria-label=GitHub><span>github</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#github"/></svg></a>
<a class=channel title="如果您想深入了解 Istio 的技术细节,请查看我们日益完善的设计文档" href=https://groups.google.com/forum/#!forum/istio-team-drive-access aria-label="team drive"><span>drive</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#drive"/></svg></a>
<a class=channel title="如果您想为 Istio 项目做出贡献,请考虑加入我们的工作组" href=https://github.com/istio/community/blob/master/WORKING-GROUPS.md aria-label="working groups"><span>working groups</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#working-groups"/></svg></a><div class=tag>对于开发者</div></div></footer><div id=scroll-to-top-container aria-hidden=true><button id=scroll-to-top title=回到顶部><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#top"/></svg></button></div></body></html>