菜单
开源

使用 Chef 安装 Grafana Alloy

你可以使用 Chef 安装和管理 Alloy。

开始之前

  • 这些步骤假设你已经有一个工作的 Chef 设置。
  • 你可以将以下资源添加到任何 recipe 中。
  • 这些任务从软件包仓库安装 Alloy。这些任务针对以下家族的 Linux 系统:
    • Debian,包括 Ubuntu
    • RedHat Enterprise Linux,包括 Fedora
    • Amazon Linux

步骤

将 Alloy 添加到主机

  1. 将以下资源添加到你的 Chef recipe 中,将 Grafana 软件包仓库添加到你的系统:

    ruby
    if platform_family?('debian', 'rhel', 'amazon', 'fedora')
      if platform_family?('debian')
        remote_file '/etc/apt/keyrings/grafana.gpg' do
          source 'https://apt.grafana.com/gpg.key'
          mode '0644'
          action :create
          end
    
        file '/etc/apt/sources.list.d/grafana.list' do
          content "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com/ stable main"
          mode '0644'
          notifies :update, 'apt_update[update apt cache]', :immediately
        end
    
        apt_update 'update apt cache' do
          action :nothing
        end
      elsif platform_family?('rhel', 'amazon', 'fedora')
        yum_repository 'grafana' do
          description 'grafana'
          baseurl 'https://rpm.grafana.com/oss/rpm'
          gpgcheck true
          gpgkey 'https://rpm.grafana.com/gpg.key'
          enabled true
          action :create
          notifies :run, 'execute[add-rhel-key]', :immediately
        end
    
        execute 'add-rhel-key' do
          command "rpm --import https://rpm.grafana.com/gpg.key"
          action :nothing
        end
      end
    else
        fail "The #{node['platform_family']} platform is not supported."
    end
  2. 添加以下资源来安装并启用 alloy 服务:

    ruby
    package 'alloy' do
      action :install
      flush_cache [ :before ] if platform_family?('amazon', 'rhel', 'fedora')
      notifies :restart, 'service[alloy]', :delayed
    end
    
    service 'alloy' do
      service_name 'alloy'
      action [:enable, :start]
    end

配置

alloy 软件包会安装一个默认配置文件,该文件不会向任何地方发送遥测数据。

默认配置文件的位置是 /etc/alloy/config.alloy。你可以用自己的配置替换此文件,或者为服务创建一个配置文件来使用。

下一步