Windows環境でのNew Relic Infrastructure Agent導入

はじめに

Windows環境でのNew Relic Infrastructure Agent導入は、MSIインストーラーやPowerShellを使用することで、効率的に実行できます。本記事では、Windows Server 2016以降、Windows 10/11での具体的なインストール手順を詳しく解説します。

企業環境での大規模展開やActiveDirectoryとの統合も考慮した設定方法を含め、実践的な導入アプローチを説明します。また、Windows特有の監視設定やトラブルシューティングについても併せて解説します。

事前準備

システム要件の確認

Infrastructure Agentを導入する前に、システムが以下の要件を満たしていることを確認してください。

対応OS

  • Windows Server 2016以降
  • Windows 10 version 1803以降
  • Windows 11全バージョン

ハードウェア要件

  • CPU: 1コア以上
  • メモリ: 1GB以上
  • ディスク容量: 100MB以上の空き容量
  • ネットワーク: HTTPS通信(443ポート)が可能

権限要件

  • 管理者権限でのインストール作業
  • サービス登録権限
  • レジストリ編集権限(一部設定で必要)

New Relicライセンスキーの準備

Windows環境での設定では、ライセンスキーを環境変数またはレジストリに設定します。事前にNew Relicダッシュボードからライセンスキーを取得しておきましょう。

セキュリティベストプラクティス

ライセンスキー管理の重要な注意点:

  • スクリプトや設定ファイルにライセンスキーを直接記載しない
  • 環境変数やSecure Stringを使用してキーを保護する
  • バージョン管理システムにキーをコミットしない
  • 定期的なキーのローテーションを検討する

MSIインストーラーによる導入

インストーラーのダウンロード

最新のMSIインストーラーは、New Relic公式サイトからダウンロードできます。

powershell
# PowerShellを使用したダウンロード
$downloadUrl = "https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi"
$outputPath = "$env:TEMP\newrelic-infra.msi"

Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath
Write-Host "Download completed: $outputPath"

サイレントインストール

企業環境での大規模展開では、サイレントインストールが効率的です。

powershell
# 管理者権限のPowerShellで実行
$msiPath = "$env:TEMP\newrelic-infra.msi"

# セキュリティベストプラクティス: 環境変数からライセンスキーを取得
$licenseKey = $env:NEW_RELIC_LICENSE_KEY
if (-not $licenseKey) {
    Write-Error "NEW_RELIC_LICENSE_KEY 環境変数が設定されていません"
    exit 1
}

# サイレントインストールの実行
$arguments = @(
    "/i", "`"$msiPath`"",
    "/quiet",
    "/norestart",
    "GENERATE_CONFIG=true",
    "LICENSE_KEY=$licenseKey"
)

Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -NoNewWindow
Write-Host "Installation completed"

GUI インストール

対話的なインストールを行う場合は、ダウンロードしたMSIファイルをダブルクリックして、ウィザードの指示に従って進めてください。

インストール中に、ライセンスキーの入力とサービス起動設定を行う画面が表示されます。

PowerShellスクリプトによる導入

一括導入スクリプト

PowerShellを使用した完全自動化されたインストールスクリプトを作成できます。

powershell
# New Relic Infrastructure Agent 一括導入スクリプト
param(
    [Parameter(Mandatory=$false)]
    [string]$LicenseKey,
    
    [Parameter(Mandatory=$false)]
    [string]$DisplayName = $env:COMPUTERNAME,
    
    [Parameter(Mandatory=$false)]
    [hashtable]$CustomAttributes = @{}
)

# セキュリティベストプラクティス: ライセンスキーの取得
if (-not $LicenseKey) {
    $LicenseKey = $env:NEW_RELIC_LICENSE_KEY
    if (-not $LicenseKey) {
        Write-Error "ライセンスキーが指定されていません。-LicenseKey パラメータまたは NEW_RELIC_LICENSE_KEY 環境変数を設定してください"
        exit 1
    }
}

# 管理者権限の確認
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Error "このスクリプトは管理者権限で実行してください"
    exit 1
}

# ダウンロードとインストール
try {
    Write-Host "New Relic Infrastructure Agent をダウンロード中..."
    $downloadUrl = "https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi"
    $installerPath = "$env:TEMP\newrelic-infra.msi"
    
    Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath
    
    Write-Host "インストール実行中..."
    $arguments = @(
        "/i", "`"$installerPath`"",
        "/quiet",
        "/norestart",
        "GENERATE_CONFIG=true",
        "LICENSE_KEY=$LicenseKey"
    )
    
    $process = Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -PassThru
    
    if ($process.ExitCode -eq 0) {
        Write-Host "インストールが正常に完了しました"
    } else {
        throw "インストールが失敗しました。終了コード: $($process.ExitCode)"
    }
    
    # 設定ファイルのカスタマイズ
    $configPath = "C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml"
    if (Test-Path $configPath) {
        $config = Get-Content $configPath -Raw
        $config += "`ndisplay_name: $DisplayName`n"
        
        if ($CustomAttributes.Count -gt 0) {
            $config += "custom_attributes:`n"
            foreach ($key in $CustomAttributes.Keys) {
                $config += "  $key`: $($CustomAttributes[$key])`n"
            }
        }
        
        Set-Content -Path $configPath -Value $config
        Write-Host "設定ファイルをカスタマイズしました"
    }
    
    # サービスの開始
    Write-Host "サービスを開始中..."
    Start-Service -Name "newrelic-infra"
    Set-Service -Name "newrelic-infra" -StartupType Automatic
    
    Write-Host "New Relic Infrastructure Agent の導入が完了しました"
    
} catch {
    Write-Error "エラーが発生しました: $($_.Exception.Message)"
    exit 1
} finally {
    # 一時ファイルの削除
    if (Test-Path $installerPath) {
        Remove-Item $installerPath -Force
    }
}

