【问题标题】:Commands not running on Linux EC2 instance launch未在 Linux EC2 实例启动上运行的命令
【发布时间】:2018-08-18 14:46:16
【问题描述】:

我有一个 AWS EC2 Linux 实例,其中用户数据设置如下:

#!/bin/bash
yum update -y
yum group mark install -y "Web Server" "MySQL Database" "PHP Support"
service httpd start
chkconfig httpd on
groupadd www
usermod -a -G www ec2-user
usermod -a -G apache ec2-user
chown -R root:www /var/www
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;

期望的目标是在通过负载均衡器调用实例时获取 apache 页面,但是当实例启动时,我得到一个 502 bad gateway 状态代码,然后我 ssh 进入实例手动运行命令,然后我按预期获取 apache 页面。

我正在关注linkedlearning aws essential training ,跟着aws docs,我还在/var/www/html 中添加了一个index.php。 我在手动运行命令时得到了预期的结果,但在使用实例设置用户数据时却没有,我做错了什么或遗漏了什么?

非常感谢您的帮助!

【问题讨论】:

  • 您可以从实例中粘贴您的/var/log/cloud-init-output.log 的输出吗?这应该会记录启动过程中的所有错误。
  • 您使用的是Amazon Linux 2 还是Amazon Linux AMI?
  • @JohnRotenstein Amazon Linux
  • Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Server FaultWebmaster Stack Exchange 会是一个更好的提问地点。
  • 谢谢@jww,如有必要,我可以将这个问题移到那里。脚本不是正在开发中吗?

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


【解决方案1】:

我在一个实例上运行了您的用户数据,并包含 /var/log/cloud-init-output.log 文件:

Marked install: Web Server,MySQL Database,PHP Support
httpd: unrecognized service
error reading information on service httpd: No such file or directory
usermod: group 'apache' does not exist
chown: cannot access ‘/var/www’: No such file or directory
chown: invalid group: ‘ec2-user:apache’
chmod: cannot access ‘/var/www’: No such file or directory
find: `/var/www': No such file or directory
find: `/var/www': No such file or directory
Aug 18 06:38:38 cloud-init[2638]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Aug 18 06:38:38 cloud-init[2638]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Aug 18 06:38:38 cloud-init[2638]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 0.7.6 finished at Sat, 18 Aug 2018 06:38:38 +0000. Datasource DataSourceEc2.  Up 16.54 seconds

【讨论】:

  • 感谢@John Rotenstein,添加此用户数据的实例是从已安装 httpd 的 AMI 创建的。我将尝试将 http install 命令添加到用户数据中,感谢 John。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-13
  • 1970-01-01
  • 2014-11-25
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多