俺です。
consul execを使ってwindows powershellを叩く方法の例です。
consulが最も簡単にwindowsをリモート管理するツールな気がしました。
consul members
- Amazon Linuxをconsul serverとしてwindows(dev-win-1a)をjoinさせている
[ec2-user@ip-172-31-10-102 ~]$ consul members
Node Address Status Type Build Protocol DC
dev-win-1a 172.31.10.189:8301 alive client 0.6.0 2 ap-northeast-1
prd-manage-1a 172.31.10.102:8301 alive server 0.6.0 2 ap-northeast-1
config & startup
consul server(Linux)
- /home/ec2-user/conf/consul.json
{
"server": true,
"bootstrap_expect": 1,
"bootstrap": false,
"data_dir": "/home/ec2-user/data",
"log_level": "INFO",
"node_name":"prd-manage-1a",
"datacenter":"ap-northeast-1"
}
- Amazon Linuxでconsul起動
[ec2-user@ip-172-31-10-102 ~]$ ./consul agent -config-dir=/home/ec2-user/conf
consul agent(Windows)
検証なのでWindows FirewallはOffってある
c:¥consul¥conf¥consul.json
{
"server": false,
"bootstrap": false,
"data_dir": "c:\\consul\\data\\",
"log_level": "INFO",
"node_name":"dev-win-1a",
"datacenter":"ap-northeast-1"
}
- Windowsでconsul起動
PS C:\consul\bin> .\consul.exe agent -config-dir c:/consul/conf
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
Node name: 'dev-win-1a'
Datacenter: 'ap-northeast-1'
Server: false (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 172.31.10.189 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas: <disabled>
==> Log data will now stream in as it occurs:
2015/12/09 17:04:15 [INFO] serf: EventMemberJoin: dev-win-1a 172.31.10.189
consul join & members
- server側で実行
[ec2-user@ip-172-31-10-102 ~]$ ./consul join 172.31.10.189
[ec2-user@ip-172-31-10-102 ~]$ ./consul members
Node Address Status Type Build Protocol DC
dev-win-1a 172.31.10.189:8301 alive client 0.6.0 2 ap-northeast-1
prd-manage-1a 172.31.10.102:8301 alive server 0.6.0 2 ap-northeast-1
以上でconsulでWindowsを任意のホストからリモート管理できるようになった。
consul execの結果
- powershellワンライナー
[ec2-user@ip-172-31-10-102 ~]$ ./consul exec -node=dev-win-1a "powershell Write-Host hello"
dev-win-1a: hello
dev-win-1a:
==> dev-win-1a: finished with exit code 0
- powershellスクリプト
hello worldと出力するps1ファイルをWindows任意の場所に配置しておく
[ec2-user@ip-172-31-10-102 ~]$ ./consul exec -node=dev-win-1a "powershell c:/consul/helloworld.ps1"
dev-win-1a: hello
dev-win-1a:
==> dev-win-1a: finished with exit code 0
1 / 1 node(s) completed / acknowledged