简体   繁体   English

使用 EB Extensions 在 Amazon Linux 2 上运行包安装命令

[英]Run Packages Installation Commands on Amazon Linux 2 using EB Extensions

I'm running ASP.NET Core 3.1 Application on Elastic Beanstalk with Amazon Linux 2 EC2 instances.我正在使用 Amazon Linux 2 EC2 实例在 Elastic Beanstalk 上运行 ASP.NET Core 3.1 应用程序。 I need my app to be able to generate QR codes and for this I'm using QRCoder library.我需要我的应用程序能够生成 QR 码,为此我正在使用 QRCoder 库。 It worked on my Windows machine out of the box, but to make it work on Amazon Linux 2 machine I had to run the following commands via SSH:它开箱即用地在我的 Windows 机器上运行,但要使其在 Amazon Linux 2 机器上运行,我必须通过 SSH 运行以下命令:

sudo amazon-linux-extras install epel
sudo yum install libgdiplus

After running these commands EB app servers also need to be restarted for image generation to work.运行这些命令后,EB 应用程序服务器也需要重新启动才能生成图像。

I tried to script it by creating .ebextensions/install_gdi.config file in my application repo root directory with the following contents:我试图通过在我的应用程序 repo 根目录中创建包含以下内容的.ebextensions/install_gdi.config文件来编写脚本:

commands:
  00_install_extras:
    command: amazon-linux-extras install -y epel
  01_install_gdi:
    command: yum install -y libgdiplus

I rebuilt my Beanstalk environment to have fresh EC2 instances redeployed version, and it seems that EB extensions config file isn't doing anything.我重建了我的 Beanstalk 环境以拥有新的 EC2 实例重新部署版本,似乎 EB 扩展配置文件没有做任何事情。 Images still cannot be generated until I connect via SSH and run those command manually on EC2 instance.在我通过 SSH 连接并在 EC2 实例上手动运行这些命令之前,仍然无法生成图像。

I read that there are alternative ways to automate instance provisioning for Amazon Linux 2 but I wasn't able to find good examples to explore things like pre deployment hooks and Buildfile and it also seems that EB extensions is the right tool for the job in this case.我读到有其他方法可以为 Amazon Linux 2 自动配置实例,但我无法找到很好的示例来探索预部署挂钩和 Buildfile 之类的东西,而且 EB 扩展似乎也是这项工作的正确工具案件。

My application is deployed to Elastic Beanstalk using AWS CodePipeline, which is hooked to a GitHub repo.我的应用程序使用 AWS CodePipeline 部署到 Elastic Beanstalk,它连接到 GitHub 存储库。

I tried to replicate the issue on EB with Amazon Linux 2, but your commands worked perfectly fine.我尝试使用 Amazon Linux 2 在 EB 上复制该问题,但您的commands运行良好。 I used Python platform, not .NET, but since both are based on AL2 I don't see why would they be different in this aspect.我使用的是 Python 平台,而不是 .NET,但由于两者都基于 AL2,所以我不明白为什么它们在这方面会有不同。

To troubleshoot , you can ssh into your EB instance, or download EB logs from console and inspect /var/log/cfn-init-cmd.log .排除故障,您可以 ssh 进入您的 EB 实例,或从控制台下载 EB 日志并检查/var/log/cfn-init-cmd.log It should have details regarding install_gdi.config execution.它应该包含有关install_gdi.config执行的详细信息。

For comparision, I attach my output:为了比较,我附上我的 output:

