gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:09:45 24 4
gpt4 key购买 nike

我正在设置新的 EC2 实例,并且我希望能够看到 hello world、显示的可用区和 IP 地址。它只显示 apache 起始页。

我已在 EC2 的用户启动部分、高级详细信息、用户数据中预加载了下面列出的代码,并单击并选择了“添加为文本”。

我从 udemy 的培训视频中复制了这段文字,Stephane Maarek 的 2019 年终极 AWS 认证解决方案架构师助理,第 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

我只是获取 apache 起始页,而不是 hello world 和用户元数据信息。谢谢,我才刚刚开始,对于任何错误我深表歉意

最佳答案

将 html 回显到 index.html 时,您没有关闭双引号。尝试以下方法。

#!/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

关于linux - 如何修复 aws ec2 的启动脚本,以显示 hello world,来自 169.254.169.254 的其他元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56924577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com