Installing nginx web server with MongoDB onto Amazon Linux AMI Beta

Featured

I located a few resources for setting up a small and simple webserver on Amazon EC2.

Setup a new Amazon EC2 Instance.

First we need to create a new instance with the Amazon Linux AMI. at the time of writing the current image id was: ami-38c33651. This is a 64-bit basic linux system. It comes prebuilt with pearl and python on a CentOS based distro. Its just a basic foundation to build up your server on.

Install nginx.

For nginx i found a thread on the Amazon AWS Forum where there was a helpful blog post about installing the current version of nginx. First we need to create our own RPM for the current version.

; First become root. sudo -i ; Install dependancies. yum install gcc rpm-build perl-ExtUtils-Embed ; setup RPM area. mkdir $HOME/rpm $HOME/rpm/SOURCES $HOME/rpm/SPECS $HOME/rpm/BUILD $HOME/rpm/SRPMS $HOME/rpm/RPMS $HOME/rpm/RPMS/i386 echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros ; Get the most recent RPM for nginx wget ftp://fr2.rpmfind.net/linux/fedora/development/rawhide/source/SRPMS/nginx-0.7.67-1.fc14.src.rpm ; install the RPM rpm -Uvh nginx-0.7.67-1.fc14.src.rpm ; Change to the specs dir and edit the nginx.spec cd ~/rpm/SPECS/ nano nginx.spec

We need to change the version line to the current version number.

; line 11 of nginx.spec version:    0.8.52

There are four additional config param files that need to be added. Find the fastcgi\_param lines and add the others to the file.

; Line 160 in nginx.spec %config(noreplace) %{nginx_confdir}/fastcgi_params %config(noreplace) %{nginx_confdir}/fastcgi_params.default ; Additional lines to add. %config(noreplace) %{nginx_confdir}/scgi_params %config(noreplace) %{nginx_confdir}/scgi_params.default %config(noreplace) %{nginx_confdir}/uwsgi_params %config(noreplace) %{nginx_confdir}/uwsgi_params.default

build and install our new RPM. (note: i am using the 64bit server. this will also create a folder for the 32bit version in the x86 folder.)

rpmbuild -bb nginx.spec cd ~/rpm/RPMS ; Install our new RPM. we need to --nosignature because we created it. rpm -Uvh --nosignature x86_64/nginx-0.8.52-1.amzn1.x86_64.rpm 

Install MongoDB.

Installing and setting up the MongoDB was fairly straight forwared. I used the yum packages that are provided by MongoDB.

; First become root. sudo -i ; Create the yum repository for MongoDB 

we need to add the information for the repo into this file.

For 64-bit:

; /etc/yum.repos.d/10gen-mongodb.repo [10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/ gpgcheck=0

For 32-bit:

; /etc/yum.repos.d/10gen-mongodb.repo [10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/ gpgcheck=0

then run the yum install

yum install mongo-stable mongo-stable-server

edit the config file

nano -w /etc/mongod.conf

fix permissions for directory

chown -R mongod:mongod /var/lib/mongo/

add the server to the startup scripts and start the server.

chkconfig --levels 235 mongod on service mongod start

Testing MongoDB

; start up the client. mongo

some simple tests

> use test switched to db test > db.foo.find() > db.foo.save({a: 1}) > db.foo.find() { "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 1 } > db.foo.update( {a: 1}, {a: 5}) > db.foo.find() { "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 5 }

this completes the installation of nginx and MongoDB.

Software:

References:

Home Cisco Lab

Here are some photos of my home lab.