Skip to content

Instantly share code, notes, and snippets.

@chyld
Last active December 14, 2017 06:22
Show Gist options
  • Save chyld/7586188 to your computer and use it in GitHub Desktop.
Save chyld/7586188 to your computer and use it in GitHub Desktop.
Install node.js, mongodb, redis on a 64-bit ubuntu 13.10 server using ec2 on amazon web services
Steps:
INITIAL SETUP
// ------------------------------------------------------------------------------------------ //
Sign in http://aws.amazon.com/
Go to the AWS Management Console
Go to the EC2 Dashboard
Click Launch Instance
Select Ubuntu Server 13.10 (64-bit)
On the top menu, choose 4. Add Storage
Change your size from 8GB to greater than or equal to 30GB (depending on how much data/images you want to store)
On the top menu, choose 6. Configure Security Group
Make up a security group name, whatever you want
Under Protocol Click Add Rule - 2 times
The first rule, from the drop down choose HTTP
The second rule, choose Custom TCP Rule, Port 3000, Anywhere 0.0.0.0/0 (for troubleshooting purposes - can be deleted later)
On the top menu, choose 7. Review
Click the Launch Button
You have to pick a key pair - if you don't have one it will create one - download this - DO NOT DELETE
Click Launch Instances (this will take some time)
Click View Instances
LOG IN
// ------------------------------------------------------------------------------------------ //
On the EC2 Dashboard, click on your instance that you just created. It is running in the cloud.
Copy your Public DNS, i.e., ec2-23-22-253-248.compute-1.amazonaws.com
Open your terminal
Find the key pair you downloaded, i.e., cd ~/Download
chmod 400 my_key_pair.pem
Now, ssh into your server like this
ssh -i my_key_pair.pem [email protected] (replace with your key and your DNS name)
Are you sure you want to continue connecting (yes/no)? yes
You are now logged into your virtual ubuntu machine running on amazon ec2
Check your version (should say Ubuntu 13.10)
lsb_release -a
Check your bit-ness (should say x86_64)
uname -m
Check your diskspace (make sure your diskspace is correct)
df -h
INSTALL LATEST GIT FROM SOURCE
// ------------------------------------------------------------------------------------------ //
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libexpat1-dev
sudo apt-get install gettext
sudo apt-get install asciidoc
sudo apt-get install docbook2x
cd ~
mkdir download
cd download
https://code.google.com/p/git-core/downloads/list
copy the link to the most recent version i.e., https://git-core.googlecode.com/files/git-1.8.5.rc3.tar.gz
wget https://git-core.googlecode.com/files/git-1.8.5.rc3.tar.gz
tar -xzvf git-1.8.5.rc3.tar.gz
cd git-1.8.5.rc3
make prefix=/usr/local/git all doc info ;
sudo make prefix=/usr/local/git install install-doc install-html install-info ;
cd ~
nano .bashrc
Add this line at the bottom of the .bashrc file
export PATH=$PATH:/usr/local/git/bin
Exit and Save
source .bashrc
sudo visudo
Change the following line
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/git/bin"
Exit and Save
git --version
sudo git --version
Both should report the current version of git that you downloaded
git config --global user.name "Chyld Medford"
git config --global user.email "[email protected]"
git config -l (this verifies your git setup)
INSTALL LATEST NODE.JS
// ------------------------------------------------------------------------------------------ //
cd ~
cd download
http://nodejs.org/download/
Copy the link for the Linux 64-bit binary
wget http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-x64.tar.gz
sudo tar -xzvf node-v0.10.22-linux-x64.tar.gz
sudo mv node-v0.10.22-linux-x64 /usr/local/node
cd ~
nano .bashrc
Edit this line at the bottom of the .bashrc file
export PATH=$PATH:/usr/local/git/bin:/usr/local/node/bin
Exit and Save
source .bashrc
sudo visudo
Change the following line
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/git/bin:/usr/local/node/bin"
Exit and Save
To verify
node --version
sudo node --version
Install the Forever Gem
sudo npm install -g forever
Delete your Tmp Directory
cd ~
sudo rm -rf tmp
INSTALL PYTHON
// ------------------------------------------------------------------------------------------ //
cd ~/downloads
wget http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tgz
tar -xzvf Python-3.3.3.tgz
cd Python-3.3.3
./configure --prefix=/usr/local/python
make
make test
sudo make install
update PATH in .bash_profile and visudo
INSTALL RUBY
// ------------------------------------------------------------------------------------------ //
\curl -L https://get.rvm.io | bash -s stable
check your .bashrc and .bash_profile
rvm install ruby
SIMPLE WEBSITE TEST
// ------------------------------------------------------------------------------------------ //
cd ~
mkdir code
cd code
git clone http://github.com/chyld/NSS-FrontEnd
cd NSS-FrontEnd/2013-10-30-Color-Demo
npm install
node app.js
Open your web browser to your DNS and port 3000
i.e., http://ec2-23-20-254-224.compute-1.amazonaws.com:3000/colors
Your web app should be running and viewable
NODE.JS APP RUN ON STARTUP
// ------------------------------------------------------------------------------------------ //
cd /etc/init
sudo touch node.conf
sudo nano node.conf
copy the node.conf file in this gist into the file you are editing and save and exit
sudo reboot
log back in after system reboots
forever list (this will show you your node.js app running)
Open your web browser now, go to the same URL but this time port 80 or the default port
INSTALL LATEST MONGODB
// ------------------------------------------------------------------------------------------ //
cd ~/download
http://www.mongodb.org/downloads
copy the URL to the linux 64-bit version
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.8.tgz
sudo tar -xzvf mongodb-linux-x86_64-2.4.8.tgz
sudo mv mongodb-linux-x86_64-2.4.8 /usr/local/mongodb
cd ~
nano .bashrc
Edit this line at the bottom of the .bashrc file
export PATH=$PATH:/usr/local/git/bin:/usr/local/node/bin:/usr/local/mongodb/bin
Exit and Save
source .bashrc
sudo visudo
Change the following line
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/git/bin:/usr/local/node/bin:/usr/local/mongodb/bin"
Exit and Save
mongod --version
sudo mongod --version
Should have db version v2.4.8
cd ~
mkdir database
MONGODB APP RUN ON STARTUP
// ------------------------------------------------------------------------------------------ //
cd /etc/init
sudo touch mongodb.conf
sudo nano mongodb.conf
copy contents of mongodb.conf in this gist into this file
save and exit
sudo reboot
after reboot
mongo
you should be inside the mongo shell
TEST DATABASE + WEBSITE
// ------------------------------------------------------------------------------------------ //
cd ~/code/NSS-FrontEnd/2013-11-13-Socket-IO-Multiplayer-Game/
npm install
cd /etc/init
sudo nano node.conf
modify the line in the file like so and save and exit
exec sudo -u ubuntu -i NODE_ENV=production forever start /home/ubuntu/code/NSS-FrontEnd/2013-11-13-Socket-IO-Multiplayer-Game/app.js
sudo reboot
once you reboot, go to the website and the socket io game should be running
this will test both node and mongo + mongoose are running
INSTALL LATEST REDIS
// ------------------------------------------------------------------------------------------ //
cd ~/download
http://redis.io/download
get the stable version
wget http://download.redis.io/releases/redis-2.6.16.tar.gz
tar -xzvf redis-2.6.16.tar.gz
cd redis-2.6.16
sudo make PREFIX=/usr/local/redis install
cd util
sudo ./install_server
update PATHs
reboot
description "Start node.js on reboot"
author "Chyld Medford <[email protected]>"
# start node
start on runlevel [2345]
# stop on halt, maintenance or reboot
stop on runlevel [016]
# start our application with the user `ubuntu`
# change to the actual app that you want to use
exec sudo -u ubuntu -i NODE_ENV=production forever start /home/ubuntu/code/NSS-FrontEnd/2013-10-30-Color-Demo/app.js
# altering ip-table so port 80 -> 3000
pre-start script
exec iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment