WinRM (Windows Remote Management)
Microsoft์์ ์ ๊ณตํ๋ ์๊ฒฉ ๊ด๋ฆฌ ํ๋กํ ์ฝ๋ก, Windows ์๋ฒ ๋ฐ ์์คํ ์ ์๊ฒฉ์ผ๋ก ๊ด๋ฆฌํ ์ ์๋ค. ํ์ค SOAP ๊ธฐ๋ฐ ๋ฐฉํ๋ฒฝ ์นํ์ ์ธ ํ๋กํ ์ฝ์ธ WS-Management ํ๋กํ ์ฝ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ค. Powershell ๋ช ๋ น์ ์๊ฒฉ ์์คํ ์์ ์คํํ ์ ์๋๋ก ๋์์ค๋ค.
๋์ ๊ฒฝ์ฐ, Linux์์ Ansible์ ์ฌ์ฉํ์ฌ Windows OS๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด WinRM์ ์ค์ ํ์๋ค. ๋ฆฌ๋ ์ค์ Windows๋ ์๋ก ๋ค๋ฅธ ๊ด๋ฆฌ ํ๋กํ ์ฝ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๋ฆฌ๋ ์ค์์ ์๋์ฐ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด์๋ WinRM๊ณผ ๊ฐ์ ํ์ค ํ๋กํ ์ฝ์ ์ฌ์ฉํด์ ํต์ ํด์ผ ํ๋ค.
WinRM ๊ตฌ๋ ์ฌ๋ถ ํ์ธ
WinRM ํ๋กํ ์ฝ์ด ์ฌ์ฉ ๊ฐ๋ฅํ์ง WinRM ๊ตฌ๋ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ค.
๋ง์ฝ ํ์ฑํ ์ค์ด ์๋๋ผ๋ฉด ์๋์ ๋ช ๋ น์ด๋ฅผ ํตํด WinRM์ ํ์ฑํํ๋ค.
winrm quickconfig
์๋ฌ๋๋ ๊ฒฝ์ฐ
VM ํ๊ฒฝ์์๋ ์ ์๋ํ๋๋ฐ ๋ด PC์์๋ '๋คํธ์ํฌ ์ฐ๊ฒฐ ํ์ ์ค ํ๋๊ฐ ๊ณต์ฉ์ผ๋ก ...' ๋ผ๋ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
์ฐพ์๋ณด๋ ๋คํธ์ํฌ ์นดํ
๊ณ ๋ฆฌ๊ฐ Public์ด๋ฉด WinRM์ ์ฌ์ฉํ ์ ์๋ค๊ณ ํ๋ค. WinRM์ ์๊ฒฉ ๊ด๋ฆฌ ๋๊ตฌ์ด๊ธฐ ๋๋ฌธ์ ์
์์ ์ผ๋ก ์๊ฒฉ ์์คํ
์ ์ ์ํ ๊ฐ๋ฅ์ฑ์ด ์์ด Public ๋คํธ์ํฌ์์๋ ์ ํ๋๋ค.
๋ฐ๋ผ์ ์๋์ ๋ช ๋ น์ด๋ฅผ ํตํด Private์ด๋ Domain์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์๋ค.
Set-NetConnectionProfile -NetworkCategory Privte
๋ชจ๋ Hosts๋ฅผ ํ์ฉํ๋๋ก ์ค์
Set-Item wsman:\localhost\Client\TrustedHosts -value *
TrustedHosts ๋ชฉ๋ก์ ๊ธฐ๋ณธ๊ฐ์ ์๋์ ์ฌ์ง๊ณผ ๊ฐ์ด ๋์ด์์ผ๋ฉฐ, ์๊ฒฉ ์ ์ ํ์ฉ์ ์ํด ๋ชจ๋ Hosts๋ฅผ ํ์ฉํ๋๋ก ์ค์ ํ๋ค.
๋ง์ฝ ํต์ ํ๋ ค๋ OS๊ฐ ๊ฐ์ ๋คํธ์ํฌ ๋ด์ ์์ ๊ฒฝ์ฐ ํด๋น ์ค์ ์ ํด์ฃผ์ง ์์๋ ๋๋ฉฐ ํน์ ํธ์คํธ๋ง์ ์ ๋ขฐํ๋ ค๋ ๊ฒฝ์ฐ ๋ช
์์ ์ผ๋ก IP๋ฅผ ์ถ๊ฐํด์ค ์๋ ์๋ค.
WinRM ์๋น์ค์์ ์คํ ์ค์ธ ํ์ฌ ๋ฆฌ์ค๋ ํ์ธ
WinRM์ ๊ธฐ๋ณธ์ ์ผ๋ก HTTP/HTTPS ํฌํธ๋ฅผ ์ฌ์ฉํ๋ค.
winrm enumerate winrm/config/Listener
๋ํ ๋๋ Ansible ํ ์คํธ ํ๊ฒฝ์์ windows๋ฅผ managed node๋ก ์ฌ์ฉํ๋ ๊ฒ์ด ๋ชฉ์ ์ด์๊ธฐ ๋๋ฌธ์ ์๋์ ์ค์ ์ ํด์ฃผ์๋ค.
winrm set winrm/config/service/Auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
๊ธฐ๋ณธ ์ธ์ฆ์ ํ์ฑํํ์ฌ ๊ณ์ ์ด๋ฆ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ํตํด ์๊ฒฉ ์์คํ ์ ์ ์ํ ์ ์๊ฒ ํ๊ณ , AllowUnencrypted True ์ค์ ์ ํตํด ์ํธํ๋์ง ์์ HTTP ํ๋กํ ์ฝ์ ์ฐ๊ฒฐ๋ ํ์ฉํ๋ค.
HTTPS ํฌํธ๋ฅผ ํตํ WinRM ํต์ ํ์ฉํ๋ ๋ฒ
WinRM์์ HTTPS ํต์ ์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์ธ์ฆ์ ๊ธฐ๋ฐ ์ธ์ฆ์ ์ค์ ํด์ผ ํ๋ค. SSL/TLS ์ธ์ฆ์๋ฅผ ์ฌ์ฉํด์ผ ํ๋๋ฐ.. ํ ์คํธ ํ๊ฒฝ์์๋ง ์๋ํ๋ ์์ฒด ์๋ช ๋ ์ธ์ฆ์๋ฅผ ์ฌ์ฉํด HTTPS ๋ฆฌ์ค๋๋ฅผ ์ถ๊ฐํ๋ค. https://docs.ansible.com/ansible/devel//os_guide/windows_winrm.html๋ฅผ ์ฐธ๊ณ ํ์ผ๋ฉฐ, ํด๋น ๋ฐฉ๋ฒ์ ํ ์คํธ ํ๊ฒฝ์ฉ์ผ๋ก ์ค์ ์ด์๋ง์์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ CA์์ ๋ฐ๊ธ๋ ์ธ์ฆ์๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
# Create self signed certificate
$certParams = @{
CertStoreLocation = 'Cert:\LocalMachine\My'
DnsName = $env:COMPUTERNAME
NotAfter = (Get-Date).AddYears(1)
Provider = 'Microsoft Software Key Storage Provider'
Subject = "CN=$env:COMPUTERNAME"
}
$cert = New-SelfSignedCertificate @certParams
# Create HTTPS listener
$httpsParams = @{
ResourceURI = 'winrm/config/listener'
SelectorSet = @{
Transport = "HTTPS"
Address = "*"
}
ValueSet = @{
CertificateThumbprint = $cert.Thumbprint
Enabled = $true
}
}
New-WSManInstance @httpsParams
# Opens port 5986 for all profiles
$firewallParams = @{
Action = 'Allow'
Description = 'Inbound rule for Windows Remote Management via WS-Management. [TCP 5986]'
Direction = 'Inbound'
DisplayName = 'Windows Remote Management (HTTPS-In)'
LocalPort = 5986
Profile = 'Any'
Protocol = 'TCP'
}
New-NetFirewallRule @firewallParams
์์ ์คํฌ๋ฆฝํธ๋ฅผ Powershell์ ์ ๋ ฅํ ํ, ๋ค์ Listener์ ์ดํด๋ณด๋ฉด HTTPS ํต์ ํฌํธ๋ ์ด๋ฆฐ ๊ฒ์ ํ์ธ ๊ฐ๋ฅํ๋ค.
'Infra & DevOps' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[AWS] Native Observability - Logs ์ค์ต (1) | 2024.11.12 |
---|---|
[Windows] Windows Server 2019์ ssh ์๋ฒ ์ค์น (0) | 2024.10.01 |
[AWS] EC2 SSH Connection Refused ํธ๋ฌ๋ธ์ํ (0) | 2024.03.28 |
Jenkins๋ก ๋ฌด์ค๋จ ๋ฐฐํฌ ํ์ดํ๋ผ์ธ ๊ตฌ์ถํ๊ธฐ (1) | 2024.03.08 |
[DevOps] ๋ฐฐํฌํ ๋ฆฌ์กํธ ํ๋ก์ ํธ์ nginx ์๋ฒ 404 ์๋ฌ (0) | 2024.03.08 |