KrisF's Blog http://krisforbes.ca Thoughts on SMB IT posterous.com Mon, 25 Jul 2011 17:26:00 -0700 Deploying with Inploy - An alternative to Capistrano http://krisforbes.ca/deploying-with-inploy-an-alternative-to-capis http://krisforbes.ca/deploying-with-inploy-an-alternative-to-capis

Inploy is similar to Capistrano but easier - it has better defaults and it is more forgiving when you don’t know what you’re doing (me).

Inploy on your development machine:

  • add to Gemfile: gem ‘inploy’
  • bundle install --without production

Create deploy.rb under your app’s config directory. The basic config/deploy.rb file:

application = "test"
repository = 'git@git.assembla.com:my-apps-repo.git'
hosts = ['zer1']
path = '/home/deploy'

Notes on deploy.rb:

  • default user is ‘deploy’
  • deploys to #{path}/#{application}
  • Inploy’s hosts will look to your development machine’s .ssh/config (so add your production server)

Inploy commands:

Pull the app from repo, bundle install, create database, migrate:

  • bundle exec rake inploy:remote:setup

Once you’re setup, you can update your app and repo:

  • bundle exec rake inploy:remote:update

That’s it! You can learn more about Inploy on Github.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1351503/avatar.jpg http://posterous.com/users/4SycOXLGr4qt Kris Forbes MrKrisF Kris Forbes
Mon, 25 Jul 2011 16:59:00 -0700 Rails on Ubuntu 10.04: Passenger, Nginx, MySQL, Varnish http://krisforbes.ca/rails-on-ubuntu-1004-passenger-nginx-mysql-va http://krisforbes.ca/rails-on-ubuntu-1004-passenger-nginx-mysql-va
I setup a new VPS this weekend and decided to share my notes.

My notes are from being logged in as root. If you're logged in as another user, you'll be typing sudo a lot. :)

Configure your locale
 
  • locale -a
  • locale-gen en_US.UTF-8
  • update-locale LANG=en_US.UTF-8
  • update-locale LANGUAGE=en_US.UTF-8
  • exit
  • ssh zer1 #zer1 is my VPS added to ~/.ssh/config 
  • locale -a #should have en_US.UTF-8 listed 
  • update-locale #errors? 

Set your time zone

  • dpkg-reconfigure tzdata
  • ntpdate ntp.ubuntu.com

Update Ubuntu

  • apt-get update && apt-get upgrade

Install dependencies

  • apt-get install build-essential libmagickcore-dev imagemagick libxml2-dev libxslt1-dev git-core libapr1-dev libssl-dev libmysqlclient15-dev libcurl4-openssl-dev curl libncurses5-dev libreadline5-dev libopenssl-ruby1.9

Install MySQL

  • apt-get install mysql-server libmysqlclient-dev libmysqlclient15-dev libmysql-ruby
  • mysql_secure_installation

Install latest Ruby from source

Set default environment for Rails

  • nano /etc/environment
  • add the following line to it:
  • export RAILS_ENV=production

Install Nginx and Passenger

