Thursday, January 13, 2011

Postgres/PostGIS with RAID 10 on Amazon EBS without Leaving the Browser

Since some one asked about installing Postgres on AWS without leaving the browser, I've updated the Postgres install script to Ubuntu 10.10 Maverick Meerkat and made the size and number of the volumes as command line arguments. The script below can be cut and pasted into the User Data textbox when launching the AMI as in the previous GeoServer install instructions.

You will need to place your private key and X.509 certificate where they can be downloaded. For the sake of simplicity, the example script retrieves the credentials  using wget protected by a username and password. In practice, I would use sftp or scp to transfer the credentials


UPDATE 1/14/11: The script from 1/13/11 contained errors and has been replaced. The current script has been tested against ami-cef405a7

#!/bin/bash -ex
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

# download the install script and run it
cd /home/ubuntu

# grab your private key and X.509 cert
wget --user=user --password='myPassword' http://example.server.com/home/*.pem
sudo chmod 600 *pem 

# change this to your keypair and cert
export EC2_PRIVATE_KEY=~/myKey.pem
export EC2_CERT=~/myCert.pem

# get install script
wget http://dl.dropbox.com/u/6706687/postgres-ubuntu-ec2-install.sh 
chmod 755 postgres-ubuntu-ec2-install.sh

# run it, note that the install script now takes arguments for the number of volumes
#   and the size of each volume in gigbytes, args below create a 500GB RAID10 
sudo -u ubuntu ./postgres-ubuntu-ec2-install.sh 10 100

4 comments:

  1. Thanks!

    This is great, although am having a concern the script is not running from the data user textbox

    I have for testing purposes added the .pem files to an open ftp directory which i can access.

    Do you have any ideas?

    PS I am using ami-cef405a7 as mentioned in the .sh file

    How would I run the .sh file from putty via ssh? Would I use the same file?

    ReplyDelete
  2. Hi,

    I uploaded an old build script yesterday. The correct script is now linked and it should work. Let me know if you have problems and thanks for trying it out.

    sophia

    ReplyDelete
  3. This appeared to work, great!

    I would like to connect via PG ADMIN III

    I have added port 5432 to my security group
    and am receiving an error that states

    could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host .....

    I believe i need to edit the hba_conf file to allow me in, although when I goto stop the server

    I receive another error

    * Error: pid file is invalid, please manually kill the stale server process.

    If I goto the AWS management console and stop the server I cannot log back in via putty...


    How would you suggest editing the HBA file to allow PG ADMIN in?

    Is there a proper way to start and stop the server?

    How does one restore via this configuration?

    Would you be interested in helping me configure my instance?

    ReplyDelete
  4. Is there a proper way to start and stop the server?

    PostgreSQL is installed as a service, so you can start/stop postgres with:

    sudo service postgresql {start|stop|restart|reload|force-reload|status}

    If this fails a kill -15 will stop postgres

    How would you suggest editing the HBA file to allow PG ADMIN in?

    1. Stop postgres:

    >sudo service postgresql stop

    2. Change you security profile on AWS to open port 5432:

    In the AWS console click on Security Groups, click on the checkbox for default. Add the postgresql port as Custom, TCP, 5432, 5432, 0.0.0.0/0 and save

    3. Edit /etc/postgresql/8.4/main/pg_hba.conf and add:

    host all all XX.XX.XX.XX/24 trust # remote acces

    where xx.xx.xx.xx/24 is your ip address

    4. Edit /etc/postgresql/8.4/main/postgresql.conf

    listen_addresses = 'XX.XX.XX.XX'

    5. restart postgres

    sudo service postgresql start


    How does one restore via this configuration?

    In AWS you can create an AMI using the AWS management console, Click on Instances, select your instance by clicking on the check box, click on Instance Actions, clcik on Create Image (EBS AMI) - this will create an AMI that you can launch.

    ReplyDelete