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を使用したダウンロード
$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で実行
$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を使用する場合、以下の準備が必要です:
📦 必要なモジュール(オプション)
# 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を使用したシンプルな一括導入スクリプトです。
# New Relic Infrastructure Agent 基本導入スクリプト
param(
[Parameter(Mandatory=$true)]
[string]$LicenseKey,
[string]$DisplayName = $env:COMPUTERNAME
)
# セキュリティベストプラクティス: 複数の安全な方法でライセンスキーを取得
function Get-SecureCredential {
param([string]$Target = "NewRelic/LicenseKey")
# 方法1: Windows Credential Manager(CredentialManagerモジュール使用)
try {
# ⚠️ 注意: CredentialManagerモジュールは別途インストールが必要です
# Install-Module -Name CredentialManager -Force -Scope CurrentUser
if (Get-Module -ListAvailable -Name CredentialManager) {
Import-Module CredentialManager -ErrorAction SilentlyContinue
if (Get-Command Get-StoredCredential -ErrorAction SilentlyContinue) {
$storedCred = Get-StoredCredential -Target $Target -ErrorAction SilentlyContinue
if ($storedCred) {
Write-Verbose "✅ Windows Credential Managerから取得成功"
return $storedCred.GetNetworkCredential().Password
}
}
} else {
Write-Warning @"
📦 CredentialManagerモジュールが見つかりません。
Windows Credential Managerを使用する場合は、以下のコマンドでインストールしてください:
Install-Module -Name CredentialManager -Force -Scope CurrentUser
または管理者権限で:
Install-Module -Name CredentialManager -Force
その後、以下のようにライセンスキーを保存できます:
New-StoredCredential -Target 'NewRelic/LicenseKey' -UserName 'NewRelic' -Password 'your-license-key' -Persist LocalMachine
"@
}
} catch {
Write-Verbose "❌ Windows Credential Managerからの取得に失敗: $_"
}
# 方法2: 環境変数から取得(最も推奨される方法)
if ($env:NEW_RELIC_LICENSE_KEY) {
Write-Verbose "✅ 環境変数から取得成功"
return $env:NEW_RELIC_LICENSE_KEY
}
# 方法3: PowerShell SecretManagement(PowerShell 7+)
try {
if (Get-Module -ListAvailable -Name Microsoft.PowerShell.SecretManagement) {
$secret = Get-Secret -Name "NewRelic-LicenseKey" -ErrorAction SilentlyContinue
if ($secret) {
Write-Verbose "✅ PowerShell SecretManagementから取得成功"
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
try {
return [Runtime.InteropServices.Marshal]::PtrToStringAuto($ptr)
} finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr)
}
}
}
} catch {
Write-Verbose "❌ SecretManagementからの取得に失敗: $_"
}
# 方法4: レジストリから取得(DPAPI暗号化対応)
try {
# DPAPI暗号化されたキーを取得
$encryptedKey = Get-ItemProperty -Path "HKLM:\SOFTWARE\NewRelic" -Name "EncryptedLicenseKey" -ErrorAction SilentlyContinue
if ($encryptedKey -and $encryptedKey.EncryptedLicenseKey) {
# Base64デコード → DPAPI復号化
$encryptedBytes = [Convert]::FromBase64String($encryptedKey.EncryptedLicenseKey)
$decryptedBytes = [Security.Cryptography.ProtectedData]::Unprotect(
$encryptedBytes,
$null,
[Security.Cryptography.DataProtectionScope]::LocalMachine
)
$decryptedString = [Text.Encoding]::UTF8.GetString($decryptedBytes)
Write-Verbose "✅ レジストリ(DPAPI暗号化)から取得成功"
return $decryptedString
}
} catch {
Write-Verbose "❌ DPAPI暗号化キーの取得に失敗: $_"
}
# 方法5: レジストリから取得(平文 - 非推奨だが互換性のため)
try {
$regKey = Get-ItemProperty -Path "HKLM:\SOFTWARE\NewRelic" -Name "LicenseKey" -ErrorAction SilentlyContinue
if ($regKey -and $regKey.LicenseKey) {
Write-Warning "⚠️ レジストリから平文のライセンスキーを取得しました。セキュリティ向上のためDPAPI暗号化の使用を推奨します。"
Write-Verbose "✅ レジストリ(平文)から取得成功"
return $regKey.LicenseKey
}
} catch {
Write-Verbose "❌ レジストリ(平文)からの取得に失敗: $_"
}
return $null
}
# ライセンスキーの取得(複数の安全な方法を試行)
if (-not $LicenseKey) {
$LicenseKey = Get-SecureCredential
if (-not $LicenseKey) {
Write-Error "ライセンスキーが見つかりません。以下のいずれかの方法で設定してください:
1. Windows Credential Managerに登録
2. NEW_RELIC_LICENSE_KEY 環境変数を設定
3. -LicenseKey パラメータで指定"
exit 1
}
}
# 管理者権限の確認
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Error "このスクリプトは管理者権限で実行してください"
exit 1
}
# ダウンロードとインストール
try {
$downloadUrl = "https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi"
$installerPath = "$env:TEMP\newrelic-infra.msi"
Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath
$arguments = @(
"/i", "`"$installerPath`"",
"/quiet", "/norestart",
"GENERATE_CONFIG=true",
"LICENSE_KEY=$LicenseKey",
"NRIA_DISPLAY_NAME=$DisplayName"
)
$process = Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -eq 0) {
Start-Service -Name "newrelic-infra"
Write-Host "インストールが完了しました"
} else {
throw "インストール失敗。終了コード: $($process.ExitCode)"
}
} catch {
Write-Error "エラーが発生しました: $($_.Exception.Message)"
} finally {
Remove-Item $installerPath -Force -ErrorAction SilentlyContinue
}
💡 高度なスクリプト: Credential Manager連携、DPAPI暗号化等の詳細機能は公式ドキュメントを参照してください。
スクリプトの実行例
基本的な実行方法:
# ライセンスキーを指定して実行
.\Install-NewRelicAgent.ps1 -LicenseKey "your-license-key"
# 表示名をカスタマイズして実行
.\Install-NewRelicAgent.ps1 -LicenseKey "your-license-key" -DisplayName "web-server-01"
セキュアな実行方法(環境変数使用):
# 事前に環境変数を設定
[Environment]::SetEnvironmentVariable("NEW_RELIC_LICENSE_KEY", "your-license-key", "Machine")
# 環境変数からライセンスキーを取得するバージョンのスクリプトを実行
設定ファイルの詳細設定
基本設定ファイル
Windowsでの設定ファイルは、以下の場所に配置されます。
C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml
基本的な設定例は以下のとおりです。
# ライセンスキー(必須)
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サービスを監視する場合の設定例です。
# 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パッケージを配布できます。
基本的な手順:
- 配布用共有フォルダにMSIファイルを配置
- グループポリシー管理コンソールを開く
- 「コンピューターの構成」→「ソフトウェアの設定」→「ソフトウェアインストール」
- 新しいパッケージとしてMSIファイルを追加
# 配布用共有フォルダの作成例
New-Item -Path "\\fileserver\software\NewRelic" -ItemType Directory
Copy-Item "newrelic-infra.msi" "\\fileserver\software\NewRelic\"
レジストリによる一括設定
レジストリを使用してライセンスキーを一括設定できます。
# 基本的なレジストリ設定
$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の状態を確認できます。
# サービス状態の確認
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
パフォーマンス監視
エージェント自体のパフォーマンスを監視するためのスクリプトです。
# リソース使用量の監視
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
トラブルシューティング
一般的な問題と解決方法
サービスが起動しない場合
# 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"
ファイアウォール設定の確認
# HTTPS通信の確認
Test-NetConnection -ComputerName "infra-api.newrelic.com" -Port 443
# Windowsファイアウォールルールの確認
Get-NetFirewallRule -DisplayName "*New Relic*" | Format-Table DisplayName, Enabled, Direction
アンインストール手順
完全なアンインストールが必要な場合の手順です。
# サービスの停止
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に必要なファイアウォール設定を適用します。
# New Relic用ファイアウォールルールの作成
New-NetFirewallRule -DisplayName "New Relic Infrastructure Agent" -Direction Outbound -Protocol TCP -RemotePort 443 -Action Allow
権限最小化
セキュリティ強化のため、最小限の権限で動作するように設定できます。
# 専用サービスアカウントの作成
$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環境でのエージェント導入関連記事: 設定ファイル完全リファレンス