スクリプトの実行例

セキュリティベストプラクティス: 環境変数の設定

powershell
# 事前に環境変数を設定(セキュアな方法)
$env:NEW_RELIC_LICENSE_KEY = "your_license_key_here"

# または永続的な環境変数として設定
[Environment]::SetEnvironmentVariable("NEW_RELIC_LICENSE_KEY", "your_license_key_here", "Machine")

スクリプト実行例

powershell
# 環境変数を使用した基本的な実行
.\Install-NewRelicAgent.ps1

# カスタム属性付きで実行
$attributes = @{
    "environment" = "production"
    "team" = "backend"
    "location" = "tokyo"
}

.\Install-NewRelicAgent.ps1 -DisplayName "web-server-01" -CustomAttributes $attributes

# パラメータで直接指定する場合(非推奨)
# .\Install-NewRelicAgent.ps1 -LicenseKey "your_license_key_here"

設定ファイルの詳細設定

基本設定ファイル

Windowsでの設定ファイルは、以下の場所に配置されます。

C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml

基本的な設定例は以下のとおりです。

yaml
# ライセンスキー(必須)
license_key: YOUR_LICENSE_KEY

# 表示名の設定
display_name: production-web-01

# ログレベル設定
verbose: 1
log_level: info

# Windows固有設定
enable_win_services: true
enable_win_firewall: true

# カスタム属性
custom_attributes:
  environment: production
  team: backend
  os: windows
  datacenter: tokyo

# プロキシ設定(必要に応じて)
proxy: http://proxy.company.com:8080

# メトリクス収集間隔の調整
metrics_process_sample_rate: 20
metrics_storage_sample_rate: 20
metrics_network_sample_rate: 10

Windows サービス監視の有効化

特定のWindowsサービスを監視する場合の設定例です。

yaml
# Windowsサービス監視の設定
integrations:
  - name: nri-winservices
    config:
      exporter_bind_address: 127.0.0.1
      exporter_bind_port: 9182
      scrape_interval: 30s
      include_service_regex: ".*"
      exclude_service_regex: "^(RemoteRegistry|BITS)$"

ActiveDirectory環境での展開

グループポリシーによる配布

企業環境では、グループポリシーを使用してMSIパッケージを配布できます。

  1. ソフトウェア配布共有の準備
powershell
# 配布用共有フォルダの作成
New-Item -Path "\\fileserver\software\NewRelic" -ItemType Directory
Copy-Item "newrelic-infra.msi" "\\fileserver\software\NewRelic\"
  1. 変換ファイル(MST)の作成
powershell
# MSI変換ファイルの作成(ライセンスキーの事前設定)
# この作業は通常、Orcaなどのツールを使用して実行
  1. グループポリシーでの設定
  • グループポリシー管理コンソールを開く
  • 「コンピューターの構成」→「ソフトウェアの設定」→「ソフトウェアインストール」
  • 新しいパッケージとしてMSIファイルを追加

レジストリによる一括設定

レジストリを使用してライセンスキーを一括設定できます。

powershell
# セキュリティベストプラクティス: 環境変数からライセンスキーを取得
$licenseKey = $env:NEW_RELIC_LICENSE_KEY
if (-not $licenseKey) {
    Write-Error "NEW_RELIC_LICENSE_KEY 環境変数が設定されていません"
    exit 1
}

# レジストリキーの作成
$registryPath = "HKLM:\SOFTWARE\New Relic\newrelic-infra"
New-Item -Path $registryPath -Force

