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

Linux EC2实例启动上未运行的命令,linux,bash,amazon-web-services,amazon-ec2,startup,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

我有一个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页面

我在跟踪调查 ,之后,我还将index.php添加到/var/www/html。 我在手动运行命令时得到了预期的结果,但在使用实例设置用户数据时却没有得到预期的结果,我做错了什么或遗漏了什么


非常感谢您的帮助

我在一个实例上运行了您的用户数据,并且
/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
标记安装:Web服务器、MySQL数据库、PHP支持
httpd:无法识别的服务
读取服务httpd上的信息时出错:没有这样的文件或目录
usermod:组“apache”不存在
chown:无法访问“/var/www”:没有这样的文件或目录
chown:无效组:“ec2用户:apache”
chmod:无法访问“/var/www”:没有这样的文件或目录
查找:`/var/www”:没有这样的文件或目录
查找:`/var/www”:没有这样的文件或目录
Aug 18 06:38:38 cloud init[2638]:util.py[警告]:无法运行/var/lib/cloud/instance/scripts/part-001[1]
Aug 18 06:38:38 cloud init[2638]:cc_scripts_user.py[警告]:无法运行模块脚本用户(在/var/lib/cloud/instance/scripts中的脚本)
Aug 18 06:38:38 cloud init[2638]:util.py[警告]:运行模块脚本用户()失败
云初始化v。0.7.6于2018年8月18日周六06:38:38+0000完成。数据源数据源EC2。上升16.54秒

能否从实例粘贴
/var/log/cloud init output.log
的输出?这将记录启动过程中的任何错误。您使用的是
amazonlinux2
还是
amazonlinux2
AMI?@JohnRotenstein-amazonlinuxstack-Overflow是一个关于编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参见帮助中心中的。也许或者会是一个更好的提问的地方。谢谢@jww,如果有必要,我可以把这个问题转移到那里。脚本不在开发中吗?感谢@John Rotenstein,添加此用户数据的实例是从已经安装了httpd的AMI创建的。我还将尝试向用户数据中添加http install命令,谢谢John。