|
Build a Rails application stack using Chef cookbooks available from the Cookbooks Community Site and Hosted Chef.At the end of this guide, you'll have four total Ubuntu 10.04 systems running in Amazon EC2.
If you don't already have an account with Amazon AWS, go to Amazon Web Sevices and click "Sign up". You'll need the access and secret access key credentials from the sign-up later. The Ruby on Rails application used in this guide is Radiant CMS. We're going to reuse a number of cookbooks from the Cookbooks Community Site to build the environment. For example:
|
Guide Based Upon Ubuntu 10.04 on Amazon AWS EC2 with Chef 0.10.0.Note: At this time, the steps described above have only been tested on the identified platform(s). Opscode has not researched and does not support alternative steps that may lead to successful completion on other platforms. Platform(s) supported by this guide may change over time, so please do check back for updates. If you'd like to undertake this guide on an alternate platform, you may desire to turn to open source community resources for support assistance.
|
Environment SetupFirst, let's configure the local workstation. Shell EnvironmentObtain the repository used for this guide. It contains all the components required. Use git: Chef and KnifeUbuntu/Debian users: Install XML2 and XLST development headers on your system: All Users: You'll need some additional gems for Knife to launch instances in Amazon EC2: As part of the Fast Start Guide, you cloned a chef-repo and copied the Knife configuration file (knife.rb), validation certificate (ORGNAME-validator.pem) and user certificate (USERNAME.pem) to Add the Amazon AWS credentials to the Knife configuration file. Add the following two lines to the end: Once the rails-quick-start and knife configuration is in place, we'll work from this directory. Amazon AWS EC2In addition to the credentials, two additional things need to be configured in the AWS account. Configure the default security group to allow incoming connections for the following ports.
Add these to the default security group for the account using the AWS Console. 1. Sign into the Amazon AWS Console. Create an SSH Key Pair and save the private key in 1. In the AWS Console, click on "Key Pairs" in the left sidebar. Acquire CookbooksThe rails-quick-start has all the cookbooks we need for this guide. They were downloaded along with their dependencies from the cookbooks site using Knife. These are in the
Upload all the cookbooks to Hosted Chef. Server RolesAll the required roles have been created in the rails-quick-start repository. They are in the base.rb Upload all the roles to Hosted Chef. Data Bag ItemThe rails-quick-start repository contains a data bag item that has all the information required to deploy and configure the Radiant application from source using the recipes in the application and database cookbooks. The data bag name is apps and the item name is radiant. Upload this to Hosted Chef. Decision TimeIt is time for you to decide whether you want a single instance running Radiant, or a few instances as a small infrastructure. In either case, we're going to use m1.small instances with the 32 bit Ubuntu 10.04 image provided [by Canonical|http://uec-images.ubuntu.com/releases/10.04/release-20101228/. The identifier is ami-88f504e1 for the AMI in us-east-1 with instance storage that we will use in this guide. We'll show you the knife ec2 server create sub-command to launch instances. This command will:
See the appropriate section below for instruction on launching a single instance, or launching the multi-system infrastructure. Launch Single InstanceLaunch the entire stack on a single instance. Once complete, the instance will be running MySQL and Radiant under Unicorn. With only one system, a load balancer is unnecessary. Launch Multi-instance InfrastructureWe will launch one database server, two application servers and one load balancer. One of the application server instances will include the role for running migrations as discussed before. First, launch the database instance. Once the database master is up, launch one node that will run database migration and set up the database with default data. Launch the second application instance w/o the *radiant_run_migrations* role or *radiant::db_bootstrap* recipe. Once the second application instance is up, launch the load balancer. Once complete, we'll have four instances running in EC2 with MySQL, Radiant and haproxy up and available to serve traffic. VerificationKnife will output the fully qualified domain name of the instance when the commands complete. Navigate to the public fully qualified domain name on port 80: The login is admin and the password is radiant. You can access the haproxy admin interface at: AppendixDatabase PasswordsThe data bag item for Radiant contains default passwords that should certainly be changed to something stronger. The passwords in the Radiant Data Bag Item are set to the values show below: To change the password to something stronger, modify mysql_root, mysql_debian, mysql_repl values. Something like the following secure passwords: Once the entries are modified, simply load the data bag item from the json file: Non-EC2 SystemsFor people not using Amazon EC2, other Cloud computing providers can be used. Supported by knife and fog as of this revision:
See Launch Cloud Instances with Knife for more information about using Knife to launch these instance types. For people not using cloud at all, but have their own infrastructure and hardware, use the Knife Bootstrap knife command. Note that the run-list specification is slightly different. For the first example of the single instance: See the contextual help for knife bootstrap on the additional options to set for SSH. A Note about EC2 InstancesWe used m1.small instances. This is a low performance instance size in EC2 and just fine for testing. Visit the Amazon AWS documentation to learn more about instance sizes.
|

