我在使用Packer的Google Cloud Platform中从自定义映像运行实例时遇到问题。半小时后,我遇到了WinRM超时问题)
==> image-ami-win: Waiting for the instance to become running...
image-ami-win: Internal IP: 10.154.21.203
image-ami-win: IP: 10.154.21.203
==> image-ami-win: Using winrm communicator to connect: 10.154.21.203
==> image-ami-win: Waiting for WinRM to become available...
==> image-ami-win: Timeout waiting for WinRM.
==> image-ami-win: Deleting instance...
image-ami-win: Instance has been deleted!
==> image-ami-win: Deleting disk...
image-ami-win: Disk has been deleted!
Build 'image-ami-win' errored: Timeout waiting for WinRM.
如果我使用基本的Windows-2016映像-一切都将以正确的方式工作。
{
"builders": [
{
"type": "googlecompute",
"account_file": "account.json",
"project_id": "my project",
"source_image_family": "windows-2016",
"image_family": "my-image"
"disk_size": "50",
"machine_type": "n1-standard-1",
"communicator": "winrm",
"winrm_username": "packer_user",
"winrm_insecure": true,
"winrm_use_ssl": true,
"metadata": {
"windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & winrm set winrm/config/service/auth @{Basic=\"true\"}"
},
"zone": "us-central1-a"
}
]
}
起初,我不是使用packer_user而是使用“管理员”用户名-它不起作用(Issue with using winrm user different from "packer_user" with Google Cloud Platform)
当前,如果我正在从自定义映像(从Windows-2016 gcp映像成功创建)运行实例,则会向我显示错误:“ Build'image-ami-win'错误:超时,等待WinRM。” < / p>
我没有运行任何可能影响防火墙或访问权限的自定义设置程序。只需从基本的Windows-2016映像创建实例-关闭,创建映像并使用打包程序进行构建:
{
"variables": {
"zone": "us-east1-b",
"winrm_user" : "packer_user",
"builder_name": ""
},
"builders": [
{
"name": "image-ami-win",
"type": "googlecompute",
"project_id": "{{user `project_id`}}",
"zone": "{{user `zone`}}",
"source_image_family": "my-family"
"communicator": "winrm",
"winrm_username": "{{user `winrm_user`}}",
"image_name": "{{user `project`}}{{user `env`}}-{{build_name}}-{{user `team`}}-{{timestamp}}",
"machine_type": "n1-standard-4",
"disk_size": 50,
"network_project_id": "{{user `network_project_id`}}",
"subnetwork": "{{user `subnetwork`}}",
"omit_external_ip": false,
"use_internal_ip": false,
"tags": [
"project-{{user `project`}}",
"branch-{{user `branch`}}",
"commit-{{user `commit_id`}}",
],
"winrm_insecure": true,
"winrm_use_ssl": true,
"metadata": {
"windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add {{user `winrm_user`}} & net localgroup administrators {{user `winrm_user`}} /add & winrm set winrm/config/service/auth @{Basic=\"true\"} & powershell -Command \"& {Set-ExecutionPolicy AllSigned -Force}\""
}
}
],
"provisioners": []
}
我已经尝试运行启动脚本:
<powershell>
Enter-PSSession -ComputerName server.domain.local -Credential domain\administrator
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
</powershell>
它无助于解决此问题。 另外,我无法通过RDP从Google Cloud Console(UI)连接到此实例,但是与此同时,我可以在从Windows-2016 Google Cloud映像创建实例的过程中轻松连接。
我还注意到从Google Cloud Windows-2016映像构建实例与自定义映像之间的区别:
如果我从Windows-2016 Google Cloud Image运行实例,则会收到下一条消息:
2019/10/21 12:22:38 packer: 2019/10/21 12:22:38 [INFO] Attempting WinRM connection...
2019/10/21 12:22:38 packer: 2019/10/21 12:22:38 [DEBUG] connecting to remote shell using WinRM
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [ERROR] connection error: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [INFO] Attempting WinRM connection...
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [ERROR] connection error: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [ERROR] WinRM connection err: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [INFO] Attempting WinRM connection...
但是,如果我从自定义映像运行实例,则会收到以下消息:
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [INFO] Attempting WinRM connection...
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] connection error: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48984->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48984->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [INFO] Attempting WinRM connection...
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] connection error: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48988->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48988->10.154.21.203:5986: read: connection reset by peer
中的差异
/ wsman:拨号 tcp 10.154.21.219:5986:输入/输出超时
和
10.147.84.31:48988-> 10.154.21.203:5986:阅读:
。看起来有些转发有效,但我不明白为什么,因为除了图像名称外,打包程序生成器完全相同。
实例应该从自定义映像成功运行,就像我从Google Cloud Windows-2016基本映像构建实例一样。
我正在使用Packer 1.4.4版
有人可以帮我吗?