English 中文(简体)
Ubuntu AMI 没有装入用户数据
原标题:Ubuntu AMI not loading user-data

我试图将用户数据装入Ubuntu 12.04 LTS AMI( ami- a299443cb, 但我尝试过其他几个没有用的东西) 通过 boto s ec2.run_ instances (..., user_ data=USER_ DATA) 输入 Ubuntu 12. 04 LTS AMI( ami- a299443cb, 但我尝试过几个其他方法, 但没有用 ) 。 同样, 在通过 AWS 控制台启动实例时, 我手动提供用户数据也没有成功 。 在 / var/logs/ Syslogslog / Syslog 中, 我尝试过的任何方法都没有结果或信息 。

USER_DATA 看起来像以下内容,从文件读成字符串 :

#!/usr/bin/env python

import boto

AWS_BOOTSTRAP_BUCKET  =   
AWS_ACCESS_KEY_ID     =   
AWS_SECRET_ACCESS_KEY =   

# Pull processing script from S3.
print  Bootstrapping started..... 
print  Connecting to S3... 
s3     = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = s3.get_bucket(AWS_BOOTSTRAP_BUCKET)
print  Downloading bootstrap file... 
key    = bucket.get_key( xxx )
key.get_contents_to_filename( xxx )

print  Importing Bootstrap file... 
import xxx
xxx.process()

# Shut down the EC2 instance running this process.
print  Shutting down this instance... 
import socket
desired_hostname = socket.gethostname()
ec2 = boto.connect_ec2(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
reservations = ec2.get_all_instances()
for reservation in reservations:
    for instance in reservation.instances:
        if desired_hostname in instance.private_dns_name:
            instance.terminate()

我还尝试将档案上载到一个公众S3桶上,并以这种方式装载,但还是徒劳无益:

#include
https://s3.amazonaws.com/bucket/file.py

是否有人在这方面有什么建议? 我完全误解了用户数据/库卢德-尼特的目的吗? 还是我试图使用的AMI中的技术仅仅是故障了?

最佳回答

很难知道发生了什么,没有错误信息, 但有一些地方你可以看:

  1. The file /var/log/cloud-init.log will usually contain any errors (e.g. boto import failure) that occurred during instance bootstrapping.
  2. The directory /var/lib/cloud/instance will contain the raw scripts and user-data downloaded to the instance
  3. You can View/Edit USER_DATA inside the AWS console by right-clicking the instance, to see if boto populated it correctly.

对这些地方的考察应有助于澄清问题。

我知道Ubuntu 12.04 与boto 2.2.2:

root@vanilla-562c:/var/lib/cloud/instance# python
Python 2.7.3 (default, Apr 20 2012, 22:44:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> boto.__version__
 2.2.2 

但我想知道它是否在运行时 在你的PYTHONPATH实际上可以进入。

问题回答

快速核对表 :

1 ) SSH into your instance.
2 ) Run cat on /var/log/cloud-init-output.log and dump it into a nice text file.
3 ) You ll see multiple block which contains the structure below:

Dependencies Resolved

================================================================================
 Package                    Arch      Version               Repository     Size
================================================================================
Installing:


Transaction Summary
================================================================================
Install  X Package (+Y Dependent packages)

每个区块都是根据您提供给 EC2 实例的 < code> 用户数据 (所有脚本都存储在 < code>/ var/lib/ cloud/ Instentance/ scrips 下) 创建的。

4) 查找关键词,如 failed , Error , WARNINing /var/lib/cloud/introud/intround/introps/products/

例如,在出现以下错误的情况下:

/var/lib/cloud/instance/scripts/part-001: line 10: vncpasswd: command not found
cp: cannot stat  /lib/systemd/system/[email protected] : No such file or directory
sed: can t read /etc/systemd/system/[email protected]: No such file or directory
Failed to execute operation: No such file or directory
Failed to start vncserver@:1.service: Unit not found.
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel

(*) 您可以快速查看 /var/log/cloud-init-output.log /var/log/cloud-init.log 的结尾,其中含有一般错误信息,可以告知您在执行 < 强用户数据 < /强者 > 脚本时发生了错误。

以上错误 /var/log/cloud-init-output.log 结尾处:

Is this ok [y/d/N]: Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2020-08-31.15-14.VpTvV1.yumtx
Aug 31 15:14:00 cloud-init[3532]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Aug 31 15:14:00 cloud-init[3532]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Aug 31 15:14:00 cloud-init[3532]: util.py[WARNING]: Running module scripts-user (<module  cloudinit.config.cc_scripts_user  from  /usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc >) failed
Cloud-init v. 19.3-3.amzn2 finished at Mon, 31 Aug 2020 15:14:00 +0000. Datasource DataSourceEc2.  Up 87.44 seconds

/var/log/cloud-init.log 的结尾处:

Aug 31 15:14:00 cloud-init[3532]: util.py[DEBUG]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
    Traceback (most recent call last):
      File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 910, in runparts
        subp(prefix + [exe_path], capture=False, shell=True)
      File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 2105, in subp
        cmd=args)
    ProcessExecutionError: Unexpected error while running command.
    Command: [ /var/lib/cloud/instance/scripts/part-001 ]
    Exit code: 1
    Reason: -
    Stdout: -
    Stderr: -
    cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签