2020-08-30 05:34:52,631 P3617 [INFO] Command 01_install_gdi
2020-08-30 05:35:08,423 P3617 [INFO] -----------------------Command Output-----------------------
2020-08-30 05:35:08,423 P3617 [INFO]    Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
2020-08-30 05:35:08,423 P3617 [INFO]    http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: [Errno 12] Timeout on http://csc.mcs.sdsmt.edu/epel/7/x86_64/repodata/0e811d5e2eb547161695f97c2fb8c2eaa0ccfe0ba7125321404db90dab5af5b3-updateinfo.xml.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 5 seconds')
2020-08-30 05:35:08,423 P3617 [INFO]    Trying other mirror.
2020-08-30 05:35:08,423 P3617 [INFO]    200 packages excluded due to repository priority protections
2020-08-30 05:35:08,423 P3617 [INFO]    Resolving Dependencies
2020-08-30 05:35:08,424 P3617 [INFO]    --> Running transaction check
2020-08-30 05:35:08,424 P3617 [INFO]    ---> Package libgdiplus.x86_64 0:2.10-10.el7 will be installed
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libXrender.so.1()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libcairo.so.2()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libexif.so.12()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
2020-08-30 05:35:08,424 P3617 [INFO]    --> Processing Dependency: libgif.so.4()(64bit) for package: libgdiplus-2.10-10.el7.x86_64
#
# more logs
#
2020-08-30 05:35:08,433 P3617 [INFO]
2020-08-30 05:35:08,433 P3617 [INFO]    Installed:
2020-08-30 05:35:08,434 P3617 [INFO]      libgdiplus.x86_64 0:2.10-10.el7
2020-08-30 05:35:08,434 P3617 [INFO]
#
# more logs
#
2020-08-30 05:35:08,435 P3617 [INFO]    Complete!
2020-08-30 05:35:08,435 P3617 [INFO] ------------------------------------------------------------
2020-08-30 05:35:08,435 P3617 [INFO] Completed successfully.

The problem was with my buildspec.yml file.问题出在我的buildspec.yml文件上。

It used to look like this and it didn't include .ebxtensions folder into the publish artifact folder:它曾经看起来像这样,并且没有将.ebxtensions文件夹包含到发布工件文件夹中:

version: 0.2

phases:
  build:
    commands:
      - dotnet publish WebApi.csproj -c Release
artifacts:
  files:
    - bin/Release/netcoreapp3.1/publish/*
  discard-paths: yes

I changed it to look like this and it works now:我将其更改为如下所示,现在可以使用了:

version: 0.2

phases:
  build:
    commands:
      - dotnet publish WebApi.csproj -c Release
artifacts:
  files:
    - '**/*'
  base-directory: bin/Release/netcoreapp3.1/publish

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

相关问题 从 AWS EB Linux 实例运行 manage.py - Run manage.py from AWS EB Linux instance 使用 Linux 2 在 EB 上通过 .ebextensions 安装 EFS 时出现问题 - Problem Mounting EFS through .ebextensions on EB using Linux 2 Amazon EC2 Minecraft Server - 无法运行 mc 命令,仅运行 bash 命令 - Amazon EC2 Minecraft Server - Cannot run mc commands, only runs bash commands GitLab CI/CD 管道 - 在 GitLab Runner 上交互式运行 Linux 命令 - GitLab CI/CD Pipeline - Run Linux commands interactively on GitLab Runner 获取“无法使用的 Erlang 运行时系统!” 尝试在亚马逊上运行时 Linux 2 - Getting "Unusable Erlang runtime system!" when trying to run on Amazon Linux 2 ECS 代理是否需要 Amazon Linux AMI 才能运行? - Does ECS Agent require an Amazon Linux AMI in order to run? 在 Amazon Linux 2 上的 AWS Amplify 中使用 NodeJS 18 失败 - Using NodeJS 18 in AWS Amplify on Amazon Linux 2 fails 在亚马逊上安装 Chromium Linux - Installing Chromium on Amazon Linux 为什么在使用 quarkus-amazon-lambda 和 quarkus-smallrye-openapi 包时会出现错误? - Why do I get an error when using quarkus-amazon-lambda and quarkus-smallrye-openapi packages? 如何运行指定 node.js 版本 8 的 eb init? - How to run eb init specifying node.js version 8?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM