为 EC2 配置结构

发布于 2024-11-15 03:33:13 字数 957 浏览 4 评论 0原文

我正在尝试创建一个 fabfile.py 以便可以在 EC2 上部署。我的 fabfile.py 中有以下内容:

from __future__ import with_statement
from fabric.api import *


def ec2():
    env.hosts = ['111.111.111.111'] 
    env.user = 'ubuntu'
    env.key_filename = '/path/to/my/pem/key.pem'

def run_ls():
    run('ls -alt')

“111.111.111.111”是我的实例的弹性 IP,我总是使用 ubuntu 登录,而不是 root。 当我运行以下命令时,

fab ec2 run_ls

我看到以下输出:

[111.111.111.111] Executing task 'run_ls'
[111.111.111.111] run: ls -alt

Fatal error: Host key for 111.111.111.111 did not match pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack.

Aborting.

不确定发生了什么,但我找不到关于在 ec2 上使用 Fabric 的任何很棒的教程,而且我不知道这是怎么可能的。

谢谢

更新:

看起来

env.hosts = ['111.111.111.111'] 

无效,您需要使用

env.hosts = ['mywebsite.com'] 

解决我的问题的实际 URL

I am trying to create a fabfile.py so that I can deploy on EC2. I have the following in my fabfile.py:

from __future__ import with_statement
from fabric.api import *


def ec2():
    env.hosts = ['111.111.111.111'] 
    env.user = 'ubuntu'
    env.key_filename = '/path/to/my/pem/key.pem'

def run_ls():
    run('ls -alt')

'111.111.111.111' is the elastic ip of my instance, and i alway login with ubuntu, not root.
when i run the following command

fab ec2 run_ls

i see the following output:

[111.111.111.111] Executing task 'run_ls'
[111.111.111.111] run: ls -alt

Fatal error: Host key for 111.111.111.111 did not match pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack.

Aborting.

Not sure what is going on, but I can't find to seem any great tutorials on using fabric on ec2, and I do not know how that is possible.

Thanks

Update:

Looks like

env.hosts = ['111.111.111.111'] 

is not valid, you need to use the actually URL

env.hosts = ['mywebsite.com'] 

which fixed my issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桃酥萝莉 2024-11-22 03:33:13

您还可以使用“--disable-known-hosts”开关来忽略此错误。

You can also use the '--disable-known-hosts' switch to ignore this error.

眼前雾蒙蒙 2024-11-22 03:33:13

确保您的弹性 IP 已附加到实例。我认为 key_filename 采用单个参数,但当您传入数组时,我的参数正在工作:

env.user = "ubuntu"
env.key_filename = ["my_key.pem",]

也许您应该尝试使用实例的公共主机名,例如:

env.roledefs.update({
    'prod': ['ec2-52-14-72-225.us-west-1.compute.amazonaws.com'],
})

Make sure your elastic IP is attached to the instance. I think the key_filename takes a single argument but mine is working when you pass in an array instead:

env.user = "ubuntu"
env.key_filename = ["my_key.pem",]

Maybe you should try using the public hostname of your instance like:

env.roledefs.update({
    'prod': ['ec2-52-14-72-225.us-west-1.compute.amazonaws.com'],
})
归途 2024-11-22 03:33:13

GitHub 上的 Vagrant 问题 中,您可能需要从 <使用如下命令创建 code>known_hosts 文件:

ssh-keygen -R 111.111.111.111

From a Vagrant issue on GitHub, you may need to remove the host from the known_hosts file using a command like this:

ssh-keygen -R 111.111.111.111
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文