# ライセンスキーの設定
Set-ItemProperty -Path $registryPath -Name "license_key" -Value $licenseKey

# 表示名の設定
Set-ItemProperty -Path $registryPath -Name "display_name" -Value $env:COMPUTERNAME

Write-Host "レジストリ設定が完了しました"

監視と運用

サービス状態の確認

PowerShellを使用してInfrastructure Agentの状態を確認できます。

powershell
# サービス状態の確認
Get-Service -Name "newrelic-infra" | Format-Table Name, Status, StartType

# プロセス詳細の確認
Get-Process -Name "newrelic-infra" | Format-Table ProcessName, Id, CPU, WorkingSet

# ログファイルの確認
Get-Content "C:\Program Files\New Relic\newrelic-infra\logs\newrelic-infra.log" -Tail 20

パフォーマンス監視

エージェント自体のパフォーマンスを監視するためのスクリプトです。

powershell
# リソース使用量の監視
function Get-NewRelicAgentPerformance {
    $process = Get-Process -Name "newrelic-infra" -ErrorAction SilentlyContinue
    
    if ($process) {
        $cpuPercent = (Get-Counter "\Process(newrelic-infra*)\% Processor Time").CounterSamples.CookedValue
        $memoryMB = [math]::Round($process.WorkingSet64 / 1MB, 2)
        
        [PSCustomObject]@{
            ProcessName = $process.ProcessName
            CPU_Percent = [math]::Round($cpuPercent, 2)
            Memory_MB = $memoryMB
            Threads = $process.Threads.Count
            Status = "Running"
        }
    } else {
        [PSCustomObject]@{
            ProcessName = "newrelic-infra"
            Status = "Not Running"
        }
    }
}

# 実行例
Get-NewRelicAgentPerformance | Format-Table

トラブルシューティング

一般的な問題と解決方法

サービスが起動しない場合

powershell
# Windowsイベントログの確認
Get-WinEvent -LogName Application | Where-Object {$_.ProviderName -eq "newrelic-infra"} | Select-Object -First 10

# サービス依存関係の確認
sc.exe qc newrelic-infra

# 手動でのサービス起動テスト
& "C:\Program Files\New Relic\newrelic-infra\newrelic-infra.exe" -config "C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml"

ファイアウォール設定の確認

powershell
# HTTPS通信の確認
Test-NetConnection -ComputerName "infra-api.newrelic.com" -Port 443

# Windowsファイアウォールルールの確認
Get-NetFirewallRule -DisplayName "*New Relic*" | Format-Table DisplayName, Enabled, Direction

アンインストール手順

完全なアンインストールが必要な場合の手順です。

powershell
# サービスの停止
Stop-Service -Name "newrelic-infra" -Force

# MSIを使用したアンインストール
$uninstallArguments = @(
    "/x",
    "{F89C8C85-5A9F-4D4D-9C8E-F6F5B6C5A4E3}",  # Product Code
    "/quiet",
    "/norestart"
)

Start-Process -FilePath "msiexec.exe" -ArgumentList $uninstallArguments -Wait

# 残存ファイルの削除
Remove-Item "C:\Program Files\New Relic" -Recurse -Force -ErrorAction SilentlyContinue

# レジストリエントリの削除
Remove-Item "HKLM:\SOFTWARE\New Relic" -Recurse -Force -ErrorAction SilentlyContinue

セキュリティ考慮事項

ファイアウォール設定

Infrastructure Agentに必要なファイアウォール設定を適用します。

powershell
# New Relic用ファイアウォールルールの作成
New-NetFirewallRule -DisplayName "New Relic Infrastructure Agent" -Direction Outbound -Protocol TCP -RemotePort 443 -Action Allow

権限最小化

セキュリティ強化のため、最小限の権限で動作するように設定できます。

powershell
# 専用サービスアカウントの作成
$securePassword = ConvertTo-SecureString "ComplexPassword123!" -AsPlainText -Force
New-LocalUser -Name "NewRelicAgent" -Password $securePassword -Description "New Relic Infrastructure Agent Service Account"

# サービスログオン権限の付与
# この設定はローカルセキュリティポリシーまたはグループポリシーで実行

まとめ

Windows環境でのNew Relic Infrastructure Agent導入は、MSIインストーラーとPowerShellスクリプトを活用することで効率的に実行できます。企業環境では、ActiveDirectoryとの統合やグループポリシーによる一括展開により、運用負荷を大幅に軽減できます。

適切な設定とセキュリティ考慮により、安定したWindows環境の監視基盤を構築できるでしょう。次回は、Docker環境での導入方法について詳しく解説します。


関連記事: Linux環境でのエージェント導入関連記事: 設定ファイル完全リファレンス