Monday, April 4, 2011

Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Three)


Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Three)

In Part Two, we successfully installed Apache and Ruby.  In this part, we’re going to focus on Rails, some gem dependencies for our application, and decide on our database and web server in rails.  Once done, I’m going to try to work on some additional configuration for our server. So, with that said, let’s start with installing Rails.  

First, there are two choices we can make here.  We can install the latest version of Rails, or install the latest version of EDGE rails; the latter being the cutting edge of rails development. Because my goal here is working with LDAP authentication and functionality, I’m going to stick with the very basics.  Let’s start.

=> gem install rails


As you can see, rails installed a lot of core dependencies here.  Now, I want to make things simple in terms of where my app is going to launch.  So, I’ll create a directory called Web in the root of C:\ and place my new application in there.

C:\>md web
C:\Web>rails new ldap


Good.  I now have a new application for rails called ldap located in C:\Web\ldap.

I’m also going to have to install the DevKit properly in case any gems need to be built on Windows Server 2008.  I already have the development kit downloaded, so I’m going to extract it into a directory called:

C:\DevKit>

Once extracted, I need to go to that directory and type the following commands:

=> ruby dk.rb init
=> ruby dk.rb install

The init command creates a .yml (YAML) file that houses the directories on the server where ruby is installed.  By default it knows that Ruby192 was already listed in C:\ and so no modification was necessary.  Once I ran the install, it created some enhancements in the existing ruby directory for C:\Ruby192.

If you need to see more instructions about the DevKit, you can go here:


The Database

Rails already comes with a default database called SQLite3.  Because this is a simple test application, I’m going to keep this default.  However, Windows Server 2008 doesn’t know what this is.  You still need to download the .dll library.  You can find it here:


I only need the .dll so I’ll install that in downloads and then extract and move the .dll into my C:\Ruby192\bin directory.  This directory is already added to my system path, so it’ll find it just fine.

I’ll modify the gem file and take a peek and for now, everything is exactly what I need. There’s nothing I need to do here until later.  Let’s go ahead and test whether or not we have a basic functioning rails app.

C:\Web\ldap\>bundle install
C:\Web\ldap\>rails s

Bundling will make sure any gems, and dependencies I need are installed and once complete,rails s will start the server.  Once the server starts (using a generic webrick server), let’s go to http://localhost:3000 (in my case) and take a look:


Great!  It’s working.  We’re riding Ruby on Rails on Windows Server 2008.  No time to pat myself on the back yet, I still have quite a few things left to do here.  Let’s get to work!

I want to get thin installed, but unfortunately on Windows, thin (which requires rack and eventmachine) can be a pain in the butt to install.  However, there’s a great work around we can do on Windows to get this installed and it partly uses “Git” to accomplish this task.   I’ll eventually be using Git anyways later on to backup my source code, so I’ll just go grab a copy of it from here:


When I install it, I want to include the git bash here and git gui here context menu entries and also make sure you choose “as is” on the following screen so you don’t get the CRLF issues when pushing your source files later on.


Now then, I have Git successfully installed, but before I do anything I’ll need another gem called specific_install.  From a windows command prompt type the following:

=> gem install specific_install

Now that I have this gem installed, I’ll right-click anywhere on a directory in windows explorer (and choose git bash here).

Run gitbash and type:

=> gem specific_install -l git://github.com/eventmachine/eventmachine.git

This should install the latest beta or latest eventmachine file, which is required by Thin to operate.  Rack already came with the latest version of rails, so nothing is needed here.  You might be saying whoa!! Why aren’t you just using the Developer Kit and compiling eventmachine.  Well, on windows server 2008 64-bit, that’s not going to work.  I will get a compile error with eventmachine only.  Now then, once downloaded  let’s run (from the windows command line):

=> gem install thin

Great, it installs just fine!  Let’s try running it: (using the command rails s thin)


And, let’s open a web browser and see what happens:

.. yay, it’s working. 

So, the one thing that people may complain about with Ruby and Ruby on Rails is that setting things up is no easy task on Windows.  This is primarily why most people that develop with Rails tend to use Linux or Mac, and even Mac can run into its own complexities.   With Windows however, you have to remain calm and be patient throughout the installation process.  Before we continue, let’s recap what we have accomplished so far:

  • Installed and configured Windows 2008 Server EE (64 bit) with Active Directory as its primary role (although AD is not currently configured)
  • Installed Apache 2.x (as our load balancer) (still needs configuration)
  • Installed Ruby 1.9.2(p180)
  • Installed the Ruby Development Kit
  • Installed Ruby on Rails v. 3.0.5
  • Configured Sqlite3 as our database
  • Installed THIN as our fast HTTP Web Server
  • .. and tested that it works for the most part.

