用户数据不在启动AWS EC2上运行

时间:2019-02-09 14:33:37

标签: linux amazon-web-services amazon-ec2

我正在尝试启动ec2 linux实例(linux 2 ami),并在用户数据中执行此操作时, 安装Node js,并同时安装git。 然后,我试图克隆我的github存储库,然后启动node js服务器,所有这些工作都在userdata中完成。

我正在尝试检查cloudlog初始化文件中的所有地方,以查找为什么我的用户数据无法正常工作的错误。

这里是代码。

#!/bin/bash
sudo yum update -y
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash 
. ~/.nvm/nvm.sh
nvm install 4.4.5
sudo yum upgrade
sudo yum install git -y
git clone https://github.com/myname/one_user.git
cd one_user

dnsaddress=$(curl -s http://169.254.169.254/latest/meta-data/public-hostname)
export dns_name=${dnsaddress}
npm install -y
node server.js

下面的代码来自云初始化日志文件。

Cloud-init v. 18.2-72.amzn2.0.6 running 'init-local' at Sun, 10 Feb 2019 15:49:35 +0000. Up 4.93 seconds.
Cloud-init v. 18.2-72.amzn2.0.6 running 'init' at Sun, 10 Feb 2019 15:49:38 +0000. Up 7.42 seconds.
ci-info: ++++++++++++++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++++++++++++++
ci-info: +--------+------+-----------------------------+---------------+--------+-------------------+
ci-info: | Device |  Up  |           Address           |      Mask     | Scope  |     Hw-Address    |
ci-info: +--------+------+-----------------------------+---------------+--------+-------------------+
ci-info: |  eth0  | True |          10.0.1.72          | 255.255.255.0 | global | 0e:1f:76:6a:3c:6c |
ci-info: |  eth0  | True | fe80::c1f:76ff:fe6a:3c6c/64 |       .       |  link  | 0e:1f:76:6a:3c:6c |
ci-info: |   lo   | True |          127.0.0.1          |   255.0.0.0   |  host  |         .         |
ci-info: |   lo   | True |           ::1/128           |       .       |  host  |         .         |
ci-info: +--------+------+-----------------------------+---------------+--------+-------------------+
ci-info: ++++++++++++++++++++++++++++++Route IPv4 info+++++++++++++++++++++++++++++++
ci-info: +-------+-----------------+----------+-----------------+-----------+-------+
ci-info: | Route |   Destination   | Gateway  |     Genmask     | Interface | Flags |
ci-info: +-------+-----------------+----------+-----------------+-----------+-------+
ci-info: |   0   |     0.0.0.0     | 10.0.1.1 |     0.0.0.0     |    eth0   |   UG  |
ci-info: |   1   |     10.0.1.0    | 0.0.0.0  |  255.255.255.0  |    eth0   |   U   |
ci-info: |   2   | 169.254.169.254 | 0.0.0.0  | 255.255.255.255 |    eth0   |   UH  |
ci-info: +-------+-----------------+----------+-----------------+-----------+-------+
ci-info: +++++++++++++++++++Route IPv6 info+++++++++++++++++++
ci-info: +-------+-------------+---------+-----------+-------+
ci-info: | Route | Destination | Gateway | Interface | Flags |
ci-info: +-------+-------------+---------+-----------+-------+
ci-info: |   9   |  fe80::/64  |    ::   |    eth0   |   U   |
ci-info: |   11  |    local    |    ::   |    eth0   |   U   |
ci-info: |   12  |   ff00::/8  |    ::   |    eth0   |   U   |
ci-info: +-------+-------------+---------+-----------+-------+
Cloud-init v. 18.2-72.amzn2.0.6 running 'modules:config' at Sun, 10 Feb 2019 15:49:39 +0000. Up 8.99 seconds.
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Existing lock /var/run/yum.pid: another copy is running as pid 3265.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  31 M RSS (321 MB VSZ)
    Started: Sun Feb 10 15:49:38 2019 - 00:02 ago
    State  : Sleeping, pid: 3265
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  70 M RSS (361 MB VSZ)
    Started: Sun Feb 10 15:49:38 2019 - 00:04 ago
    State  : Running, pid: 3265
 --> 1:openssl-libs-1.0.2k-16.amzn2.0.1.x86_64 from installed removed (updateinfo)
 --> 1:openssl-1.0.2k-16.amzn2.0.1.x86_64 from installed removed (updateinfo)
 --> 1:openssl-libs-1.0.2k-16.amzn2.0.2.x86_64 from amzn2-core removed (updateinfo)
 --> 1:openssl-1.0.2k-16.amzn2.0.2.x86_64 from amzn2-core removed (updateinfo)
1 package(s) needed (+0 related) for security, out of 3 available
Resolving Dependencies
--> Running transaction check
---> Package kernel-tools.x86_64 0:4.14.88-88.76.amzn2 will be updated
---> Package kernel-tools.x86_64 0:4.14.94-89.73.amzn2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch        Version                    Repository       Size
================================================================================
Updating:
 kernel-tools      x86_64      4.14.94-89.73.amzn2        amzn2-core      111 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 111 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : kernel-tools-4.14.94-89.73.amzn2.x86_64                      1/2 
  Cleanup    : kernel-tools-4.14.88-88.76.amzn2.x86_64                      2/2 
  Verifying  : kernel-tools-4.14.94-89.73.amzn2.x86_64                      1/2 
  Verifying  : kernel-tools-4.14.88-88.76.amzn2.x86_64                      2/2 

Updated:
  kernel-tools.x86_64 0:4.14.94-89.73.amzn2                                     

Complete!
Cloud-init v. 18.2-72.amzn2.0.6 running 'modules:final' at Sun, 10 Feb 2019 15:49:47 +0000. Up 16.22 seconds.
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Existing lock /var/run/yum.pid: another copy is running as pid 3324.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  54 M RSS (270 MB VSZ)
    Started: Sun Feb 10 15:49:45 2019 - 00:03 ago
    State  : Running, pid: 3324
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:4.14.94-89.73.amzn2 will be installed
---> Package openssl.x86_64 1:1.0.2k-16.amzn2.0.1 will be updated
---> Package openssl.x86_64 1:1.0.2k-16.amzn2.0.2 will be an update
---> Package openssl-libs.x86_64 1:1.0.2k-16.amzn2.0.1 will be updated
---> Package openssl-libs.x86_64 1:1.0.2k-16.amzn2.0.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch        Version                    Repository       Size
================================================================================
Installing:
 kernel            x86_64      4.14.94-89.73.amzn2        amzn2-core       19 M
Updating:
 openssl           x86_64      1:1.0.2k-16.amzn2.0.2      amzn2-core      496 k
 openssl-libs      x86_64      1:1.0.2k-16.amzn2.0.2      amzn2-core      1.2 M

Transaction Summary
================================================================================
Install  1 Package
Upgrade  2 Packages

Total download size: 21 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
--------------------------------------------------------------------------------
Total                                               33 MB/s |  21 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:openssl-libs-1.0.2k-16.amzn2.0.2.x86_64                    1/5 
  Updating   : 1:openssl-1.0.2k-16.amzn2.0.2.x86_64                         2/5 
  Installing : kernel-4.14.94-89.73.amzn2.x86_64                            3/5 
  Cleanup    : 1:openssl-1.0.2k-16.amzn2.0.1.x86_64                         4/5 
  Cleanup    : 1:openssl-libs-1.0.2k-16.amzn2.0.1.x86_64                    5/5 
  Verifying  : 1:openssl-libs-1.0.2k-16.amzn2.0.2.x86_64                    1/5 
  Verifying  : kernel-4.14.94-89.73.amzn2.x86_64                            2/5 
  Verifying  : 1:openssl-1.0.2k-16.amzn2.0.2.x86_64                         3/5 
  Verifying  : 1:openssl-libs-1.0.2k-16.amzn2.0.1.x86_64                    4/5 
  Verifying  : 1:openssl-1.0.2k-16.amzn2.0.1.x86_64                         5/5 

Installed:
  kernel.x86_64 0:4.14.94-89.73.amzn2                                           

Updated:
  openssl.x86_64 1:1.0.2k-16.amzn2.0.2                                          
  openssl-libs.x86_64 1:1.0.2k-16.amzn2.0.2                                     

Complete!
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10007  100 10007    0     0  10007      0  0:00:01 --:--:--  0:00:01 99079
=> Downloading nvm as script to '/.nvm'

=> Profile not found. Tried  (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
=> Create it (touch ) and run this script again
   OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
/var/lib/cloud/instance/scripts/part-001: line 4: /root/.nvm/nvm.sh: No such file or directory
/var/lib/cloud/instance/scripts/part-001: line 5: nvm: command not found
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Existing lock /var/run/yum.pid: another copy is running as pid 11772.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  52 M RSS (268 MB VSZ)
    Started: Sun Feb 10 15:50:08 2019 - 00:02 ago
    State  : Running, pid: 11772
No packages marked for update
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:2.17.2-2.amzn2 will be installed
--> Processing Dependency: perl-Git = 2.17.2-2.amzn2 for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: git-core-doc = 2.17.2-2.amzn2 for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: git-core = 2.17.2-2.amzn2 for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: emacs-filesystem >= 25.3 for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: perl(Git::I18N) for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: perl(Git) for package: git-2.17.2-2.amzn2.x86_64
--> Processing Dependency: libsecret-1.so.0()(64bit) for package: git-2.17.2-2.amzn2.x86_64
--> Running transaction check
---> Package emacs-filesystem.noarch 1:25.3-3.amzn2.0.1 will be installed
---> Package git-core.x86_64 0:2.17.2-2.amzn2 will be installed
---> Package git-core-doc.noarch 0:2.17.2-2.amzn2 will be installed
---> Package libsecret.x86_64 0:0.18.5-2.amzn2.0.2 will be installed
---> Package perl-Git.noarch 0:2.17.2-2.amzn2 will be installed
--> Processing Dependency: perl(Error) for package: perl-Git-2.17.2-2.amzn2.noarch
---> Package perl-TermReadKey.x86_64 0:2.30-20.amzn2.0.2 will be installed
--> Running transaction check
---> Package perl-Error.noarch 1:0.17020-2.amzn2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch       Version                   Repository      Size
================================================================================
Installing:
 git                  x86_64     2.17.2-2.amzn2            amzn2-core     217 k
Installing for dependencies:
 emacs-filesystem     noarch     1:25.3-3.amzn2.0.1        amzn2-core      64 k
 git-core             x86_64     2.17.2-2.amzn2            amzn2-core     4.0 M
 git-core-doc         noarch     2.17.2-2.amzn2            amzn2-core     2.3 M
 libsecret            x86_64     0.18.5-2.amzn2.0.2        amzn2-core     153 k
 perl-Error           noarch     1:0.17020-2.amzn2         amzn2-core      32 k
 perl-Git             noarch     2.17.2-2.amzn2            amzn2-core      70 k
 perl-TermReadKey     x86_64     2.30-20.amzn2.0.2         amzn2-core      31 k

Transaction Summary
================================================================================
Install  1 Package (+7 Dependent packages)

Total download size: 6.8 M
Installed size: 36 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               18 MB/s | 6.8 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : git-core-2.17.2-2.amzn2.x86_64                               1/8 
  Installing : git-core-doc-2.17.2-2.amzn2.noarch                           2/8 
  Installing : libsecret-0.18.5-2.amzn2.0.2.x86_64                          3/8 
  Installing : 1:perl-Error-0.17020-2.amzn2.noarch                          4/8 
  Installing : perl-TermReadKey-2.30-20.amzn2.0.2.x86_64                    5/8 
  Installing : 1:emacs-filesystem-25.3-3.amzn2.0.1.noarch                   6/8 
  Installing : perl-Git-2.17.2-2.amzn2.noarch                               7/8 
  Installing : git-2.17.2-2.amzn2.x86_64                                    8/8 
  Verifying  : 1:emacs-filesystem-25.3-3.amzn2.0.1.noarch                   1/8 
  Verifying  : perl-TermReadKey-2.30-20.amzn2.0.2.x86_64                    2/8 
  Verifying  : 1:perl-Error-0.17020-2.amzn2.noarch                          3/8 
  Verifying  : libsecret-0.18.5-2.amzn2.0.2.x86_64                          4/8 
  Verifying  : git-core-2.17.2-2.amzn2.x86_64                               5/8 
  Verifying  : git-2.17.2-2.amzn2.x86_64                                    6/8 
  Verifying  : perl-Git-2.17.2-2.amzn2.noarch                               7/8 
  Verifying  : git-core-doc-2.17.2-2.amzn2.noarch                           8/8 

Installed:
  git.x86_64 0:2.17.2-2.amzn2                                                   

Dependency Installed:
  emacs-filesystem.noarch 1:25.3-3.amzn2.0.1                                    
  git-core.x86_64 0:2.17.2-2.amzn2                                              
  git-core-doc.noarch 0:2.17.2-2.amzn2                                          
  libsecret.x86_64 0:0.18.5-2.amzn2.0.2                                         
  perl-Error.noarch 1:0.17020-2.amzn2                                           
  perl-Git.noarch 0:2.17.2-2.amzn2                                              
  perl-TermReadKey.x86_64 0:2.30-20.amzn2.0.2                                   

Complete!
Cloning into 'zero2architect'...
/var/lib/cloud/instance/scripts/part-001: line 16: npm: command not found
/var/lib/cloud/instance/scripts/part-001: line 17: node: command not found
Feb 10 15:50:16 cloud-init[3314]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [127]
Feb 10 15:50:16 cloud-init[3314]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Feb 10 15:50:16 cloud-init[3314]: 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. 18.2-72.amzn2.0.6 finished at Sun, 10 Feb 2019 15:50:16 +0000. Datasource DataSourceEc2.  Up 45.55 seconds

1 个答案:

答案 0 :(得分:0)

您是否检查了SG和NACL配置?您需要在出站SG规则中允许端口80(HTTP)和端口443(HTTPS)-目标0.0.0.0/0。您还需要在出站NACL规则和入站规则上的临时端口上允许相同。确保您的实例位于公共子网(具有到IGW的路由)中,并且已附加有公共/弹性IPv4。

如果不满足这些条件中的任何一个,您的用户数据脚本将失败,因为它需要连接到Internet(在您的情况下)。

如果您的实例位于专用子网中,请确保您正在运行NAT网关或NAT实例,并且已正确配置了路由表以及SG和NACL。另外,请确保在使用NAT实例时禁用了源/目标检查。

更新

您的日志清楚地表明您尚未安装npmnode,因此还需要将安装说明传递给脚本。

npm install -y

不是安装npm的正确方法。您可以按照以下步骤安装nodenpm

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

. ~/.nvm/nvm.sh

nvm install 4.4.5

这将安装节点版本4.4.5。如果要安装其他版本的节点,请更改受支持版本的编号。

相关问题