亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 ElasticBeanstalk 配置中設置 Python WSGIDaemon

在 ElasticBeanstalk 配置中設置 Python WSGIDaemon

精慕HU 2023-05-16 15:49:01
我正在尋找有關如何--maximum-requests在運行 Django 的 AWS ElasticBeanstalk Python 環境中設置值的說明。請注意,此環境不使用 Linux 2 映像,因此 gunicorn 不是一個選項,也不使用 procfile。maximum-requests=nnn 定義守護進程在關閉和重新啟動之前應處理的請求數限制。當您遇到與 Python 對象引用計數周期相關的問題或內存緩存使用不當導致內存不斷增長時,這可能會用于定期強制重啟 WSGI 應用程序進程。如果此選項未定義,或定義為 0,則守護進程將持續存在并繼續為請求提供服務,直到 Apache 本身重新啟動或關閉。避免在處理大量流量的網站上將此設置為少量請求。這是因為 WSGI 應用程序的不斷重啟和重新加載可能會對您的系統造成不必要的負載并影響性能。僅當由于內存使用問題而別無選擇時才使用此選項。一旦任何內存問題得到解決,請立即停止使用它。您可以將 graceful-timeout 選項與此選項結合使用,以減少由于使用此選項而導致重新啟動時活動請求被中斷的可能性。
查看完整描述

2 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

為了實現這一點,我必須在包含以下內容的 .ebextensions 文件夾中創建一個配置。


您需要從您的服務器復制 wsgi.conf 文件,以確保您首先擁有正確的 EB 設置。


files:

? "/opt/elasticbeanstalk/local/override_wsgi_conf.py":

? ? mode: "000755"

? ? owner: root

? ? group: root

? ? content: |

? ? ? ? #!/usr/bin/env python

? ? ? ? import os

? ? ? ? import sys

? ? ? ? sys.path.append(os.path.dirname(

? ? ? ? ? ? os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

? ? ? ? import config

? ??

? ? ? ? MY_APACHE_TEMPLATE = r'''

? ? ? ? # Customized wsgi.conf.? If you're seeing this, good!

?

? ? ? ? LoadModule wsgi_module modules/mod_wsgi.so

? ? ? ? WSGIPythonHome /opt/python/run/baselinenv

? ? ? ? WSGISocketPrefix run/wsgi

? ? ? ? WSGIRestrictEmbedded On


? ? ? ? <VirtualHost *:80>


? ? ? ? Alias /static/ /opt/python/current/app/static/

? ? ? ? <Directory /opt/python/current/app/static/>

? ? ? ? Order allow,deny

? ? ? ? Allow from all

? ? ? ? </Directory>



? ? ? ? WSGIScriptAlias / /opt/python/current/app/key_collector_backend/wsgi.py



? ? ? ? <Directory /opt/python/current/app/>

? ? ? ? Require all granted

? ? ? ? </Directory>


? ? ? ? WSGIDaemonProcess wsgi processes=3 threads=20 maximum-requests=10000 display-name=%{GROUP} \

? ? ? ? python-home=/opt/python/run/venv/ \

? ? ? ? python-path=/opt/python/current/app user=wsgi group=wsgi \

? ? ? ? home=/opt/python/current/app

? ? ? ? WSGIProcessGroup wsgi

? ? ? ? </VirtualHost>


? ? ? ? LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined


? ? ? ? WSGIPassAuthorization On

? ? ? ? WSGIApplicationGroup %{GLOBAL}


? ? ? ? '''



? ? ? ? def main():

? ? ? ? ? ? try:

? ? ? ? ? ? ? ? WSGI_STAGING_CONFIG = config.get_container_config('wsgi_staging_config')

? ? ? ? ? ? ? ? print 'Overriding WSGI configuration in %s' % WSGI_STAGING_CONFIG

? ? ? ? ? ? ? ? open(WSGI_STAGING_CONFIG, 'w').write(MY_APACHE_TEMPLATE)

? ? ? ? ? ? except Exception, e:

? ? ? ? ? ? ? ? config.emit_error_event(config.USER_ERROR_MESSAGES['badappconfig'])

? ? ? ? ? ? ? ? config.diagnostic("Error generating config during configdeploy/pre: %s"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? % str(e))

? ? ? ? ? ? ? ? sys.exit(1)

? ??

? ??

? ? ? ? if __name__ == '__main__':

? ? ? ? ? ? config.configure_stdout_logger()

? ? ? ? ? ? main()

?

commands:

?

? 5_app_deploy_dir:

? ? command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/pre"

? 5_config_deploy_dir:

? ? command: "mkdir -p /opt/elasticbeanstalk/hooks/configdeploy/pre"

?

? 10_app_deploy_file:

? ? command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/appdeploy/pre/90_override_wsgi_conf.py"

?

? 20_config_deploy_file:

? ? command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/configdeploy/pre/90_override_wsgi_conf.py"



查看完整回答
反對 回復 2023-05-16
?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

您必須替換使用 WSGIDaemonProcess 指令的 Apache 服務器配置。


通過 SSH 連接到運行您的彈性 beanstalk 應用程序的 EC2 實例并切換到配置目錄/etc/httpd/conf.d/。


在那里尋找包含WSGIDaemonProcess.


grep -rnwl . -e 'WSGIDaemonProcess'

替換 elasticbeanstalk 應用程序配置中匹配文件的內容。


生成配置的位置(在應用程序部署的暫存階段)可以使用 shell 命令方便地獲?。?/p>


/opt/elasticbeanstalk/bin/get-config container -k wsgi_staging_config

.ebextensions/wsgi.config


files:

  /opt/elasticbeanstalk/hooks/appdeploy/pre/05_wsgi.sh:

    mode: "000755"

    owner: root

    group: root

    content: |

      #!/usr/bin/env bash

      # Set max-requests option in generated wsgi.conf

      sed -i -e '/WSGIDaemonProcess wsgi/ a\

      \ \ maximum-requests=1000 \\

      ' $(/opt/elasticbeanstalk/bin/get-config container -k wsgi_staging_config)


查看完整回答
反對 回復 2023-05-16
  • 2 回答
  • 0 關注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號