Nic*_*ady 5 amazon-web-services amazon-elastic-beanstalk
我正在为 EBS 苦苦挣扎,因为我认为它的架构相对简单。我有一个 Django 应用程序。这个 Django 应用程序将包含我的工作环境和我的 WebServer 的代码。我一直在很好地部署到一个 WebServer,当我尝试合并它时,我的工作环境只有这个问题。这个可怜的家伙有同样的问题,社区似乎没有很好的答案。
这是我学到的第一个错误,因为没有很好的方法来分离配置。
从我收到此错误开始:
2020/09/03 20:17:59.065285 [ERROR] update processes [web sqsd nginx healthd cfn-hup] pid symlinks failed with error Read pid source file /var/pids/web.pid failed with error:open /var/pids /web.pid: 没有那个文件或目录
从这个链接,我认为是由于我.platform的 nginx 覆盖(仅修改 gzip 以打开它)以某种方式导致了这个。我已将其删除并重新部署,但错误不存在,因此似乎合乎逻辑。不幸的是,它看起来相当喜怒无常,因为它又回来了(在我已经部署了几次之后!!!!)。
我第一次尝试解决这个问题是使用 saved_configs/
??? .elasticbeanstalk
? ??? config.yml
? ??? saved_configs
? ??? web.cfg.yml
? ??? worker.cfg.yml
Run Code Online (Sandbox Code Playgroud)
并像这样调用它:
eb create testweb --cfg web
eb create testwrkr -t worker --cfg worker
eb deploy testweb
eb deploy testwrkr
Run Code Online (Sandbox Code Playgroud)
这似乎有效,但我仍然无法部署我的工作环境。接下来我尝试创建一个 Makefile,因为删除 .platform 昨天为我修复了错误。
ENVS = 'production development'
ifndef env
$(error "env" is not specified. Please use one of: $(ENVS))
endif
create_web: clean copy_web_configuration
@echo "Creating Environment: $(env)"
-eb create $(env)
create_worker: clean copy_worker_configuration
@echo "Creating Worker Environment: $(env)"
-eb create $(env) -t worker
deploy_web: clean copy_web_configuration
@echo "Deploying to: $(env)"
-eb deploy $(env) $(args)
@$(MAKE) clean
deploy_worker: clean copy_worker_configuration
@echo "Deploying worker to: $(env)"
-eb deploy $(env) $(args)
@$(MAKE) clean
copy_web_configuration:
@cp -r config/ebs/extensions/shared/ .ebextensions/
@cp -r config/ebs/extensions/web/ .ebextensions/
@cp -r config/ebs/platform/web/ .platform/
copy_worker_configuration:
@cp -r config/ebs/extensions/shared/ .ebextensions/
@cp -r config/ebs/extensions/worker/ .ebextensions/
clean:
@find .ebextensions/ -maxdepth 1 -type f -exec rm -f {} \;
@rm -rf .platform/nginx
@find .platform/ -maxdepth 1 -type f -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
所以我可以 100% 确定无论是在.ebextensions/或.platform/用于预期平台。
My new file tree looks like this:
.ebextensions/
.platform/
config/
??? __init__.py
??? ebs
? ??? extensions
? ? ??? shared
? ? ? ??? 01_packages.config
? ? ? ??? appslog.config
? ? ? ??? django.config
? ? ??? web
? ? ? ??? db-migrate.config
? ? ? ??? securelistener-clb.config
? ? ? ??? static.config
? ? ??? worker
? ? ??? worker.config
? ??? platform
? ??? web
? ??? nginx
? ??? nginx.conf
??? settings
? ??? __init__.py
? ??? base.py
? ??? local.py
? ??? production.py
??? urls.py
??? wsgi.py
Run Code Online (Sandbox Code Playgroud)
现在,当我部署(添加后cron.yaml)时,我又得到了我的老朋友
2020/09/04 22:12:21.485660 [INFO] 执行指令:跟踪 healthd 中的 pids 2020/09/04 22:12:21.485677 [INFO] 这是一个增强的健康环境... 2020/09:124 2 :21.485697 [INFO] 运行命令 /bin/sh -c systemctl show -p ConsistsOf aws-eb.target | cut -d= -f2 2020/09/04 22:12:21.491871 [INFO] nginx.service healthd.service cfn-hup.service sqsd.service
2020/09/04 22:12:21.491894 [INFO] 运行命令 /bin/sh -c systemctl show -p ConsistsOf eb-app.target | cut -d= -f2 2020/09/04 22:12:21.496690 [信息] web.service
2020/09/04 22:12:21.496761 [ERROR] update processes [web nginx healthd cfn-hup sqsd] pid symlinks failed with error Read pid source file /var/pids/web.pid failed with error:open /var/pids /web.pid: no such file or directory 2020/09/04 22:12:21.496772 [ERROR] 执行命令时出错 [app-deploy] - [Track pids in healthd]。停止运行命令。错误:更新进程 [web nginx healthd cfn-hup sqsd] pid symlinks failed with error Read pid source file /var/pids/web.pid failed with error:open /var/pids/web.pid: no such file or directory
2020/09/04 22:12:21.496776 [INFO] 执行清理逻辑 2020/09/04 22:12:21.496861 [INFO] CommandService 响应:{"status":"FAILURE","api_version":"1.0" results":[{"status":"FAILURE","msg":"引擎执行遇到错误。","returncode":1,"events":[{"msg":"实例部署成功生成了一个' Procfile'.","timestamp":1599257531,"severity":"INFO"},{"msg":"实例部署失败。详见'eb-engine.log'。","timestamp":1599257541, "严重性":"错误"}]}]}
我的工作人员配置中没有太多内容,所以我不知道为什么这不会部署。有没有人见过这个问题?我在网上找到的唯一资源是:
我同时监视了日志,并按操作顺序查看了首先出现此错误的操作:
Sep 4 22:42:18 ip-172-31-7-235 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Sep 4 22:42:18 ip-172-31-7-235 web: return _bootstrap._gcd_import(name[level:], package, level)
Sep 4 22:42:18 ip-172-31-7-235 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Sep 4 22:42:18 ip-172-31-7-235 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Sep 4 22:42:18 ip-172-31-7-235 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Sep 4 22:42:18 ip-172-31-7-235 web: ModuleNotFoundError: No module named 'application'
Sep 4 22:42:18 ip-172-31-7-235 web: [2020-09-04 22:42:18 +0000] [9303] [INFO] Worker exiting (pid: 9303)
Sep 4 22:42:18 ip-172-31-7-235 web: [2020-09-04 22:42:18 +0000] [9296] [INFO] Shutting down: Master
Sep 4 22:42:18 ip-172-31-7-235 web: [2020-09-04 22:42:18 +0000] [9296] [INFO] Reason: Worker failed to boot.
Run Code Online (Sandbox Code Playgroud)
进而
2020/09/04 22:42:21.717799 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf eb-app.target | cut -d= -f2
2020/09/04 22:42:21.722604 [INFO] web.service
2020/09/04 22:42:21.722678 [ERROR] update processes [web healthd nginx sqsd cfn-hup] pid symlinks failed with error Read pid source file /var/pids/web.pid failed with error:open /var/pids/web.pid: no such file or directory
2020/09/04 22:42:21.722689 [ERROR] An error occurred during execution of command [app-deploy] - [Track pids in healthd]. Stop running the command. Error: update processes [web healthd nginx sqsd cfn-hup] pid symlinks failed with error Read pid source file /var/pids/web.pid failed with error:open /var/pids/web.pid: no such file or directory
2020/09/04 22:42:21.722694 [INFO] Executing cleanup logic
2020/09/04 22:42:21.722778 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment successfully generated a 'Procfile'.","timestamp":1599259331,"severity":"INFO"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1599259341,"severity":"ERROR"}]}]}
Run Code Online (Sandbox Code Playgroud)
所以我猜web.service没有找到是因为ModuleNotFound错误。我不明白的是我使用与 Web 环境完全相同的代码存储库..那么 Worker 环境怎么会失败?配置在我看来没问题。我的树在上面,相关的beanstalk配置是这样的:
aws:elasticbeanstalk:container:python:
WSGIPath: config.wsgi:application
Run Code Online (Sandbox Code Playgroud)
由于最初的问题是关于web.service失败的,因此我将添加 AWS 支持人员的注释。
\n\n接下来,\xe2\x80\x98web.service\xe2\x80\x99 是 Beanstalk 的 linux 服务,负责激活暂存中的虚拟环境并使用 \xe2\x80\x98gunicorn\xe2\x80\x99 运行 WSGI 服务器python 插件[2]。因此,从错误 \xe2\x80\x98/var/pids/web.pid failed with error:open /var/pids/web.pid\xe2\x80\x99 来看,当 \xe2\x80\x98web. service\xe2\x80\x99 尝试使用 \xe2\x80\x98ExecStart=/bin/sh -c "gunicorn --bind 127.0.0.1:8000 --workers=1 --threads=15 application\xe2 运行应用程序\x80\x9d\xe2\x80\x99 并且由于模块丢失而失败。
\n
这指出了我认为问题所在的地方,即ModuleNotFound. 当我tail -f查看两个不同的日志文件并看到该ModuleNotFound错误发生在另一个错误之前时,这支持了该论文。
之所以发生这种情况,是因为在我切换到使用 Makefile 后,在运行 eb 部署之前我没有自动提交代码,或者至少暂存它并使用该--staged标志运行部署。不幸的是,如果我想使用同一个存储库,AWS 的建议建议是使用两个不同的分支来管理工作代码和 Web 代码。我发现这对 EBS 来说绝对是糟糕的建议和糟糕的设计,所以我决定保留我的Makefile,并找到了一种解决方法,如果我指定.ebignore,我可以绕过git,并且在部署之前直接复制任何文件,然后进行清理,将被部署。
如果有人觉得有帮助的话,这是我的调试过程:
\nWSGI 应用程序未启动。这意味着无论出于何种原因都找不到 python 应用程序的入口点。
\n在应用程序的根目录中,我有:
\nconfig/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 settings\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 local.py\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 urls.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wsgi.py\nRun Code Online (Sandbox Code Playgroud)\n其中有变量:
\nconfig/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 settings\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 local.py\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 urls.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wsgi.py\nRun Code Online (Sandbox Code Playgroud)\n由于某种原因,配置文件无法找到此变量来启动 python 应用程序
\n用于启动应用程序的相关 Elastic Beanstalk 代码/.ebextensions/django.config
application = get_wsgi_application()\nRun Code Online (Sandbox Code Playgroud)\n这对我来说似乎是对的,所以我有点困惑。另外,我已经使用此设置部署了很多次并且它很有效;但现在它失败了。为什么?
\n检查控制台以查看 WSGI 路径是否按照我的想法设置
\n\n只说申请。它对实际运行的环境有何影响?正如我所想,工作环境说config.wsgi:application。所以..问题是/无论出于何种原因,配置实际上并未进入Elastic Beanstalk。/
我意识到我想要部署的文件实际上并未被提交。目录中的文件.ebextensions需要像应用程序的其余部分一样提交。这使得事情Makefile有点棘手,因为文件不会被提交,因为我刚刚复制了它们。
尝试将新复制的文件添加到git,然后使用 运行我的部署--staged,然后使用 删除更改git restore --source=HEAD --staged --worktree -- .ebextensions/。所以我去看看是否有办法在 git 之外部署。这可行,但我不喜欢干扰 git 工作流程。从这个 AWS线程看来,这可以通过.ebignore文件来完成。
文档中具体说明: \n配置 EB CLI - AWS Elastic Beanstalk
\n\n\n当 .ebignore 存在时,EB CLI 不会使用 git 命令来创建源包。这意味着 EB CLI 会忽略 .ebignore 中指定的文件,并包括所有其他文件。特别是,它包含未提交的源文件。
\n
这似乎已经解决了问题。
\n| 归档时间: |
|
| 查看次数: |
2647 次 |
| 最近记录: |