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スクリプトでWindows Credential Managerを使用する場合、以下の準備が必要です:

📦 必要なモジュール(オプション) ​

powershell
# Windows Credential Managerを使用する場合(推奨)
Install-Module -Name CredentialManager -Force -Scope CurrentUser

# PowerShell 7+ で SecretManagement を使用する場合
Install-Module -Name Microsoft.PowerShell.SecretManagement -Force

🔒 ライセンスキー管理の方法(優先順位) ​

方法設定の簡単さセキュリティ企業環境適用性
環境変数⭐⭐⭐⭐⭐⭐⭐⭐
Credential Manager⭐⭐⭐⭐⭐⭐⭐⭐
SecretManagement⭐⭐⭐⭐⭐⭐

💡 推奨: 最初は環境変数から始めて、セキュリティ要件に応じてCredential Managerに移行

一括導入スクリプト(基本版) ​

PowerShellを使用した基本的な導入スクリプトです。以下は環境変数からライセンスキーを取得する最小構成です:

powershell
# 管理者権限で実行してください
$licenseKey = $env:NEW_RELIC_LICENSE_KEY
if (-not $licenseKey) {
    Write-Error "NEW_RELIC_LICENSE_KEY 環境変数が設定されていません"
    exit 1
}

$msiPath = "$env:TEMP\newrelic-infra.msi"
Invoke-WebRequest -Uri "https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi" -OutFile $msiPath

$arguments = @("/i", "`"$msiPath`"", "/quiet", "/norestart", "GENERATE_CONFIG=true", "LICENSE_KEY=$licenseKey")
$process = Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -PassThru

if ($process.ExitCode -eq 0) {
    Start-Service -Name "newrelic-infra"
    Write-Host "インストールが完了しました"
}

より詳細なスクリプト(Credential Manager連携、DPAPI暗号化対応等)は、GitHub上の完全版スクリプトを参照してください。

スクリプトの実行例 ​

環境変数からライセンスキーを取得して実行する方法:

powershell
# 事前に環境変数を設定
[Environment]::SetEnvironmentVariable("NEW_RELIC_LICENSE_KEY", "your-license-key", "Machine")

# PowerShellスクリプトを実行(管理者権限必須)
.\install-agent.ps1

設定ファイルの詳細設定 ​

基本設定ファイル ​

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. 配布用共有フォルダにMSIファイルを配置
  2. グループポリシー管理コンソールを開く
  3. 「コンピューターの構成」→「ソフトウェアの設定」→「ソフトウェアインストール」
  4. 新しいパッケージとしてMSIファイルを追加
powershell
# 配布用共有フォルダの作成例
New-Item -Path "\\fileserver\software\NewRelic" -ItemType Directory
Copy-Item "newrelic-infra.msi" "\\fileserver\software\NewRelic\"

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

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

powershell
# 基本的なレジストリ設定
$registryPath = "HKLM:\SOFTWARE\New Relic\newrelic-infra"
New-Item -Path $registryPath -Force

# ライセンスキーと表示名の設定
Set-ItemProperty -Path $registryPath -Name "license_key" -Value "YOUR_LICENSE_KEY"
Set-ItemProperty -Path $registryPath -Name "display_name" -Value $env:COMPUTERNAME

⚠️ セキュリティ注意: 本番環境では環境変数やCredential Managerからライセンスキーを取得することを推奨します。

監視と運用 ​

サービス状態の確認 ​

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環境の監視基盤を構築できるでしょう。

次のステップ - 高度な監視設定 ​

基本的なエージェント導入が完了したら、以下の特殊監視機能の設定をご検討ください:


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