Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active June 3, 2016 04:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak/d35659b7302843694b3a788d4d26b180 to your computer and use it in GitHub Desktop.
Save deepak/d35659b7302843694b3a788d4d26b180 to your computer and use it in GitHub Desktop.
App setup for a rails app on AWS (separate database server)
# provisioning a rails stack with
# - ngixn web server and reverse proxy
# - puma app server
# - redis
# - elasticsearch
# - Amazon RDS using etc for the SQL database
# installed on an AWS EC2 instance running Ubuntu 14.04 LTS
# fix locale.
# needed to remove login warning
# and to create postgres database
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
echo "LANG=en_US.UTF-8" >> /etc/environment
echo "LANGUAGE=en_US.UTF-8" >> /etc/environment
echo "LC_CTYPE=en_US.UTF-8" >> /etc/environment
source /etc/environment
sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales
sudo apt-get update && sudo apt-get -y upgrade
# add user deploy for deploying code
sudo useradd -d /home/deploy -m deploy
sudo passwd deploy
# equivalent to adding `ALL=(ALL:ALL) ALL` in sudoers
usermod -a -G sudo deploy
# will use user for capistrano deploy
su - deploy
ssh-keygen # no password
# cat .ssh/id_rsa.pub
# and add to deploy keys on github
# add your public key to ~/.ssh/authorized_keys (for the deploy user)
# check with ssh deploy@<aws-ip-address>
# aws ip and FQDN will keep on changing on stop-start'ing the EC2 server
# for viewing directories
sudo apt-get install tree
sudo apt-get install git
sudo apt-get install nginx
unlink /etc/nginx/sites-enabled/default
# can use `capistrano/puma/nginx` or bootstrap for an nginx script
# for building rubygems native extensions
# is an overkill. need gcc and make
sudo apt-get install build-essential
# for building the mysql2 gem
sudo apt-get install libmysqlclient-dev
# install ruby
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby2.3 ruby2.3-dev
sudo gem update --system
sudo gem install bundler --no-ri --no-rdoc
# mkdir dir for capistrano
# as deploy user
mkdir -p ~/apps/rails-app/shared/config
# create an Amazon RDS instance
# add a security group to the EC2 app server
# add another to this RDS instance to only allow connections from that group
# test that the EC2 server can access it:
# mysql -h <RDS-host> -P 3306 -u <db-name> -p
# for web server install only redis-tools
sudo apt-add-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-tools
# install rabbitmq
# https://www.rabbitmq.com/install-debian.html
# https://www.ejabberd.im/epmd
echo 'deb http://www.rabbitmq.com/debian/ testing main' |
sudo tee /etc/apt/sources.list.d/rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc |
sudo apt-key add -
sudo apt-get update
sudo apt-get install rabbitmq-server
service rabbitmq-server status
service rabbitmq-server stop
epmd -kill
# some useful commands:
# - sudo netstat -ntlap
# listening services
# - sudo lsof -n -a -i -urabbitmq
# listening services by a user
# install elasticsearch
# https://gist.github.com/Globegitter/662713f90d5af5b4269d
# https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
java -version
wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -
# https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.3/elasticsearch-2.3.3.deb
echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch
# start elasticsearch during bootup
sudo update-rc.d elasticsearch defaults 95 10
sudo service elasticsearch start
sudo service elasticsearch status
sudo lsof -n -a -i -uelasticsearch
sudo cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.original.yml
# changes in elasticsearch.yml:
# - cluster.name to something meaningful
# - network.host to localhost. so that it listens only on localhost
# - add script.disable_dynamic: true
# need to check for 2.3. this is no longer valid
# for redis server
# install redis
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server
service redis-server status
# test that redis-server is accessible from the EC2 server
redis-cli ping
# edit /etc/redis/redis.conf
# uncomment bind 127.0.0.1 to listen on all interfaces
# change tcp-keepalive to 60
sudo service redis-server restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment