我在AWS的Elastic Beanstalk上部署了一个带mysql的django应用,所以,我想在AWS上部署一个带mysql的django应用。mysqlclient
库是需要的。mysqlclient
需要 python3-devel
和 mysql-devel
包来安装,所以我为它准备了自定义配置文件。01_packages.config
:
packages:
yum:
python3-devel: []
mysql-devel: []
部署失败,日志文件 /var/log/cfn-init.log
(Beanstalk日志中提到的)显示错误。
2020-05-31 02:17:37,565 [INFO] -----------------------Starting build-----------------------
2020-05-31 02:17:37,572 [INFO] Running configSets: Infra-EmbeddedPreBuild
2020-05-31 02:17:37,575 [INFO] Running configSet Infra-EmbeddedPreBuild
2020-05-31 02:17:37,579 [INFO] Running config prebuild_0_doyouknow
2020-05-31 02:17:41,831 [ERROR] mysql-devel is not available to be installed
2020-05-31 02:17:41,831 [ERROR] Error encountered during build of prebuild_0_doyouknow: Yum does no
t have mysql-devel available for installation
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 229, in build
changes['packages'][manager] = CloudFormationCarpenter._packageTools[manager]().apply(packages,
self._auth_config)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/rpm_tools.py", line 74, in apply
raise ToolError("Yum does not have %s available for installation" % pkg_spec)
ToolError: Yum does not have mysql-devel available for installation
2020-05-31 02:17:41,834 [ERROR] -----------------------BUILD FAILED!------------------------
然而,我试图通过以下方式手动安装到我的Ec2实例上 yum install mysql-devel
并且安装成功。
我的python版本是3.7,我的 requirements.txt
文件内容是。
asgiref==3.2.7
Django==3.0.5
django-cors-headers==3.2.1
django-dotenv==1.4.2
django-social-share==1.4.0
mysqlclient==1.4.6
numpy==1.18.4
pandas==1.0.3
Pillow==7.1.1
python-dateutil==2.8.1
pytz==2019.3
six==1.14.0
sqlparse==0.3.1
xlrd==1.2.0
解决了! 我已经替换了 mysql-devel
与 mariadb-devel
并成功运行,然后我就可以安装 mysqlcient
图书馆。
我的新 01_packages.config
:
packages:
yum:
python3-devel: []
mariadb-devel: []
我不知道其根本原因,但我这样做是因为我注意到手动安装的 mysql-devel
通过 yum install mysql-devel
实际上是在安装 mariadb-devel
!
这是我的ec2实例发布详情。也许是因为新的Amazon Linux Release 2。
$ cat /etc/*-release*
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
Amazon Linux release 2 (Karoo)
cpe:2.3:o:amazon:amazon_linux:2