简体   繁体   English

如何修复 aws ec2 的启动脚本,以显示 hello world 和来自 169.254.169.254 的其他元数据

[英]how to fix startup script for aws ec2, to display hello world, other meta data from 169.254.169.254

I am setting up new EC2 instances, and I want to be able to see hello world, the AZ and the IP address displayed.我正在设置新的 EC2 实例,我希望能够看到 hello world、AZ 和显示的 IP 地址。 It only shows the apache start page.它只显示 apache 起始页。

I have preloaded the code listed below in the user startup section of EC2, in the advanced details, user data, and have "added as text" clicked and selected.我已经在 EC2 的用户启动部分、高级详细信息、用户数据中预加载了下面列出的代码,并单击并选择了“添加为文本”。

I copied this text off of a training video from udemy, Ultimate AWS Certified Solutions Architect Associate 2019 by Stephane Maarek, Lesson 60, rt53 EC2 setup at approx the 1:11 mark.我从 Stephane Maarek 的 udemy,Ultimate AWS Certified Solutions Architect Associate 2019,第 60 课,rt53 EC2 设置中以大约 1:11 标记复制了此文本。

#!/bin/bash
  yum update -y
  yum install -y httpd
  systemctl start httpd.service
  systemctl enable httpd.service
  EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
  echo "<h1>Hello World From Rokkitt at $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1> > /var/www/html/index.html

I am just getting the apache start page, not the hello world and user meta data info.我只是获取 apache 起始页,而不是 hello world 和用户元数据信息。 thank you, I am just starting so I apologize for any mistakes谢谢,我刚刚开始,所以我为任何错误道歉

You aren't closing your double quotes when echoing html into the index.html.将 html 回显到 index.html 时,您没有关闭双引号。 Try the below.试试下面的。

#!/bin/bash
  yum update -y
  yum install -y httpd
  systemctl start httpd.service
  systemctl enable httpd.service
  EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
  echo "<h1>Hello World From Rokkitt at at $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1>” > /var/www/html/index.html

ok, thank you ...好的谢谢 ...

after carefully looking, I missed the closing quote as stated above.仔细查看后,我错过了上述结束语。 thanks!谢谢! also, I spent time making sure the index.html file was present with the cat command with the string /var/www/html/index.html and it showed me the contents of that file.此外,我还花时间确保 index.html 文件与带有字符串 /var/www/html/index.html 的 cat 命令一起存在,它向我显示了该文件的内容。 thank you again!再次感谢你!

also, I set up my nacl and security group and internet gateway IGW to allow icmp traffic so I could ping the instance as well.此外,我设置了我的 nacl 和安全组以及互联网网关 IGW 以允许 icmp 流量,因此我也可以 ping 实例。

thanks!谢谢!

1082 1082

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM