Alright, let's get started. SSH into the fresh Linode as root, and enable the appropriate sources:
vim /etc/apt/sources.list
Uncomment the stuff under "backports", after you've done that, then:
apt-get update
apt-get upgrade
apt-get install git-core curl
Now set the hostname, I often like to use nameofapp-main as the initial/sole instance.
echo "myapp-main" > /etc/hostname
hostname -F /etc/hostname
Now assign your machine a FQDN (Fully Qualified Domain Name)
vim /etc/hosts
Somewhere, usually at the top just blow the localhost.localdomain
bit, insert,
please substitute 0.0.0.0
with the public IP address of the machine.
0.0.0.0 myhostname.myapp.com myhostname
Set the system locale to UTF-8, so Postgres doesn't build DBs in ASCII.
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8
Configure the timezone, I recommend Etc/UTC because it's for real.
dpkg-reconfigure tzdata
Now, add your (and whoever else's) public key(s) to the root account:
mkdir ~/.ssh
cd ~/.ssh
vim authorized_keys
Insert the public keys, keener points for using scp
.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Logout of the machine and try logging in again, if it works without a password then it's time to disable noob-ass password auth:
vim /etc/ssh/sshd_config
Now, modify or add PasswordAuthentication no
and...
service ssh restart
Create the deploy user:
useradd -m -s /bin/bash deploy
Copy over SSH access stuff to the deploy user, you might want this to be different than the access for root, in that case, do your thing.
mkdir /home/deploy/.ssh
cp ~/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh/
Time to install Postgres, if you'd prefer to install MySQL or MongoDB then you should stop being an idiot:
apt-get install python-software-properties
add-apt-repository ppa:pitti/postgresql
add-apt-repository ppa:pi-deb/gis
apt-get update
apt-get install postgresql-9.1 libpq-dev postgresql-contrib-9.1
Create your app's database(s):
su - postgres
createuser -s -D -R deploy
createdb -O deploy myapp_production
Time to install Redis for all your NoSQL needs, but mostly we'll use it for queues and caching and possibly metrics.
Create a src
directory in root's home directory:
cd ~
mkdir src
cd src
Now go to the Redis website and wget the latest stable version.
wget {{redis-stable-tgz-url}}
tar -xzf {{redis-stable-tgz-file}}
cd {{uncompressed-redis-dir}}
make 32bit
make install
Now time to configure Redis, copy the redis.conf file from
config/system/redis.conf
into /etc
:
cp redis.conf /etc/redis.conf
useradd -r redis
mkdir -p /var/log/redis # <- Unless you use syslog instead
chown redis:redis /var/log/redis # <- Unless you use syslog instead
mkdir /var/lib/redis
chown redis:redis /var/lib/redis
Modify redis.conf to point to above director(y|ies) add the following to
/etc/init/redis.conf
:
description "Redis"
start on runlevel [23]
stop on shutdown
exec sudo -u redis /usr/local/bin/redis-server /etc/redis.conf
respawn
Finally, start Redis:
start redis
Time to compile and install Nginx, download the latest stable source from the Nginx Wiki, then download the latest version of the Nginx Upload Module, then compile and install:
apt-get install libpcre3-dev
./configure --with-http_ssl_module --add-module=../nginx_upload_module-2.2.0
make
make install
Then create an Nginx user and a log directory:
useradd -r nginx
mkdir /var/log/nginx
chown nginx:nginx /var/log/nginx
Now copy over the config from config/system/etc/nginx.conf
:
cp nginx.conf /etc/nginx.conf
Create an Upstart process for Nginx, insert the following into
/etc/init/nginx.conf
:
description "Nginx"
start on runlevel [2]
stop on runlevel [016]
console owner
exec /usr/local/nginx/sbin/nginx -c /etc/nginx.conf -g "daemon off;"
respawn
Now, su - deploy
and install RVM, it might be a good idea to check the RVM
website for the latest way to install RVM. It might also be a
good idea to not use RVM and use ruby-build instead:
curl -L https://get.rvm.io | bash -s stable
Ask RVM for build requirements and install them, it will usually list
subversion
as a requirement but I always lop it off and I've never had
problems:
rvm requirements
Install Ruby through RVM, when you read this 1.9.3-p194 might be old, so check
and see what the latest patch-level ism, rvm list known
, and then:
rvm install {{ruby-version}}
Make it the default interpreter for the deploy user:
rvm use {{ruby-version}} --default
Install Bundler, it's probably the only gem you'll need in the global environment:
gem install bundler --no-rdoc --no-ri
The base system is now provisioned!
You can now copy the remaining Upstart configs for the application's Unicorns
into /etc/init
from config/system/upstart
.
Now you should be able to run cap deploy:setup
and then copy over any
application config files such as database.yml.
♥ ♥ ♥