正在加载

步骤 4:运行后端应用程序

Elastic Stack

下一步是运行后端应用程序。为此,请执行以下操作:

  1. 创建 API 密钥以验证后端应用程序的身份。
  2. LinuxKubernetes 上运行应用程序。

收集器和符号器都需要验证 Elasticsearch 的身份才能处理剖析数据。为此,您需要为每个应用程序创建一个 API 密钥。

请参阅创建 API 密钥以使用 Kibana 创建 API 密钥。选择一个 用户 API 密钥,并在 控制安全权限 下分配以下权限

{
  "profiling": {
    "cluster": [
      "monitor"
    ],
    "indices": [
      {
        "names": [
          "profiling-*"
        ],
        "privileges": [
          "read",
          "write"
        ]
      }
    ]
  }
}

存储 API 密钥的“编码”版本,因为您需要它们才能运行通用剖析后端。继续 在 Linux 上运行在 Kubernetes 上运行,以获取有关运行后端应用程序的信息。

在 Linux 上运行后端应用程序之前,我们建议创建 配置文件 以管理应用程序。也支持 CLI 标志,但它们可能会导致后端应用程序的管理更加复杂。

使用以下选项之一安装后端应用程序

  1. OS 软件包 (DEB/RPM)
  2. OCI 容器
  3. 二进制文件:使用您选择的配置管理系统(Ansible、Puppet、Chef、Salt 等)进行编排

配置文件采用 YAML 格式,由两个顶级部分组成:“application”部分和“output”部分。

“application”部分包含后端应用程序的配置,“output”部分包含连接到数据读取和发送位置的配置。“application”部分以二进制文件的名称命名。“output”部分目前仅支持 Elasticsearch。

配置文件从以下默认位置读取

  • 收集器:/etc/Elastic/universal-profiling/pf-elastic-collector.yml
  • 符号器:/etc/Elastic/universal-profiling/pf-elastic-symbolizer.yml

您可以使用运行应用程序时的 -c 标志自定义配置文件的位置。

为了简单起见,我们将在下面的示例中使用默认位置。我们还显示了默认的应用程序设置;您可以参考 YAML 中的注释来了解如何自定义它们。

将以下代码段的内容复制到 /etc/Elastic/universal-profiling/pf-elastic-collector.yml 文件中。

使用您选择的密钥令牌自定义 pf-elastic-collector.auth.secret_token 的内容。通用剖析代理将使用此令牌向收集器验证身份;您不能使用空字符串作为令牌。如果要使用 TLS 保护收集器的端点,请调整 ssl 部分。

使用 Elasticsearch 端点和 API 密钥 自定义 output.elasticsearch 部分的内容,以分别设置 hostsapi_key 值。根据需要调整 protocol 值和其他 TLS 相关设置。

将以下代码段的内容复制到 /etc/Elastic/universal-profiling/pf-elastic-symbolizer.yml 文件中。

您无需自定义 pf-elastic-symbolizer 部分中的任何值。如果要使用 TLS 保护符号器的端点,请调整 ssl 部分。

使用 Elasticsearch 端点和 API 密钥 自定义 output.elasticsearch 部分的内容,以分别设置 hostsapi_key 值。根据需要调整 protocol 值和其他 TLS 相关设置。

按照以下步骤使用 OS 软件包安装后端。

  1. 配置 APT 存储库

    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
    sudo apt-get install apt-transport-https
    echo "deb https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-9.x.list
    
  2. 安装软件包

    sudo apt update
    sudo apt install -y pf-elastic-collector pf-elastic-symbolizer
    

对于 RPM 软件包,配置 YUM 存储库并安装软件包

  1. 下载并安装公钥

    sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
    
  2. /etc/yum.repos.d/ 目录中创建一个带有 .repo 扩展名的文件(例如,elastic.repo),并添加以下行

    [elastic-9.x]
    name=Elastic repository for 9.x packages
    baseurl=https://artifacts.elastic.co/packages/9.x/yum
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=1
    autorefresh=1
    type=rpm-md
    
  3. 通过运行以下命令安装后端服务

    sudo yum update
    sudo yum install -y pf-elastic-collector pf-elastic-symbolizer
    

安装软件包后,启用并启动 systemd 服务

sudo systemctl enable pf-elastic-collector
sudo systemctl start pf-elastic-collector

sudo systemctl enable pf-elastic-symbolizer
sudo systemctl start pf-elastic-symbolizer

现在您可以检查服务的日志以发现任何问题

sudo journalctl -xu pf-elastic-collector
sudo journalctl -xu pf-elastic-symbolizer

有关排查日志中可能出现的错误的更多信息,请参阅排查通用剖析后端故障

我们在 Elastic 注册表中提供 OCI 镜像,以在容器中运行后端服务。这些镜像支持多平台,因此它们既可以在 x86_64 架构上运行,也可以在 ARM64 架构上运行。

在您的系统中放置配置文件后,您可以使用以下命令运行容器(示例命令使用 Docker,但任何 OCI 运行时都可以使用)

  1. 收集器

    docker run -d --name pf-elastic-collector -p 8260:8260 -v /etc/Elastic/universal-profiling/pf-elastic-collector.yml:/pf-elastic-collector.yml:ro \
      docker.elastic.co/observability/profiling-collector:{version} -c /pf-elastic-collector.yml
    
  2. 符号器

    docker run -d --name pf-elastic-symbolizer -p 8240:8240 -v /etc/Elastic/universal-profiling/pf-elastic-symbolizer.yml:/pf-elastic-symbolizer.yml:ro \
      docker.elastic.co/observability/profiling-symbolizer:{version} -c /pf-elastic-symbolizer.yml
    

使用上述命令,后端容器将在主机端口 8260 和 8240 上分别提供 HTTP 端点。我们提供了 -v 标志来将配置文件挂载到容器中,然后我们使用了 -c 标志来告诉应用程序从挂载的路径读取配置文件。

容器进程将在后台运行,您可以使用 docker logs <container_name> 检查日志,例如:

docker logs pf-elastic-collector
docker logs pf-elastic-symbolizer
  1. 下载并解压缩适用于您的平台的二进制文件

    对于 x86_64

    wget -O- "https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-collector-9.0.0-linux-x86_64.tar.gz" | tar xzf -
    wget -O- "https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-symbolizer-9.0.0-linux-x86_64.tar.gz" | tar xzf -
    

    对于 ARM64

    wget -O- "https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-collector-9.0.0-linux-arm64.tar.gz" | tar xzf -
    wget -O- "https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-symbolizer-9.0.0-linux-arm64.tar.gz" | tar xzf -
    
  2. pf-elastic-collectorpf-elastic-symbolizer 二进制文件复制到计算机的 PATH 中的目录。

  3. 运行后端应用程序进程,指示它们读取先前创建的配置文件。

    pf-elastic-collector -c /etc/Elastic/universal-profiling/pf-elastic-collector.yml
    pf-elastic-symbolizer -c /etc/Elastic/universal-profiling/pf-elastic-symbolizer.yml
    

如果要自定义传递给二进制文件的配置选项,可以使用命令行标志。所有替代项都使用 -E 标志指定。例如,如果要替代 pf-elastic-collector 应用程序的 host 值,可以使用 -E pf-elastic-collector.host 标志,如下所示

pf-elastic-collector -c /etc/Elastic/universal-profiling/pf-elastic-collector.yml -E pf-elastic-collector.host=0.0.0.0:8844

在前面的示例中,我们将收集器配置为在端口 8844 上的所有网络接口上侦听,而不是 YAML 配置文件中包含的 8260 值。

您可以使用 -E 标志覆盖配置文件中包含的任何值,只要您在命令行标志上指定完整的 YAML 路径即可。我们建议使用配置文件以简化编排。

相同的配置覆盖和建议也适用于 pf-elastic-symbolizer 二进制文件。

我们提供了 Helm 图表,用于在 Kubernetes 上部署后端服务。

要安装后端服务,您需要将 Elastic Helm 存储库添加到您的 Helm 安装中,然后安装图表。

我们建议创建一个 values.yaml 文件,定义图表的 Kubernetes 特定的选项。如果您想使用图表提供的默认值,则无需为每个图表创建一个 values.yaml 文件。对于应用程序的配置,您可以重用 “创建配置文件” 中详述的配置文件,并将它们作为值文件(使用 --values-f 标志)传递给 Helm,或将它们复制到 values.yaml 文件中。

在下面的示例中,我们不对 Kubernetes 配置应用任何修改,因此我们将使用图表提供的默认值。

  1. 安装和更新 Elastic Helm 注册表

    helm repo add elastic https://helm.elastic.co
    helm repo update elastic
    
  2. 安装图表(我们使用的是 universal-profiling 命名空间,但您可以随意自定义)

    helm install --create-namespace -n universal-profiling collector elastic/profiling-collector -f /etc/Elastic/universal-profiling/pf-elastic-collector.yml
    helm install --create-namespace -n universal-profiling symbolizer elastic/profiling-symbolizer -f /etc/Elastic/universal-profiling/pf-elastic-symbolizer.yml
    
  3. 按照 helm install 命令的输出中列出的步骤检查 Pod 是否正在运行并读取其日志。

注意

在前面的示例中,我们使用了图表的默认值来配置 Kubernetes 资源。这些包括创建 Ingress 资源。如果要将服务公开给 Kubernetes 集群外部的通用剖析代理和 symbtool 部署,则需要设置每个图表的 ingress 部分。

继续 步骤 5:后续步骤

© . All rights reserved.