有没有人有任何使用PostGIS设置Amazon Elastic Beanstalk的经验(以便我可以利用Geodjango)?使用PostGIS配置Amazon Elastic Beanstalk
有许多的默认设置(RDS,设有MySQL的)当前不支持开箱的特征: 1. PostgreSQL的+ PostGIS的 2.安装C/C++库如GEOS和PROJ的能力0.4
在此先感谢
有没有人有任何使用PostGIS设置Amazon Elastic Beanstalk的经验(以便我可以利用Geodjango)?使用PostGIS配置Amazon Elastic Beanstalk
有许多的默认设置(RDS,设有MySQL的)当前不支持开箱的特征: 1. PostgreSQL的+ PostGIS的 2.安装C/C++库如GEOS和PROJ的能力0.4
在此先感谢
如果你想与亚马逊弹性青苗使用GeoDjango内置您需要创建一个自定义AMI在那里你可以旋转起来时,安装了PostGIS,然后点你的魔豆弹性应用到AMI。
这是一个很好的tutorial on how to customize an EBS AMI。还有一个AWS tutorial for that,但我发现第一个更容易理解。在我的自定义AMI上,我从源代码安装了geos,gdal,proj4和postgis,以及使用yum install postgres
的postgres。以下是我用来将所有库安装到AMI中的命令。
对于django应用程序来查找库,我还在AWS EBS控制台中设置了一个额外的环境变量。在我的环境的菜单栏中,我去了配置 - >软件配置并编辑了环境属性通过添加属性LD_LIBRARY_PATH
设置为/usr/local/lib/:$LD_LIBRARY_PATH
。
由于beanstalk应用程序实例不是自己运行数据库的前提,因此我还设置了一个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对此进行了测试,因此请使用该实例而不是新实例。如果您的Django in Elastic Beanstalk 101已完成,则您可以了解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
我存储在其他大多数蟒的依赖../ lib目录中,我包括在我的PYTHONPATH所以我的回购协议的结构是这样的:
<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非常重要。它是我为此设置工作的唯一一个。如果其他实例正常工作,请随时将其编辑到此答案中。另见my original question。
00_repo文件太棒了!我今天学到了一些新东西。 – po5i
正如我所提到here我的解决方案为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: []
完美!谢谢 –
LD_LIBRARYPATH应该是LD_LIBRARY_PATH吗?它在我做这个改变后适用于我。 –
是的,你是对的。那是一个错字。感谢您指出,只是更新了答案。 – yellowcap