That's a pretty big list already!  So, before we move on, let’s take a break and rest and come back tomorrow and continue with our setup.  See you in part four..

Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Two)


Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Two)

So, looking back at part one, I was happy to get most of the server software installed and initially configured.  However, I know there’s still quite a few things to do here.  I haven’t even started to install Ruby or RoR yet, and it's always a lot of fun having to grab a hundred or so critical microsoft patches! 

The next thing that I need to do is perform a few updates, namely running windows updateto get the server up to par.  Once done, I’ve decided to disable Internet Explorer protection, which is the largest nag feature ever invented for Windows Server Environments.  Normally, in a production server environment, there’s absolutely no reason to have browsing enabled.  But, since this is a 100% test environment, I want to enable it.  The easiest way to do this is through the administrator tools à server manager. 




If you click on the root of the Security Manager and scroll down to Security Information, you can click Configure IE ESC.  I’m going to turn this feature off for both admins and users.  It will make testing easier.  But, again, on a normal production server you would not have any browsing on anyways so this would not be turned off.

Once our updates are completed and the server has been restarted, we can start thinking about how we want to go about the rest of the project.

Deciding on Web Servers

After much research, my goal is going to be to use Apache as a Web Server load balancer and couple it with a fast HTTP server that can run Ruby.  I can go with either Mongrel or Thin in this respect, but I’ve decided that Thin will work best for this first project.  Mongrel or Thin can work completely on their own without Apache, but they wouldn’t be able to handle load balancing and it would only allow for a very light load.  This is why I’m using both together.  The only thing to note is that Apache does not come with 64-bit support for windows.  Oh well, we can’t have everything perfect now can we?  To simplify things, here is a list of items I will be downloading before I continue:

Downloads:

Apache:

Ruby 1.9.2:

Developer Kit-Ruby:

Once everything has been downloaded, I’m ready to start the installation of Apache. Everything appears pretty simple here.  I chose all of the defaults, changing the administrator email to a local one, and selected the default locations.  Once the installation is completed, I see the apache icon in the system tray and it shows the service has been started.  So far, so good.  Let’s go ahead and install Ruby.

I’m going to keep the default ruby location for C:\Ruby192, but I will set the ruby executables in the path and associate the .rb and .rbw extensions.  I will then click install and let it finish the installation.





Now that the basic installations are installed, let’s test out Ruby and see if it works.

We can do ruby –v to find out our ruby version.  We can also do a gem –v to find our gem version.  Finally, we can run IRB and type in 2 + 2 to see 4.





The paths were already set so we can do this from any command prompt in any path.  So far so good!  If I run a gem update system there’s nothing to update.  Okay, we’re in good shape here.  At this point I’m going to save my snapshot and make sure everything is saved.  We actually covered a lot in this part two, so we'll work on some new things in part three.

Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part One)


Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part One)

One of my burning short term ambitions has been to build some key ruby on rails applications for my company.  My company is primarily a windows shop that uses ASP.NET and Windows Server 2008.  Like most companies, sometimes it's difficult to move away from standardization and into innovation.  I'm not saying that Ruby and Ruby on Rails is the most innovativelanguage and framework around.  No, I'm merely stating that sometimes it's difficult for people to move away from standard practices and think outside of the box.


So, to further my own ends, I’ve decided to build a Ruby on Rails application on Windows Server 2008 Enterprise Edition.  It appears difficult, it’s a nice challenge, and I want to showcase some nice RoR apps to the management team at my company.  But, I know I’m going to be stretching things a bit to get everything I want out of a pure windows shop.  The easiest thing I can do here is to focus on a few core ideas that I've been interested in, and go from there.


