尽管我已经写了相当多的 Chef ,但我对 AWS/VPC 和管理网络流量(尤其是堡垒主机)都相当陌生。
使用 Knife ec2 插件,我希望能够从我的开发人员工作站动态创建和引导 VM。 VM 应该能够存在于我的 VPC 的公共(public)子网或私有(private)子网中。我想在不使用弹性 IP 的情况下完成所有这些工作。我还希望我的堡垒主机能够放手(即我希望避免在我的堡垒主机上创建显式的每个 VM 监听隧道)
我已成功使用 Knife ec2 插件在旧版 EC2 模型中创建了一个 VM(例如,在我的 VPC 之外)。我现在正在尝试在我的 VPC 中创建一个实例。在 Knife 命令行上,我指定了网关、安全组、子网等。虚拟机被创建,但 Knife 随后无法通过 ssh 连接到它。
这是我的 Knife 命令行:
knife ec2 server create \
--flavor t1.micro \
--identity-file <ssh_private_key> \
--image ami-3fec7956 \
--security-group-ids sg-9721e1f8 \
--subnet subnet-e4764d88 \
--ssh-user ubuntu \
--server-connect-attribute private_ip_address \
--ssh-port 22 \
--ssh-gateway <gateway_public_dns_hostname (route 53)> \
--tags isVPC=true,os=ubuntu-12.04,subnet_type=public-build-1c \
--node-name <VM_NAME>
我怀疑我的问题与堡垒主机的配置有关。经过一天的谷歌搜索,我无法找到有效的配置。我可以通过 ssh 连接到堡垒主机,然后可以从那里通过 ssh 连接到新创建的虚拟机。我无法使用 gateway 参数成功地复制它。
我玩过/etc/ssh/ssh_config。这是它今天的存在方式:
ForwardAgent yes
#ForwardX11 no
#ForwardX11Trusted yes
#RhostsRSAAuthentication no
#RSAAuthentication yes
#PasswordAuthentication no
#HostbasedAuthentication yes
#GSSAPIAuthentication no
#GSSAPIDelegateCredentials no
#GSSAPIKeyExchange no
#GSSAPITrustDNS no
#BatchMode no
CheckHostIP no
#AddressFamily any
#ConnectTimeout 0
StrictHostKeyChecking no
IdentityFile ~/.ssh/identity
#IdentityFile ~/.ssh/id_rsa
#IdentityFile ~/.ssh/id_dsa
#Port 22
#Protocol 2,1
#Cipher 3des
#Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#EscapeChar ~
Tunnel yes
#TunnelDevice any:any
#PermitLocalCommand no
#VisualHostKey no
#ProxyCommand ssh -q -W %h:%p gateway.example.com
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
GatewayPorts yes
我还将/home/ubuntu/.ssh/identity 设置为我的新实例的匹配私钥。
更新:
我在堡垒主机的/var/log/auth.log 中注意到以下内容:
May 9 12:15:47 ip-10-0-224-93 sshd[8455]: Invalid user from <WORKSTATION_IP>
May 9 12:15:47 ip-10-0-224-93 sshd[8455]: input_userauth_request: invalid user [preauth]
最佳答案
我终于解决了这个问题。指定网关时我丢失了用户名。我最初认为 --ssh-user 参数将用于网关和我试图引导的 VM。这是不正确的,必须为两者指定用户名。
knife ec2 server create \
--flavor t1.micro \
--identity-file <ssh_private_key> \
--image ami-3fec7956 \
--security-group-ids sg-9721e1f8 \
--subnet subnet-e4764d88 \
--ssh-user ubuntu \
--server-connect-attribute private_ip_address \
--ssh-port 22 \
--ssh-gateway ubuntu@<gateway_public_dns_hostname (route 53)> \
--tags isVPC=true,os=ubuntu-12.04,subnet_type=public-build-1c \
--node-name <VM_NAME>
只是包含更新的行(注意前面的 ubuntu@):
--ssh-gateway ubuntu@<gateway_public_dns_hostname (route 53)>
我现在已经完成并锁定了我的堡垒主机,包括删除/home/ubuntu/.ssh/identity,因为将私钥存储在堡垒主机上真的很烦我。
仅供引用:设置堡垒主机时,sshd 的“开箱即用”配置将在使用 Amazon Linux AMI 镜像时起作用。此外,上面的一些参数是可选的,例如 --ssh-port。
关于ssh - 使用knife ec2插件在VPC私有(private)子网中创建VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16451762/