ec2 centos用户数据未运行

时间:2018-12-10 21:33:12

标签: amazon-ec2 centos amazon-cloudformation ec2-ami

我正在尝试在实例启动时使用userdata通过centos ec2实例在Rails应用程序上部署ruby,指定图像是centos 7图像。以下是我的userdata部分。但是,当我将每个命令输出通过管道传输到日志时,userdata无法正常工作,甚至没有创建日志文件。是否有人对此有任何见解或如何对ec2用户数据进行故障排除?我也查看了/ var / logs中的cloud-init.log文件,但无法确定实际运行了哪个命令,而哪个没有运行,我也包括了下面日志中的最后几行。任何帮助表示感谢,谢谢!

#!/bin/bash
sudo yum update -y | tee -a log.txt
sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 | tee -a /home/ec2-user/log.txt
curl -sSL https://get.rvm.io | sudo bash -s stable | tee -a /home/ec2-user/log.txt
sudo usermod -a -G rvm `whoami` | tee -a /home/ec2-user/log.txt
if sudo grep -q secure_path /etc/sudoers; then sudo sh -c "echo export rvmsudo_secure_path=1 >> /etc/profile.d/rvm_secure_path.sh" && echo Environment variable installed; fi | & tee -a log.txt
sudo su ec2-user
rvm install ruby | tee -a /home/ec2-user/log.txt
rvm --default use ruby | tee -a /home/ec2-user/log.txt
curl -sL https://rpm.nodesource.com/setup_11.x | sudo -E bash - | tee -a /home/ec2-user/log.txt
sudo yum install -y nodejs | tee -a /home/ec2-user/log.txt
sudo yum -y install ImageMagick-devel | tee -a /home/ec2-user/log.txt
sudo yum -y upgrade | tee -a /home/ec2-user/log.txt
sudo yum -y install git | tee -a /home/ec2-user/log.txt
sudo yum -y install java-1.8.0-openjdk | tee -a log.txt
export JAVA_HOME="/usr/lib/jvm/jre-1.8.0-openjdk" | tee -a /home/ec2-user/log.txt
export PATH=$JAVA_HOME/bin:$PATH | tee -a /home/ec2-user/log.txt
sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs | tee -a /home/ec2-user/log.txt
rails new app-name -m https://raw.githubusercontent.com/projectblacklight/spotlight/master/template.rb | tee -a /home/ec2-user/log.txt
cd app-name
rake db:migrate | tee -a /home/ec2-user/log.txt
solr_wrapper | tee -a /home/ec2-user/log.txt
rails server | tee -a /home/ec2-user/log.txt

cloud-init.log

2018-12-10 16:24:43,554 - util.py[DEBUG]: Cloud-init v. 0.7.9 finished at Mon, 10 Dec 2018 21:24:43 +0000. Datasource DataSourceEc2.  Up 735.81 seconds
2018-12-10 16:24:43,554 - util.py[DEBUG]: Writing to /var/lib/cloud/instance/boot-finished - wb: [420] 52 bytes
2018-12-10 16:24:43,555 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/i-0b323a8331354129b/boot-finished (recursive=False)
2018-12-10 16:24:43,555 - util.py[DEBUG]: Restoring selinux mode for /var/lib/cloud/instances/i-0b323a8331354129b/boot-finished (recursive=False)
2018-12-10 16:24:43,556 - handlers.py[DEBUG]: finish: modules-final/config-final-message: SUCCESS: config-final-message ran successfully
2018-12-10 16:24:43,556 - main.py[DEBUG]: Ran 9 modules with 1 failures
2018-12-10 16:24:43,565 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/result.json' => '../../var/lib/cloud/data/result.json'
2018-12-10 16:24:43,566 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
2018-12-10 16:24:43,566 - util.py[DEBUG]: Read 14 bytes from /proc/uptime
2018-12-10 16:24:43,566 - util.py[DEBUG]: cloud-init mode 'modules' took 687.571 seconds (687.57)
2018-12-10 16:24:43,566 - handlers.py[DEBUG]: finish: modules-final: FAIL: running modules for final

1 个答案:

答案 0 :(得分:0)

CloudFormation?您还记得用Base64编码用户数据吗?

  EventCollectionLc:
    Type: 'AWS::AutoScaling::LaunchConfiguration'
    Properties:
      UserData: !Base64 
        'Fn::Sub': |
          #!/bin/bash