This article was sponsored by AppFog. Thank you for supporting the sponsors who make SitePoint possible.
There are many cloud platform providers out there. One of the most complete and vast offerings is the CenturyLink Cloud platform. For scope, just take a look at the menu on the CenturyLink site:
CenturyLink constantly looks for new services to add to the platform, and recently released Bare Metal servers. Previously, I wrote a tutorial on provisioning a Bare Metal server and deploying a simple Rails app on that server. Bare Metal servers fit into the gap between shared virtual machines and dedicated servers. They have the isolation of a physical box, but scale and provision more like a shared VM. I recommend you read that article to get an idea of how Bare Metal servers fit into the picture.
In this article, I am going to take the application from the previous article to the next architectural step, namely, separate repository and application servers. CenturyLink offers AppFog, which is a Platform as a Service (PaaS) like Heroku, so it makes sense to move the Rails application there. The application database will be moved from SQLite to PostgreSQL. The PostgreSQL instance will be created on a Bare Metal server, so this application is going to grow up, just a bit.
Here's a simple image that shows the new architecture:
CenturyLink Setup
Refer to the first post to sign up with CenturyLink and make sure Bare Metal is enabled.
Bare Metal Database Server: PostgreSQL
If you've followed the first tutorial, then you know how to deploy a Bare Metal server. Here, I’m going to deploy a new one for our PostgreSQL database. I want to add the new server to the existing VA1 - US East deployment (created in the first article), so I click the hamburger icon for that region:
Which then shows:
From this point forward, it's really just a matter of picking some basic options:
- Choose 'Bare Metal' for the server type
- I went with the smallest configuration (4GB)
- For the OS, I chose Ubuntu 14
It takes a few minutes for the provisioning to complete. Again, this is the same process described in the first tutorial, so refer to it if needed.
Looking at the dashboard, I now have a new Bare Metal server called VA1SPGGSPPG202. Your server will have a different name. Let's get PostgreSQL installed on it. We'll need to SSH into the box for the installation, which means assigning a public IP address and opening the appropriate ports. The default port for SSH is 22, as we all know. Remember that PostgreSQL is going to be on this machine, which uses port 5432 by default.
The provisioning of the public IP takes a few minutes. Adding a public IP is not a security best practice. Do not do this in a real production scenario. You'd at least want to restrict the source IP to your application servers for this box. More likely, a private virtual network is merited where only your servers can see your servers and the application server is the single point of entry. Even when following tutorials, you should get in the habit of using the VPN that is provided for you when you create the server. For the sake of keeping the tutorial succinct, I’ll refer you to CenturyLink’s instructions on setting up a client VPN.
CenturyLink offers many options for securing network access, so check the documentation for more or contact CenturyLink support for assistance with these options.
Once the public IP address has been added, SSH into the box using the username and password (available on the dashboard entry of the server).
ssh root@<your public ip>
root@<public ip>'s password:
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-68-generic x86_64)
* Documentation: http://ift.tt/ABdZxn
*
* The programs included with the Ubuntu system are free software;
* the exact distribution terms for each program are described in the
* individual files in /usr/share/doc/*/copyright.
*
* Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
* applicable law.
root@VA1SPGGSPPG202:~#
Excellent, we're in. Installing PostgreSQL really is pretty simple:
apt-get update
...lots of updates...
sudo apt-get install postgresql postgresql-contrib
....lots of installation fodder...
You can verify that PostgreSQL is working by switching to the postgres user and running psql:
root@VA1SPGGSPPG202:~# sudo -i -u postgres
postgres@VA1SPGGSPPG202:~$ psql
psql (9.3.10)
Type "help" for help.
postgres=#
Yup, all good. However, the postgres role is associated with the postgres Linux user (this is called "peer authentication") and is somewhat privileged. As such, let's create a role that we can use for our application. Exit psql by typing \q so you're back at the Ubuntu command prompt and then type:
vi /etc/postgresql/9.3/main/pg_hba.conf
This opens the file in vi. By default, PostgreSQL is configured to use Peer Authentication only, but we want to use Password Authentication. Find the following line:
local all postgres peer
Change it to:
local all postgres md5
Also, add the following line to the file:
host all all all md5
This enables PostgreSQL to accept incoming connections from remote hosts.
Save and exit the file (:wq).
Next, PostgreSQL needs to be configured to listen for remote connections. This is done in the main configuration file:
vi /etc/postgresql/9.3/main/postgresql.conf
Find the line with listen_addresses, uncomment it, and change it to:
listen_addresses='*'
Note: These are not recommended security practices for a production PostgreSQL instance. This is intended purely as an illustration of a dev PostgreSQL environment.
Back at the command prompt:
postgres@VA1SPGGSPPG202:~$ createuser --interactive
Enter name of role to add: thingsuser
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
Password:
postgres@VA1SPGGSPPG202:~$
You should now be able to login using that user and psql:
psql -U thingsuser -d postgres
Password for user thingsuser:
psql (9.3.10)
Type "help" for help.
postgres=>
We’re ready to set up our Rails application on AppFog.
Continue reading %How to Set Up a Rails App with CenturyLink’s AppFog & Bare Metal%
by Glenn Goodrich via SitePoint