有没有人有使用 PostGIS 设置 Amazon Elastic Beanstalk 的经验(以便我可以利用 Geodjango)?
默认设置(RDS,以 MySQL 为特色)目前不支持开箱即用的许多功能: 1. PostgreSQL + PostGIS 2. 安装 C/C++ 库(如 GEOS 和 Proj.4)的能力
提前致谢
有没有人有使用 PostGIS 设置 Amazon Elastic Beanstalk 的经验(以便我可以利用 Geodjango)?
默认设置(RDS,以 MySQL 为特色)目前不支持开箱即用的许多功能: 1. PostgreSQL + PostGIS 2. 安装 C/C++ 库(如 GEOS 和 Proj.4)的能力
提前致谢
如果您想将 geodjango 与 Amazon Elastic Beanstalk 一起使用,您需要创建一个自定义AMI,您可以在其中安装 PostGIS,然后在启动时将您的 Elastic Beanstalk 应用程序指向该 AMI。
这是一个关于如何自定义 EBS AMI的好教程。还有一个AWS 教程,但我发现第一个更容易理解。在我的自定义 AMI 上,我从源代码安装了 geos、gdal、proj4 和 postgis,并使用yum install postgres
. 以下是我用来将所有库安装到 AMI 中的命令。
为了让 django 应用程序找到库,我还在 AWS EBS 控制台中设置了一个额外的环境变量。在我的环境的菜单栏中,我转到配置-> 软件配置并通过添加属性集来编辑环境属性为.LD_LIBRARY_PATH
/usr/local/lib/:$LD_LIBRARY_PATH
由于 beantalk 应用程序实例不会自己运行数据库,因此我还设置了一个Amazon RDS Postgres托管数据库,这是一项相对较新的服务,它支持 PostGIS。
如果你把所有这些放在一起,你应该得到一个非常可扩展的 GeoDjango 应用程序!
sudo yum install postgresql postgresql-devel postgresql-server postgresql9-contrib gcc gcc-c++ make libtool curl libxml2 libxml2-devel python-devel
wget http://download.osgeo.org/proj/proj-4.8.0.zip
unzip proj-4.8.0.zip
cd proj-4.8.0
./configure
make
sudo make install
cd ..
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar -xvf geos-3.4.2.tar.bz2
cd geos-3.4.2
./configure
make
sudo make install
cd ..
wget http://download.osgeo.org/gdal/1.10.1/gdal1101.zip
unzip gdal1101.zip
cd gdal-1.10.1
./configure --with-python=yes
make
sudo make install
cd ..
wget http://download.osgeo.org/postgis/source/postgis-2.1.1.tar.gz
tar -xvf postgis-2.1.1.tar.gz
cd postgis-2.1.1
./configure
make
sudo make install
您也可以在没有自定义 AMI 的情况下执行此操作,只需使用ebextensions。我使用 Amazon Instance (2013.09) ami-35792c5c对此进行了测试,因此请使用该实例而不是较新的实例。如果您已完成Elastic Beanstalk 101 中的 Django,您就会了解 ebextensions。下面的 ebextensions 将很快开始,您可以使用以下 ebextensions。只需将以下内容放在存储库底部的 .ebextensions 文件夹中。我还在这些配置文件中包含了 postgres 9.3 和 memcached:
00_repo_ostgis.config:
files:
"/etc/yum.repos.d/pgdg-93-redhat.repo":
mode: "000644"
owner: root
group: root
content: |
[pgdg93]
name=PostgreSQL 9.3 $releasever - $basearch
baseurl=http://yum.postgresql.org/9.3/redhat/rhel-6-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93
[pgdg93-source]
name=PostgreSQL 9.3 $releasever - $basearch - Source
failovermethod=priority
baseurl=http://yum.postgresql.org/srpms/9.3/redhat/rhel-6-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93
commands:
epel_repo:
command: yum-config-manager -y --enable epel
remi_repo:
command: yum-config-manager -y --enable remi
packages:
rpm:
pgdg-redhat93-9.3-1: 'http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm'
remi: 'http://rpms.famillecollet.com/enterprise/remi-release-6.rpm'
qt4-devel: 'http://mirror.centos.org/centos/6/os/x86_64/Packages/qt-4.6.2-28.el6_5.x86_64.rpm'
01_app_postgis.config:
packages:
yum:
libtiff-devel: ''
libjpeg-devel: ''
libzip-devel: ''
freetype-devel: ''
postgresql-devel: ''
gdal: ''
gdal-python: ''
geos: ''
proj: ''
libmemcached: ''
libmemcached-devel: ''
cyrus-sasl-devel: ''
zlib-devel: ''
container_commands:
01_collectstatic:
command: 'PYTHONPATH=.:..:../lib cd site/<your_project> && ./manage.py collectstatic -c --noinput && cd ../..'
leader_only: true
02_migrate:
command: 'PYTHONPATH=.:..:../lib cd site/<your_project> && ./manage.py migrate --noinput && cd ../..'
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: site/<your_project>/wsgi.py
- namespace: aws:elasticbeanstalk:container:python:staticfiles
option_name: /static/
value: site/<your_project>/static/
- option_name: DJANGO_SETTINGS_MODULE
value: settings_prod
我的项目的结构有点不同。我的设置文件和 urls.py 我移动到了项目目录的根目录,所以我不得不更改 wsgi.py 中设置的路径。所以相应地调整它。只需使用您之前使用的 container_commands 和 option_settings 即可。
您的requirements.txt文件至少应包含:
Django==1.7.1
Pillow
psycopg2
我将大多数其他 python 依赖项存储在我的 PYTHONPATH 中包含的 ../lib 中,所以我的 repo 结构是这样的:
<your_project>/
├── requirements.txt
├── .ebextensions/
│ ├── 00_repos_postgis.config
│ └── 01_app_postgis.config
└── site/
├── <your_project>
│ ├── wsgi.py
│ ├── settings_prod.py # used for EB, like settings_local.py but uses env vars
│ └── settings.py
└── lib/
└── <all pip dependencies>
查看我构建的部署工具,它使用结构。我从 EB CLI 工具中获取了我喜欢的内容并进行了调整,直到它为 django 量身定制:https ://github.com/radlws/django-awseb-tasks
注意:启动环境时使用 AMI ami-35792c5c 非常重要。它是唯一一个对我有用的设置。如果其他实例有效,请随时将它们编辑到此答案中。另请参阅我的原始问题。
正如我在这里提到的,我对 2017.03 图像的解决方案是:
commands:
01_yum_update:
command: sudo yum -y update
02_epel_repo:
command: sudo yum-config-manager -y --enable epel
03_install_gdal_packages:
command: sudo yum -y install gdal gdal-devel
files:
"/etc/httpd/conf.d/wsgihacks.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIPassAuthorization On
packages:
yum:
git: []
postgresql95-devel: []
gettext: []
libjpeg-turbo-devel: []
libffi-devel: []
如果您想使用 radtek 的解决方案并想使用最新的 Amazon AMI (2014.9),您可能会遇到依赖问题。这为我解决了。
打开 aws beanstalk 的 ssh shell。一步一步执行下面的命令。你会得到工作的postgis。
cd /home/ec2-user
sudo yum -y install gcc gcc-c++ make cmake libtool libcurl-devel libxml2-devel rubygems swig fcgi-devel libtiff-devel freetype-devel curl-devel libpng-devel giflib-devel libjpeg-devel cairo-devel freetype-devel readline-devel openssl-devel python27 python27-devel
# PROJ
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar -zxvf proj-4.8.0.tar.gz
cd proj-4.8.0
./configure
make
sudo make install
cd ..
# GEOS
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar -xvf geos-3.4.2.tar.bz2
cd geos-3.4.2
./configure
make
sudo make install
cd ..
# GDAL
wget http://download.osgeo.org/gdal/1.10.1/gdal-1.10.1.tar.gz
tar -zxvf gdal-1.10.1.tar.gz
cd gdal-1.10.1
./configure
make
sudo make install
cd ..
# PostGIS
wget http://download.osgeo.org/postgis/source/postgis-2.1.0.tar.gz
tar -xvf postgis-2.1.0.tar.gz
cd postgis-2.1.0
./configure
make
sudo make install
cd ..
然后创建一个符号链接:
ln -s /usr/local/lib/libgdal.so /usr/lib/libgdal.so.1
/sbin/ldconfig