My company loves using ASP.NET with IIS and Active Directory.  I don’t want to use or have to rely on IIS for anything in my application.  I will definitely need to communicate with Active Directory so I need some type of LDAP communication in my app.  IIS and Fastcgi is too cumbersome imho, and I already have a few concepts in production on linux that I want to try and use on windows.  So, instead I’ll be using devise_ldap_authenticatable (https://github.com/cschiewek/devise_ldap_authenticatable).  This gem will allow me LDAP functionality with Active Directory and I can skip using IIS and fastcgi, which sometimes becomes an alternative in this scenario.  I might make some folks angry in my work place for bypassing IIS, but that's to be expected.  You can't make everyone happy.


As far as web servers are concerned, I want to use Apache as my load balancer.  It can handle the amount of people that will access the applicatioin, and it will allow me to use a faster web server with my rails application.  I had originally thought about using Mongrel, but I've started to move away from Mongrel lately.  I'm opting for Thin instead. 

But, for now, let’s start with some initial setup and work on customization later. 

I will need to use Windows Server 2008 EE, and one nice item that Microsoft provides is a free evaluation copy of this OS for 60 days that can be re-armed 3 additional times.  Re-arming allows you to reset the 60-day evaluation by running a supported Microsoft script.  That gives me 240 days of free evaluation of Windows Server 2008 EE, which is more than enough time for me to develop and showcase my app to the management team.  I will also put it on VMWare so that it’s virtualized, which will allow me to make snapshots before implementing critical changes down the road.  So, let's start by grabbing a copy here:  


http://www.microsoft.com/downloads/en/details.aspx?FamilyId=13C7300E-935C-415A-A79C-538E933D5424&displaylang=en .  


Don’t worry if the download link doesn’t work or isn’t correct.  Just do a search for it and you’ll find the free version of the one you want to use most.  In my case, I’m going to use the amd64 version because I am coding on a 64-bit machine.  So, I’ll grab a copy of the ISO for amd64, store it on a secondary development drive, and I’m ready to begin setting it up.

Installation is going to be fairly simple here. I can launch VMware, click New Virtual Machine, and point the new installation to the ISO image I downloaded.  I chose Windows Server 2008 Enterprise and will use the simple install to finish up the installation.  When I was asked for the license key, I left it blank and hit next and chose NO so that the activation would not take place.  This will start the 60-day evaluation timer and I’m off and running.  In terms of what type of VMware hardware I’m going to run, I think I’m going to set the space to 60GB, and use2GB of RAM for the server.  That should be more than enough to start.

Once it’s fully installed, I see the following startup screen:



The first thing I think I’m going to do is install the VMware tools.  This can be done by clickingVM, clicking reinstall VMWare tools, and running the setup.exe program when the popup arrives.  You can then click next, followed by modify, and I’m going to make sure that all features of the tools are installed.  Once completed, I click next, and modify again, and the toolset is reinstalled with everything requested.  At this time, I think I’m going to restart my server and make sure everything looks fairly clean before I go any further.  (waiting.. waiting.. eating popcorn..)  Hey, it appears to be running fine!

Choosing what roles this server will perform is going to be a little different than I expect to see at my work place.  This is mainly because I need to test Active Directory and so I’m going to make this server have an ADDS role.  With ADDS, you can’t add Application or Web Server roles at the same time. 



Click Next and accept the defaults and choose install to begin the ADDS installation.  Once finished, I will need to run dcpromo.exe to make it a fully functional domain controller.  But, I don’t want to do this just yet.  I think I’m going to change my server name first.

 
I like ROR-DEVAPP01 as a good name (Ruby on Rails – Development Application 01).  Once I change the name, it’s going to ask me to restart and I can work on the domain controller promotion next.  When it’s restarted, I go to Start, type in dcpromo and hit enter and begin the installation.  I don’t want to use advanced installation features.

The first screen is a little daunting because I got a nasty big scary screen talking about older operating systems and algorithms, etc. – wooo.., ghosts in the machine.  Why does Microsoft always want to scare the hell out of you!

I skip the message, continue right along and check “Create a new domain in a new forest” and click Next.  How about that, another big scary looking message!:


This just states that the Local Administrator account either doesn’t have a password set, or it’s not a strong enough password.  Well, how about I change it to [administrator = !Ruby on Rails#] | [admin = !Ruby on Rails#].  This will fix this error.  You can accomplish this by going through Computer Management.
I’m going to name my FQDN after something fictitious – how about corp.ruby.com.  After performing some verification, everything checks out.  I’m going to set the functional level of the forest to Windows Server 2008 and click next.  In addition, I’m going to leave the DNS server checked, and click next.

At this point the IP address will be dynamically assigned for now, so click Yes.  Normally, I would set this statically, but this is a test environment.  Since we’re working in a virtual environment, it’s pretty simple to keep this setting as dynamic for now.  Production servers would have static IP addresses assigned.


I accept the defaults and ignore any errors, and reboot upon completion.

So, it’s been a pretty good start for part one.  I have a Windows Server 2008 EE server setup with active directory and DNS, the forest has been named, and the sever has been renamed as well.   I’ve built some simple personalization and virtualization is complete.  I think I’ll stop for now and start again tomorrow.  Here’s what it looks like at the end of Part One:


We'll cover more in part two.  See you then!