Get Hands-on with Amazon EKS - Workshop Event Series
Whether you're taking your first steps with Kubernetes or you're an experienced practitioner looking to sharpen your skills, our Amazon EKS workshop series delivers practical, real-world experience that moves you forward. Learn directly from AWS solutions architects and EKS specialists through hands-on sessions designed to build your confidence with Kubernetes. Register now and start building with Amazon EKS!
如何将 Amazon EFS 卷挂载到 Elastic Beanstalk 环境中的应用程序目录?
我想将 Amazon Elastic File System(Amazon EFS)卷挂载到 AWS Elastic Beanstalk 环境中的应用程序目录中。
简短描述
以下解决方法就将 Amazon EFS 卷挂载到基于 Amazon Linux 1 的平台上提供了一般说明。该解决方法使用 PHP 解决方案堆栈。如果您使用不同的解决方案堆栈,请从以下选项中选择适合您的解决方案堆栈的应用程序目录和暂存目录:
----------------------------------------------------- Solution stack Application directory Staging directory Nodejs /var/app/current /tmp/deployment/application PHP /var/app/current /var/app/ondeck Ruby (Passenger) /var/app/current /var/app/ondeck Ruby (Puma) /var/app/current /var/app/ondeck Java with Tomcat /usr/share/tomcat*/webapps/ROOT /tmp/deployment/application/ROOT Java SE /var/app/current /var/app/staging Python /opt/python/current/app /opt/python/ondeck/app Go /var/app/current /var/app/staging Single Container Docker /var/app/current /var/app/staging Multi-Container Docker /var/app/current /var/app/staging -----------------------------------------------------
重要信息:在您部署 Elastic Beanstalk 应用程序时,/var/app/current 的内容将被移动到 /var/app/current.old。您无法直接将 Amazon EFS 卷挂载到应用程序目录中。当前部署的源包将被移动到应用程序目录。如果您将 Amazon EFS 卷挂载到 /var/app/current,则在部署完成后,该卷将被移动到 /var/app/current.old。
eb-activity.log 输出示例:
=============================== [2020-02-12T02:28:18.237Z] INFO [3159] - [Application deployment Sample Application@1/StartupStage1/AppDeployEnactHook/01_flip.sh] : Starting activity... [2020-02-12T02:28:18.431Z] INFO [3159] - [Application deployment Sample Application@1/StartupStage1/AppDeployEnactHook/01_flip.sh] : Completed activity. Result: ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir + EB_APP_STAGING_DIR=/var/app/ondeck ++ /opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir + EB_APP_DEPLOY_DIR=/var/app/current + '[' -d /var/app/current ']' + mv /var/app/current /var/app/current.old + mv /var/app/ondeck /var/app/current + nohup rm -rf /var/app/current.old ===============================
解决方法
如需将 Amazon EFS 卷挂载到 Elastic Beanstalk 环境中的应用程序目录,请完成以下步骤:
- 确认您的源包已解压到暂存目录。有关详细信息,请参阅查看您的 Elastic Beanstalk 环境中的 Amazon Elastic Compute Cloud (Amazon EC2) 实例的日志。
eb-activity.log 输出示例:
注意:****/opt/elasticbeanstalk/hooks/appdeploy/pre/ 中的所有 appdeploy pre 钩子和 .ebextensions 都在暂存目录中运行。=============================== [2020-02-12T02:28:16.336Z] INFO [3159] - [Application deployment Sample Application@1/StartupStage0/AppDeployPreHook/01_unzip.sh] : Starting activity... [2020-02-12T02:28:16.631Z] INFO [3159] - [Application deployment Sample Application@1/StartupStage0/AppDeployPreHook/01_unzip.sh] : Completed activity. Result: ++ /opt/elasticbeanstalk/bin/get-config container -k app_user + EB_APP_USER=webapp ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir + EB_APP_STAGING_DIR=/var/app/ondeck ++ /opt/elasticbeanstalk/bin/get-config container -k source_bundle + EB_SOURCE_BUNDLE=/opt/elasticbeanstalk/deploy/appsource/source_bundle + rm -rf /var/app/ondeck + /usr/bin/unzip -d /var/app/ondeck /opt/elasticbeanstalk/deploy/appsource/source_bundle Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle creating: /var/app/ondeck/.ebextensions/ inflating: /var/app/ondeck/.ebextensions/logging.config inflating: /var/app/ondeck/scheduled.php inflating: /var/app/ondeck/index.php inflating: /var/app/ondeck/cron.yaml inflating: /var/app/ondeck/styles.css extracting: /var/app/ondeck/logo_aws_reduced.gif + chown -R webapp:webapp /var/app/ondeck + chmod 775 /var/app/ondeck =============================== - 在源包的根目录下创建 .ebextensions 文件夹。
- 要将 Amazon EFS 卷挂载到特定目录(例如 /efs),请向您的目录添加格式化配置文件(YAML 或 JSON)。
- 要将 Amazon EFS 卷挂载到应用程序目录,请创建指向暂存目录的符号链接。要从 /efs 创建指向暂存目录的符号链接,请使用 container_commands 在 .ebextensions 文件夹中创建 .config 文件。
示例:
**注意:**在 Elastic Beanstalk 环境中部署期间运行 appdeploy enact 钩子时,暂存目录内容将会移到应用程序目录。例如,在 PHP 解决方案中,flip.sh 脚本可以将暂存目录的内容移动到应用程序目录。flip.sh 脚本是 /opt/elasticbeanstalk/hooks/appdeploy/enact/ 中的第一个 AppDeployEnactHook 脚本。container_commands: 01_symlink: command: ln -s /efs /var/app/ondeck/

