gpt4 book ai didi

amazon-web-services - AWS Cloudformation 用户数据问题

转载 作者:行者123 更新时间:2023-12-05 04:01:52 25 4
gpt4 key购买 nike

我在启动传递用户数据的云信息模板时遇到问题。好像里面没有运行任何命令。实例无需运行这些命令即可正常运行。请帮忙解决。

AWSTemplateFormatVersion : 2010-09-09
Description: sonar
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
KeyName: sivakey_feb
ImageId: ami-04bfee437f38a691e
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
sudo chown -R ec2-user:ec2-user /opt/sonar/temp/conf
/opt/sonar/bin/linux-x86-64/sonar.sh start
InstanceType: t2.large
Tags:
-
Key: Name
Value: sonar

最佳答案

所以我看不出你的脚本有什么问题。但我建议采取以下行动;

  1. 脚本的可执行标志,因此

    chmod +x /opt/sonar/bin/linux-x86-64/sonar.sh
  2. 出于调试目的,添加以下行

    exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

所以你的用户数据应该是这样的;

    #!/bin/bash -xe
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
sudo chown -R ec2-user:ec2-user /opt/sonar/temp/conf
chmod +x /opt/sonar/bin/linux-x86-64/sonar.sh
/opt/sonar/bin/linux-x86-64/sonar.sh start

附加行取自 aws docs ;

To troubleshoot issues on your EC2 instance bootstrap without having to access the instance through SSH, you can add code to your user-data bash script that redirects all the output both to the /var/log/user-data.log and to /dev/console. When the code is executed, you can see your user-data invocation logs in your console.

关于amazon-web-services - AWS Cloudformation 用户数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54906764/

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