使用PostGIS配置Amazon Elastic Beanstalk

Ash*_*han 7 postgresql postgis geodjango amazon-web-services amazon-elastic-beanstalk

有没有人有任何使用PostGIS设置Amazon Elastic Beanstalk的经验(这样我可以利用Geodjango)?

默认设置(RDS,特色MySQL)目前不支持开箱即用的功能:1.PostgreSQL + PostGIS 2.安装C/C++库(如GEOS和Proj.4)的功能

提前致谢

yel*_*cap 10

如果您想将geodjango与Amazon Elastic Beanstalk一起使用,则需要创建一个自定义AMI,您可以在其中安装PostGIS,然后在启动时将Elastic Beanstalk应用程序指向该AMI.

这是一个关于如何自定义EBS AMI的好教程.还有一个AWS教程,但我发现第一个更容易理解.在我的自定义AMI上,我从源代码安装了geos,gdal,proj4和postgis,并使用了postgres yum install postgres.以下是我用于将所有库安装到AMI中的命令.

为了让django app找到库,我还在AWS EBS Console中设置了一个额外的环境变量.在我的环境的菜单栏中,我进入了配置 - >软件配置,并通过添加属性集来编辑环境属性.LD_LIBRARY_PATH/usr/local/lib/:$LD_LIBRARY_PATH

由于beanstalk app实例并不能自己运行数据库,我还设置了一个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
Run Code Online (Sandbox Code Playgroud)

  • 您可以在实例出现时利用ebextensions为您安装软件包,请参阅此问题:http://stackoverflow.com/questions/27177327/setting-up-django-with-geodjango-support-in-aws-beanstalk-或-EC2实例?noredirect = 1#comment43973188_27177327 (2认同)

rad*_*tek 5

您也可以在没有自定义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'
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

我的项目结构有点不同.我的设置文件和urls.py我移动到项目目录的根目录,所以我不得不更改wsgi.py中设置的路径.所以相应地调整它.只需使用之前使用的container_commands和option_settings.

您的requirements.txt文件至少应包含:

Django==1.7.1
Pillow
psycopg2
Run Code Online (Sandbox Code Playgroud)

我将大多数其他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>
Run Code Online (Sandbox Code Playgroud)

检查我构建的部署工具,它使用结构.我从EB CLI工具中获取了我喜欢的内容并进行了调整,直到为django定制:https://github.com/radlws/django-awseb-tasks

注意:启动环境时使用AMI ami-35792c5c非常重要.它是唯一一个适合我的设置.如果其他实例有效,请随时将它们编辑到此答案中.另见我原来的问题.


psy*_*ok7 5

正如我在这里提到的我对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: []
Run Code Online (Sandbox Code Playgroud)