Configure Nginx

  • mkdir /opt/nginx/conf/sites-enabled
  • nano /opt/nginx/conf/nginx.conf
  • add this within the http { } block:
  • change default listen port to 8080
  • include /opt/nginx/conf/sites-enabled/*;
  • nano /opt/nginx/conf/sites-enabled/test

*note port 8080 for Varnish

server {
   listen 8080;
   server_name mywebsite.com;
   root /home/deploy/test/public;
   passenger_enabled on;
}


  • service nginx restart

Add deploy user

  • adduser deploy
  • su deploy #switches to deploy
  • ssh-keygen -t rsa -C “deploy@myserver”
  • cat ~/.ssh/id_rsa.pub
  • copy the output into your favorite Git hosting as an allowed key (Assembla, Github, etc)
  • on your development machine:
  • cat ~/.ssh/id_rsa.pub
  • on the server as deploy user:
  • nano ~/.ssh/authorized_keys
  • paste in your development machine’s public key
  • git clone git@git.assembla.com:myapp.git      #lets you add host as known_host
  • rm -rf myapp         

Create a MySQL user and database

  • mysql -u root -p
  • create database myapp_prod;
  • create user 'mydbuser'@'localhost' identified by 'secret';
  • grant all privileges on myapp_prod.* to 'mydbuser'@'localhost';

Install Varnish HTTP cache

  • apt-get install subversion autotools-dev automake1.9 libtool autoconf libncurses-dev xsltproc quilt debhelper
  • svn co http://varnish-cache.org/svn/tags/varnish-2.0.5
  • cd varnish-2.0.5/varnish-cache
  • dpkg-buildpackage
  • cd ..
  • dpkg -i libvarnish1_2.0.6-2_i386.deb
  • dpkg -i varnish_2.0.6-2_i386.deb
  • service varnish start

Configure Varnish

  • nano /etc/varnish/default.vcl
  • Leave this at defaults, but now you know where it is :)
  • nano /etc/default/varnish
  • Comment out DAEMON_OPTS use the following instead:
  • DAEMON_OPTS="-a :80 -f /etc/varnish/default.vcl -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
  • service varnish restart

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1351503/avatar.jpg http://posterous.com/users/4SycOXLGr4qt Kris Forbes MrKrisF Kris Forbes
Sun, 17 Jul 2011 20:10:00 -0700 Migrating to Google Apps Standard from Cpanel http://krisforbes.ca/migrating-to-google-apps-standard-from-cpanel http://krisforbes.ca/migrating-to-google-apps-standard-from-cpanel

So I just had a nightmare of a time bouncing from cPanel providers. I figured there had to be something better that I could offer small businesses I work with.

I decided to run a trial of Google Apps Standard for two weeks and consider if it would be viable to move businesses using cPanel to Google Apps Standard accounts.

The trial went well. I used Google Apps for two weeks and had no service disruptions and migration was painless. After the trial, I moved my family's small business http://midhurstroofing.ca to Google Apps. 

Here's some problems I encountered during the migration and how I fixed them:

1.  Microsoft Outlook + POP3 + Google Apps Migration Tool = TimeStamp fail

I finished my first user and hooked up IMAP. All the dates for messages were wrong. The dates shown after the migration were all < 1 day and they should have gone all the way back to 2009. WTF!

Apparently the problem is related to Outlook displaying the DateTime from a part of the message header that is updated during the migration. I found two solutions to this:

The first, was to use an email client other than Outlook. Literally any other client has no issues with the Google Apps Migration Tool - Mozilla Thunderbird, Apple Mail, mobile clients, etc.

The second, for those that have users that are too used to Outlook to switch cold turkey, is to change Outlooks view to sort and display the Sent DateTime of the message header instead of Received(default). To accomplish this:

- click the Sort by Date at the top of your message list.
- click custom
- change Sort to Sent

This view change is on a per-folder level, meaning you'll have to do it on a couple folders. Depending on your user, usually Inbox and Sent is a must.

All future emails (not migrated) will have the proper information in the headers for Outlook to handle this under default settings. Hopefully Microsoft improves IMAP to handle this like other email clients do.

2.  Users were used to an Inbox under Personal, now the IMAP mailbox is a separate item in the Navigation Pane

For this one, I made sure unused PST/Archives listed in the navigation pane were removed (AutoArchive) since users get boat loads of storage with Google Apps, there's no need to retain copies locally. 

The next thing was to either hide or delete email messages on the user's machine. I recommend hiding them in a subfolder until you're confident the move to Google Apps is complete.

Next is to make sure when Outlook is started, it shows their IMAP inbox instead of their old Inbox. To do this:

- Tools > Options > Misc tab
- Advanced Options
- Change which folder is opened when Outlook runs
- Select the inbox under IMAP

After that's done, I collapsed the whole Personal archive in the navigation pane.

This results in a Navigation pane that looks very similar to the user's old one.

3.  Sent items need to go into GMail

Make sure their sent items are properly being placed in their GMail Sent Items and not a local folder or the copy Google Apps Migration Tool makes.

4. I need to clean up IMAP folders but it says Permission Denied

GMail only allows the deletion of IMAP folders through the web interface. For this, I suggest you login to the web interface and use Manage Labels to clean things up.

Manage Labels interface:
Pastedgraphic-1

As you can see, there's a lot of garbage folders that one might not necessarily use that get copied in a migration.

That's all! Overall I'm pleased with the outcome and I hope users are too. :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1351503/avatar.jpg http://posterous.com/users/4SycOXLGr4qt Kris Forbes MrKrisF Kris Forbes
Sat, 11 Sep 2010 18:07:00 -0700 Rails 3 on AWS micro: CentOS Nginx Passenger http://krisforbes.ca/rails-3-on-aws-micro-centos-nginx-passenger http://krisforbes.ca/rails-3-on-aws-micro-centos-nginx-passenger
Rails 3 Stack: Ruby 1.9.2 + Nginx + Passenger + MySQL on CentOS AWS micro

Note: This was tested on AWS using a micro instance and ami-6b608c02 which seemed to be the most barebones community CentOS i386 EBS AMI I could find. It works as a Micro instance out of the box without issues.

Prepare the Server

Update the system and install required libraries
  • yum update -y
  • yum groupinstall "Development Tools" -y
  • yum install zlib-devel wget openssl-devel pcre pcre-devel readline-devel sudo nano -y

Configure Time Settings
  • yum install tzdata system-config-date -y
  • yum install ntp -y

Contact NTP server and update time:

Configure the hostname
Write loopback IP and your hostname in your /etc/hosts file:
Write your hostname to /etc/hostname

Installing the Application Stack

Install MySQL
  • yum install mysql mysql-devel
Secure your MySQL install:
  • mysql_secure_installation

Install Ruby
Ignore ri and rdoc for this server
  • nano ~/.gemrc
Add these two lines:
  • install: --no-ri --no-rdoc
  • update: --no-ri --no-rdoc

Download Ruby from source and install:

Check that Ruby and RubyGems all were installed correctly:
  • ruby -v
  • gems -v

Clean up the Ruby source files:
  • cd ..
  • rm -R ruby*

Install Git (Good idea for Capistrano deployments)

Install Rails and Passenger gems
  • gem install rails
If you need a specific version of Rails:
  • gem install rails -v=2.3.8
  • gem install passenger

Install modified Nginx with Passenger built-in
  • passenger-install-nginx-module
Option 1

Create init scripts for Nginx

Verify the script can start and stop Nginx:
  • sudo /etc/init.d/nginx start

  * Starting Nginx Server...
  ...done.

  • sudo /etc/init.d/nginx status

  nginx found running with processes:  11511 11510

  • sudo /etc/init.d/nginx stop

  * Stopping Nginx Server...
  ...done.

Add Nginx to startup:
  • sudo /sbin/chkconfig nginx on
Check that it starts and stops with the server by:
  • reboot
Install ImageMagick and RMagick (Optional)
  • yum remove imagemagick
  • yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel
  • yum install libjpeg-devel libpng-devel glib2-devel fontconfig-devel zlib-devel libwmf-devel freetype-devel
Download the ImageMagick Source
  • wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
  • tar xvfz ImageMagick.tar.gz
  • cd ImageMagick-6*
  • ./configure --prefix=/usr --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes
  • make && make install
Install RMagick
  • gem install rmagick

Create a ‘deployer’ user (Recommended)

Add the user
  • useradd deployer
  • passwd deployer

Give deployer sudo permission
  • nano /etc/sudoers
Add this near the bottom of the file:
  • deployer    ALL=(ALL)     ALL

Test the account

End your SSH session

Lock the root account
  • sudo passwd root -l

Test a Rails 3 app

Create the testapp
  • rails new testapp -d mysql
  • cd testapp
  • bundle install
Enter your database password in your database.yml real quick
  • nano config/database.yml
  • rake db:create:all
  • rails generate scaffold post title:string body:text
  • rake db:migrate
Check really quick that WeBrick can start the rails app before we involve Passenger/Nginx
  • rails server

Change the user Nginx runs as
  • sudo nano /opt/nginx/conf/nginx.conf
At the top of the config file, uncomment or change “user nobody;” to:
  •  user deployer;

Add a virtual host to Nginx
  • sudo nano /opt/nginx/conf/nginx.conf

Find the server { } block in the default file and remove it. Add this:

server {
    listen 80;
    # server_name www.mycook.com;
    root /home/deployer/testapp/public;
    passenger_enabled on;
}

Restart Nginx:
  •  sudo /etc/init.d/nginx restart

Try accessing your testapp
In your web browser:

Tweaking Nginx/Passenger

Enable gzip
  • sudo nano /opt/nginx/conf/nginx.conf
Find the existing commented “ #gzip on; ” and remove it and replace it with the following:

gzip on;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

Longer expiration tags on content served by Nginx

Place the following in your virtual host’s server { } block:

location ~* \.(ico|css|js|gif|jp?g|png)(\?[0-9]+)?$ {
      expires max;
      break;
  }

Reduce Passenger spin-up time

Place the following in your virtual host’s server { } block:

#Passenger options
rails_spawn_method smart-lv2; # This can cause problems with some apps
rails_app_spawner_idle_time 0;
rails_framework_spawner_idle_time 0;

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1351503/avatar.jpg http://posterous.com/users/4SycOXLGr4qt Kris Forbes MrKrisF Kris Forbes