在Linux EC2实例启动上未运行的命令

时间:2018-08-18 06:00:05

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

我有一个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错误的网关状态代码,然后ssh进入实例,手动运行命令,然后按预期方式获取apache页面。

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

非常感谢您的协助!

1 个答案:

答案 0 :(得分:0)

我在一个实例上运行了您的用户数据,并且其中包含/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