์์ฒด ๊ด๋ฆฌ ๋ฐฐํฌ๋ฅผ ์ํ Windows netsh
๋ฐฉํ๋ฒฝ ๊ตฌ์ฑ
์ด ํ์ด์ง์ ๋ด์ฉ
Windows Server ์์คํ
์์ netsh
ํ๋ก๊ทธ๋จ์ Windows Firewall์(๋ฅผ) ๊ด๋ฆฌํ๊ธฐ ์ํ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค. ์ด๋ฌํ ๋ฐฉํ๋ฒฝ ๊ท์น์ ํตํด ๊ด๋ฆฌ์๋ ์์คํ
์ ์ฐ๊ฒฐํ ์ ์๋ ํธ์คํธ๋ฅผ ์ ์ดํ๊ณ ์์คํ
์ ์ฐ๊ฒฐํ ์ ์๋ ํธ์คํธ๋ฅผ ์ ํํ์ฌ ์ํ ๋
ธ์ถ์ ์ ํํ ์ ์์ต๋๋ค.
์ด ๋ฌธ์์์๋ ๊ธฐ๋ณธ Windows Firewall ๊ตฌ์ฑ์ ๋ํด ๊ฐ๋ตํ๊ฒ ์ค๋ช ํฉ๋๋ค. ์ด๋ฌํ ์ ๊ทผ ๋ฐฉ์์ ๋ ํฐ ๊ท๋ชจ์ ๋คํธ์ํน ์กฐ์ง์ ์ํ ์ถ๋ฐ์ ์ผ๋ก ํ์ฉํ์ธ์. MongoDB์ ๋ณด์ ๊ดํ ๋ฐ ์ํ ๊ด๋ฆฌ์ ๋ํ ์์ธํ ๊ฐ์๋ ๋ณด์์ ์ฐธ์กฐํ์ธ์.
๊ฐ์
Windows Firewall ๊ท์น ์ ํ์ ๋ฐ๋ผ ๊ฒฐ์ ๋ ์์๋๋ก ๊ท์น์ ์ฒ๋ฆฌํ๊ณ ๋ค์ ์์๋ก ๊ตฌ๋ฌธ ๋ถ์๋ฉ๋๋ค.
Windows Service Hardening
Connection security rules
Authenticated Bypass Rules
Block Rules
Allow Rules
Default Rules
๊ธฐ๋ณธ์ ์ผ๋ก Windows Firewall์ ์ ์ฑ ์ ๋ชจ๋ ์์๋ฐ์ด๋ ์ฐ๊ฒฐ์ ํ์ฉํ๊ณ ๋ชจ๋ ๋ค์ด์ค๋ ์ฐ๊ฒฐ์ ์ฐจ๋จํฉ๋๋ค.
๋ชจ๋ MongoDB ํ๋ก์ธ์ค์ ๊ธฐ๋ณธ ํฌํธ๋ฅผ ๊ณ ๋ คํ ๋, ์ ํ๋ฆฌ์ผ์ด์
๊ณผ ์ ํฉํ mongod.exe
๋ฐ mongos.exe
์ธ์คํด์ค ๊ฐ์ ํ์ํ ํต์ ๋ง ํ์ฉํ๋ ๋คํธ์ํน ๊ท์น์ ๊ตฌ์ฑํด์ผ ํฉ๋๋ค.
์ด ๋ฌธ์์ ์ค๋ช ๋ ๊ตฌ์ฑ ๋ณ๊ฒฝ ์ฌํญ์ ๋ช ์์ ์ผ๋ก ํ์ฉ๋์ง ์๋ ๋ชจ๋ ํธ๋ํฝ์ ์ ๊ฑฐํ๋ ๊ธฐ๋ณธ ์ ์ฑ ์ ์ฌ์ฉํ์ฌ ํน์ ์ฃผ์ ๋ฐ ํน์ ํฌํธ์ ํธ๋ํฝ์ ๋ช ์์ ์ผ๋ก ํ์ฉํ๋ ๊ท์น์ ์์ฑํฉ๋๋ค.
netsh
๋ช
๋ น์ค ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ Windows ์ ํ๋ฆฌ์ผ์ด์
์ ํตํด Windows Firewall๋ฅผ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. Windows Server 2008์์ ์ด ์ ํ๋ฆฌ์ผ์ด์
์ Administrative Tools์ Windows Firewall With Advanced Security์
๋๋ค. ์ด์ ๋ฒ์ ์ Windows Server์์๋ System and Security ์ ์ดํ์์ Windows Firewall ์ ํ๋ฆฌ์ผ์ด์
์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
์ด ๋ฌธ์์ ์ ์ฐจ์์๋ netsh
๋ช
๋ น์ค ๋๊ตฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
ํจํด
์ด ์น์
์๋ MongoDB deployment์ ์ฌ์ฉํ ์ ์๋๋ก Windows Firewall์ ๊ตฌ์ฑํ๊ธฐ ์ํ ์ฌ๋ฌ ๊ฐ์ง ํจํด๊ณผ ์์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. port
๊ตฌ์ฑ ์ค์ ์ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ํฌํธ๋ฅผ ๊ตฌ์ฑํ ๊ฒฝ์ฐ ์ด์ ๋ฐ๋ผ ๊ท์น์ ์์ ํด์ผ ํฉ๋๋ค.
mongod.exe
์ธ์คํด์ค ๊ฐ ํธ๋ํฝ
์ด ํจํด์ ๋
๋ฆฝํ ์ธ์คํด์ค ๋๋ ๋ณต์ ๋ณธ ์ธํธ์ ์ผ๋ถ๋ก ์คํ๋๋ ๋ชจ๋
mongod.exe
์ธ์คํด์ค์ ์ ์ฉํ ์ ์์ต๋๋ค. ์ด ํจํด์ ๋ชฉํ๋ ์ ํ๋ฆฌ์ผ์ด์
์๋ฒ์์ {2} ์ธ์คํด์ค๋ก์ ํธ๋ํฝ์ ๋ช
์์ ์ผ๋ก ํ์ฉํ๋ ๊ฒ์
๋๋ค.
netsh advfirewall firewall add rule name="Open mongod port 27017" dir=in action=allow protocol=TCP localport=27017
์ด ๊ท์น์ ์ ํ๋ฆฌ์ผ์ด์
์๋ฒ๊ฐ mongod.exe
์ธ์คํด์ค์ ์ฐ๊ฒฐํ ์ ์๋๋ก ํ๋ ํฌํธ
27017
์์ ์์ ๋ค์ด์ค๋ ๋ชจ๋ ํธ๋ํฝ์ ํ์ฉํฉ๋๋ค.
Windows Firewall ๋ํ, ๋ค์ ์์ ๊ฐ์ด ํน์ ํฌํธ๊ฐ ์๋ ์ ์ฒด ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ํ ๋คํธ์ํฌ ์ก์ธ์ค๋ฅผ ํ์ฑํํ ์ ์์ต๋๋ค.
netsh advfirewall firewall add rule name="Allowing mongod" dir=in action=allow program=" C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"
๋ค์ ํธ์ถ์ ์ฌ์ฉํ์ฌ mongos.exe
์๋ฒ์ ๋ํ ๋ชจ๋ ์ก์ธ์ค๋ฅผ ํ์ฉํ ์ ์์ต๋๋ค.
netsh advfirewall firewall add rule name="Allowing mongos" dir=in action=allow program=" C:\Program Files\MongoDB\Server\3.4\bin\mongos.exe"
mongos.exe
์ธ์คํด์ค ๊ฐ ํธ๋ํฝ
mongos.exe
์ธ์คํด์ค๋ ์ค๋ฉ๋ ํด๋ฌ์คํฐ์ ๋ํ ์ฟผ๋ฆฌ ๋ผ์ฐํ
์ ์ ๊ณตํฉ๋๋ค. ํด๋ผ์ด์ธํธ๋ mongos.exe
์ธ์คํด์ค์ ์ฐ๊ฒฐํ๋ฉฐ, ์ด ์ธ์คํด์ค๋ ํด๋ผ์ด์ธํธ ๊ด์ ์์ mongod.exe
์ธ์คํด์ค๋ก ์๋ํฉ๋๋ค. ์ฐจ๋ก๋ก mongos.exe
์ ์ค๋ฉ๋ ํด๋ฌ์คํฐ์ ๊ตฌ์ฑ ์์์ธ ์ ์ฒด mongod.exe
์ธ์คํด์ค์ ์ฐ๊ฒฐํฉ๋๋ค.
๋ณต์ ๋ณธ ์ธํธ์ ๊ตฌ์ฑ์์ธ mongod.exe
์ธ์คํด์ค์์์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ด๋ฌํ ์ธ์คํด์ค์์ ํธ๋ํฝ์ ํ์ฉํ๋ ค๋ฉด ๋์ผํ Windows Firewall ๋ช
๋ น์ ์ฌ์ฉํฉ๋๋ค.
netsh advfirewall firewall add rule name="Open mongod shard port 27018" dir=in action=allow protocol=TCP localport=27018
MongoDB ๊ตฌ์ฑ ์๋ฒ์์ ํธ๋ํฝ
๊ตฌ์ฑ ์๋ฒ๋ ์ค๋ฉ๋ ํด๋ฌ์คํฐ์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ config ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ํธ์คํ
ํฉ๋๋ค. ๊ฐ ํ๋ก๋์
cluster์๋ mongod --configsvr
์ต์
์ ์ฌ์ฉํ์ฌ ์์๋ 3๊ฐ์ ๊ตฌ์ฑ ์๋ฒ๊ฐ ์์ต๋๋ค. [1] ๊ตฌ์ฑ ์๋ฒ๊ฐ ํฌํธ 27019
์์ ์ฐ๊ฒฐ์ ์์ ๋๊ธฐํฉ๋๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก ๋ค๋ฅธ ๊ตฌ์ฑ ์๋ฒ์ ์ฐ๊ฒฐํ๊ธฐ ์ํด ํฌํธ 27019
์์ ์์ ๋ฐ ๋ฐ์ ์ฐ๊ฒฐ์ ํ์ฉํ๋๋ก ๊ตฌ์ฑ ์๋ฒ์ ๋ค์ Windows Firewall ๊ท์น์ ์ถ๊ฐํฉ๋๋ค.
netsh advfirewall firewall add rule name="Open mongod config svr port 27019" dir=in action=allow protocol=TCP localport=27019
๋ํ, config ์๋ฒ๋ ํด๋ฌ์คํฐ์ ๋ชจ๋ mongos.exe
์ธ์คํด์ค ๋ฐ ํด๋ฌ์คํฐ์ ๋ชจ๋ mongod.exe
์ธ์คํด์ค์์ ๋ค์ด์ค๋ ์ฐ๊ฒฐ์ ํ์ฉํด์ผ ํฉ๋๋ค. ๋ค์๊ณผ ์ ์ฌํ ๊ท์น์ ์ถ๊ฐํฉ๋๋ค:
netsh advfirewall firewall add rule name="Open mongod config svr inbound" dir=in action=allow protocol=TCP remoteip=<ip-address> localport=27019
<ip-address>
๋ฅผ mongos.exe
์ธ์คํด์ค ๋ฐ ์ค๋ mongod.exe
์ธ์คํด์ค์ ์ฃผ์๋ก ๋์ฒดํฉ๋๋ค.
[1] | ๋ํ ๊ตฌ์ฑ ํ์ผ์์ clusterRole ์ค์ ์ configsvr ๊ฐ์ ์ฌ์ฉํ์ฌ config ์๋ฒ๋ฅผ ์คํํ ์๋ ์์ต๋๋ค. |
MongoDB ์ค๋ ์๋ฒ ๊ฐ ํธ๋ํฝ
์ค๋ ์๋ฒ์ ๊ฒฝ์ฐ mongod --shardsvr
๋ก ์คํ [2] clusterRole
์ค์ ์ ๋ํ
shardsvr
๊ฐ์ผ๋ก ์คํํ ๋ ๊ธฐ๋ณธ ํฌํธ ๋ฒํธ๊ฐ 27018
์ด๋ฏ๋ก ๊ฐ ์ค๋ ๊ฐ์ ํธ๋ํฝ์ ํ์ฉํ๋๋ก ๋ค์ Windows Firewall ๊ท์น์ ๊ตฌ์ฑํด์ผ ํฉ๋๋ค.
netsh advfirewall firewall add rule name="Open mongod shardsvr inbound" dir=in action=allow protocol=TCP remoteip=<ip-address> localport=27018 netsh advfirewall firewall add rule name="Open mongod shardsvr outbound" dir=out action=allow protocol=TCP remoteip=<ip-address> localport=27018
<ip-address>
์ฌ์์ ๋ชจ๋ mongod.exe
์ธ์คํด์ค์ IP ์ฃผ์๋ก ๋์ฒดํฉ๋๋ค. ์ด๋ฅผ ํตํด ๋ค์์ ๋ํ ๊ตฌ์ฑ ๋ณต์ ๋ณธ ์ธํธ ๋ฉค๋ฒ๋ฅผ ํฌํจํ ๋ชจ๋ ์ค๋ ๊ฐ์ ๋ค์ด์ค๊ณ ๋๊ฐ๋ ํธ๋ํฝ์ ํ์ฉํฉ๋๋ค.
์ค๋์ ๋ณต์ ๋ณธ ์ธํธ์ ์๋ ๋ชจ๋
mongod.exe
์ธ์คํด์ค.๋ค๋ฅธ ์ค๋์ ๋ชจ๋
mongod.exe
์ธ์คํด์ค. [3]
๋ํ, ์ค๋๋ ๋ค์ ๋์์ผ๋ก ๋๊ฐ๋ ์ฐ๊ฒฐ์ ๋ง๋ค ์ ์์ด์ผ ํฉ๋๋ค.
๋ชจ๋
mongos.exe
์ธ์คํด์ค.๊ตฌ์ฑ ์๋ฒ์ ๋ชจ๋
mongod.exe
์ธ์คํด์ค.
๋ค์๊ณผ ์ ์ฌํ ๊ท์น์ ๋ง๋ค๊ณ <ip-address>
์ config ์๋ฒ ๋ฐ mongos.exe
์ธ์คํด์ค์ ์ฃผ์๋ก ๋ฐ๊ฟ๋๋ค.
netsh advfirewall firewall add rule name="Open mongod config svr outbound" dir=out action=allow protocol=TCP remoteip=<ip-address> localport=27018
[2] | ๊ตฌ์ฑ ํ์ผ์์ clusterRole ์ค์ ์ shardsvr ๊ฐ์ ์ฌ์ฉํ์ฌ ์ค๋ ์๋ฒ ์ต์
์ ์ง์ ํ ์๋ ์์ต๋๋ค. ์ค๋ ๋ฉค๋ฒ๋ ๊ธฐ๋ณธ ํฌํธ๋ฅผ ์ฌ์ฉํ๋ ๊ธฐ์กด ๋ณต์ ๋ณธ ์ธํธ์ธ ๊ฒฝ์ฐ๋ ๋ง์ต๋๋ค. |
[3] | cluster์ ๋ชจ๋ ์ค๋๋ ์ฒญํฌ ๋ฐ ๋ฐธ๋ฐ์ฑ ์ฐ์ฐ์ ์ํํ๊ฒ ์ํํ๊ธฐ ์ํด ๋ค๋ฅธ ๋ชจ๋ ์ค๋์ ํต์ ํ ์ ์์ด์ผ ํฉ๋๋ค. |
๋ชจ๋ํฐ๋ง ์์คํ ์ ๋ํ ์ก์ธ์ค ๊ถํ ์ ๊ณต
mongostat
์ง๋จ ๋๊ตฌ๋ --discover
์ ํจ๊ป ์คํ๋ ๋ config ์๋ฒ, ์ค๋ ์๋ฒ, mongos.exe
์ธ์คํด์ค๋ฅผ ํฌํจํ์ฌ ํด๋ฌ์คํฐ์ ๋ชจ๋ ๊ตฌ์ฑ ์์์ ๋๋ฌํ ์ ์์ด์ผ ํฉ๋๋ค.
Windows ๋ฐฉํ๋ฒฝ ๊ตฌ์ฑ ๊ด๋ฆฌ
์ด ์น์
์๋ netsh
์ ๊ด๋ฆฌํ๊ณ ์ฌ์ฉํ๊ธฐ ์ํ ์ฌ๋ฌ ๊ฐ์ง ๊ธฐ๋ณธ ์ฐ์ฐ์ด ํฌํจ๋์ด ์์ต๋๋ค. GUI ํ๋ฐํธ์๋๋ฅผ ์ฌ์ฉํ์ฌ Windows Firewall๋ฅผ managedํ ์ ์์ง๋ง netsh
์์ ๋ชจ๋ ํต์ฌ ๊ธฐ๋ฅ์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
๊ธฐ๋ณธ MongoDB ํฌํธ์ ๋ํ Windows ๋ฐฉํ๋ฒฝ ๊ท์น ์ญ์
mongod.exe
ํธ๋ํฝ์ ํ์ฉํ๋ ๋ฐฉํ๋ฒฝ ๊ท์น์ ์ญ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
netsh advfirewall firewall delete rule name="Open mongod port 27017" protocol=tcp localport=27017 netsh advfirewall firewall delete rule name="Open mongod shard port 27018" protocol=tcp localport=27018
๋ชจ๋ Windows ๋ฐฉํ๋ฒฝ ๊ท์น ๋์ด
๋ชจ๋ Windows Firewall ๊ท์น์ ๋ชฉ๋ก์ ๋ค์๊ณผ ๊ฐ์ด ๋ฐํํฉ๋๋ค.
netsh advfirewall firewall show rule name=all
Windows ๋ฐฉํ๋ฒฝ ์ฌ์ค์
๋ค์๊ณผ ๊ฐ์ด Windows Firewall ๊ท์น์ ์ฌ์ค์ ํฉ๋๋ค.
netsh advfirewall reset
Windows ๋ฐฉํ๋ฒฝ ๊ท์น ๋ฐฑ์ ๋ฐ ๋ณต์
๋๊ท๋ชจ ์์คํ ์ ๊ด๋ฆฌ๋ฅผ ๊ฐ์ํํ๊ธฐ ์ํด Windows ๋ฐฉํ๋ฒฝ ๊ท์น์ ๋ด๋ณด๋ด๊ฑฐ๋ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
๋ชจ๋ Windows ๋ฐฉํ๋ฒฝ ๊ท์น์ ๋ด๋ณด๋ด๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
netsh advfirewall export "C:\temp\MongoDBfw.wfw" "C:\temp\MongoDBfw.wfw"
๋ฅผ ์ํ๋ ๊ฒฝ๋ก๋ก ๋ฐ๊ฟ๋๋ค.Windows ๋ฐฉํ๋ฒฝ ๊ท์น์ ๊ฐ์ ธ์ค๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
netsh advfirewall import "C:\temp\MongoDBfw.wfw" "C:\temp\MongoDBfw.wfw"
๋ฅผ Windows ๋ฐฉํ๋ฒฝ ๊ท์น์ด ํฌํจ๋ ํ์ผ ๊ฒฝ๋ก๋ก ๋ฐ๊ฟ๋๋ค.