首頁  >  問答  >  主體

解決Django Elastic Beanstalk與RDS MySQL連線問題

<p>我正在嘗試將我的Django Elastic Beanstalk連接到我的RDS MySQL。我的Django透過localhost與我的RDS MySQL工作正常,但是當我嘗試將我的Django上傳到Elastic Beanstalk時,我得到了「部署應用程式失敗」的錯誤,並且AWS顯示了以下錯誤。我的專案在requirements.txt中有mysqlclient,就像這裡所示:</p> <p>https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html</p> <p>根據該頁面,這應該足夠了。我當然嘗試過搜尋類似的問題,但迄今為止沒有成功。我注意到許多問題都提到需要在.ebextensions資料夾中有一個packages.config文件,我嘗試了其中許多建議,但沒有成功。這是問題嗎?為什麼AWS頁面上沒有提到這一點? </p> <pre class="brush:php;toolbar:false;">× python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [16 lines of output] /bin/sh: mysql_config: command not found /bin/sh: mariadb_config: command not found /bin/sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/tmp/pip-install-r0dz9d2g/mysqlclient_f2b5c53e43a648c284b06f7af63d9855/setup.py", line 15, in <module> metadata, options = get_config() File "/tmp/pip-install-r0dz9d2g/mysqlclient_f2b5c53e43a648c284b06f7af63d9855/setup_posix.py", line 70, in get_config libs = mysql_config("libs") File "/tmp/pip-install-r0dz9d2g/mysqlclient_f2b5c53e43a648c284b06f7af63d9855/setup_posix.py", line 31, in mysql_config raise OSError("{} not found".format(_mysql_config_path)) OSError: mysql_config not found mysql_config --version mariadb_config --version mysql_config --libs [end of output]</pre></p>
P粉716228245P粉716228245388 天前521

全部回覆(1)我來回復

  • P粉777458787

    P粉7774587872023-08-29 13:37:05

    回答自己的問題。稍後我問了一個類似的問題AWS Elastic Beanstalk RDS MacOS mysqlclient not working並得到了幫助。

    答案確實是packages.config文件,透過yum安裝所需的文件(請參考上面的連結)。我的程式碼中還有其他地方出了問題,但我得到的錯誤與上面的錯誤相同,儘管packages.config已經正確設定。我發現這個問題是因為我嘗試將其設定回SQLite資料庫並上傳到Elastic Beanstalk,但它不起作用。 (對不起,我不記得我得到了什麼錯誤,我很緊張,我想是"111: Connection refused"錯誤。)

    我讓事情正常工作的方法是刪除所有配置文件,然後從常規完成的項目重新開始,然後按照教程進行操作(就像我以前做的那樣):https://docs.aws .amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html#python-rds-connect

    #從那裡,我在我的.ebextensions資料夾中新增了一個packages.config文件,其中包含以下程式碼...

    packages: 
      yum:
        python3-devel: []
        mariadb-devel: []

    ...正如我在上面連結的另一個問題中所提到的,以及這裡:mysqlclient installation error in AWS Elastic Beanstalk

    我還需要gunicorn和一個Procfile,但我之前已經解決了這個問題,但如果你因為Elastic Beanstalk和RDS的問題而來到這裡,這也值得一提。

    我還不明白如果我在我的電腦上沒有yum,是否可以在packages.config檔中使用yum,特別是因為我使用的是MacOS,而在MacOS上使用yum並不常見。這個問題在我上面連結的另一個問題中得到了回答,答案是在這種情況下你不需要在你的電腦上安裝yum,因為yum在這種情況下是由Elastic Beanstalk的Amazon Linux 2伺服器使用的。

    回覆
    0
  • 取消回覆