Rails in the wild (on Debian), step-by-step, against the clock 4 comments

Posted by robon March 13, 2007

Alright, I'm about to re-deploy my blog onto a server that I've gone in with (with about 6 other friends). It's a Debian box located across the pond, in Germany. I've logged into the box once to set up my shell environment, but otherwise haven't done anything special to get Rails cooking and my blog deployed. I'll document the steps it takes me from now to having my blog deployed. I hope this helps at least a handful of people somehow. Oh, and I'm timing myself, because I only have about an hour (it's 9:41pm). Ready? Go!

Hmm, might be logging in to this box alot.. better set up keys:

(Uh oh, just lost some time. I decided it I'm going to do this, then just to do it. I logged into GoDaddy and tollerated their interface long enough to point blog.tupleshop.com to my IP on the German box, that I affectionately call "hosten boxen.")

Log into box, look around... create a dir named ".ssh":

1
2
3
4
5
6
7
8
9
rob@mac:~
$ ssh rob@85.10.241.146
rob@85.10.241.146's password: 
rob@unicron:~$
rob@unicron:~$ mkdir .ssh
rob@unicron:~$ ls -al .ssh/
total 8
drwxr-xr-x 2 rob 4096 Mar 13 06:00 ./
drwxr-xr-x 4 rob 4096 Mar 13 06:00 ../

Get out and push up my key:

1
2
3
4
5
6
7
8
rob@unicron:~$ exit
logout
Connection to 85.10.241.146 closed.
rob@mac:~
$ cat ~/.ssh/id_dsa.pub | ssh rob@85.10.241.146 "cat >> .ssh/authorized_keys2"
rob@85.10.241.146's password: 
rob@mac:~
$

Smooth sailing from here.

1
2
3
4
$ alias blog='ssh rob@85.10.241.146'
rob@mac:~
$ blog
rob@unicron:~$

Okay, I know I have Ruby 1.8.5 because my friend knew I would need it. I also know I have Apache 2.2.3 because I had asked about that too. This is good. It means I can use mod_proxy_balancer to manage request being sent back to my Mongrel cluster. Let's see if that module is enable:

1
2
3
4
5
rob@unicron:~$ cd /etc/apache2/
rob@unicron:/etc/apache2$ ls mods-available/*balanc*
mods-available/proxy_balancer.load
rob@unicron:/etc/apache2$ ls mods-enabled/*balanc*
ls: mods-enabled/*balanc*: No such file or directory

So I enable it, with:

1
2
3
4
5
6
7
8
rob@unicron:/etc/apache2$ sudo a2enmod proxy_balancer
Password:
Enabling proxy as a dependency
This module is already enabled!
Enabling cache as a dependency
Module cache installed; run /etc/init.d/apache2 force-reload to enable.
Module proxy_balancer installed; run /etc/init.d/apache2 force-reload to enable.
rob@unicron:/etc/apache2$ sudo apache2ctl restart

Now, set up http.conf:

1
2
rob@unicron:/etc/apache2/sites-available$ sudo cp default tupleshop.com
rob@unicron:/etc/apache2/sites-available$

For now (until DNS propagates) I'll set this up on port 8080:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
rob@unicron:/etc/apache2/sites-available$ cat tupleshop.com 
Listen 85.10.241.146:8080

<Proxy balancer://prncluster>
    # cluster members
    BalancerMember http://127.0.0.1:4000
    BalancerMember http://127.0.0.1:4001
</Proxy>

ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

<VirtualHost 85.10.241.146:8080>
    ServerName   blog.tupleshop.com
    ServerAdmin  webmaster@tupleshop.com
    ProxyPass / balancer://prncluster/
    ProxyPassReverse / balancer://prncluster/
</VirtualHost>

Then, enable the site:

1
2
unicron:/etc/apache2/sites-enabled# ln -s ../sites-available/tupleshop.com 001-tupleshop.com
unicron:/etc/apache2/sites-enabled# vi 001-tupleshop.com

Have Ruby but need gems:

1
2
3
4
5
rob@unicron:~$ cd /usr/local/src/
rob@unicron:/usr/local/src$ sudo wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
rob@unicron:/usr/local/src$ sudo tar xvzf rubygems-0.9.2.tgz
rob@unicron:/usr/local/src$ cd rubygems-0.9.2
rob@unicron:/usr/local/src/rubygems-0.9.2$ sudo ruby setup.rb

Okay, now get Rails:

1
2
3
rob@unicron:~$ sudo gem install rails -y
...
Successfully installed rails-1.2.2

oh, and Mongrel & mongrel_cluster:


rob@unicron:~$ sudo gem install Mongrel

Crap! No make?? no gcc? Alright... Look online for Ben (path of least resistance):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[10:34] RobO> ah!@
[10:34] RobO> no gcc
[10:34] RobO> f**k
[10:34] RobO> :)
[10:34] BenB> looks like gcc-4.1 is on there?
[10:34] RobO> oh
[10:34] RobO> need some nice symlinks
[10:35] BenB> yea... cause you gotta do gcc-4.1
[10:35] RobO> make too
[10:35] RobO> scripts use them
[10:35] BenB> wait
[10:35] BenB> nevermind
[10:35] BenB> hit gcc
[10:35] BenB> fine now
[10:35] BenB> that was weird
[10:35] BenB> I used aptitude install gcc
[10:35] BenB> and it made links to the 4.1 install or something
[10:36] RobO> and make?
[10:36] RobO> need that to
[10:36] BenB> done
[10:36] BenB> weird, it made links for that too
[10:36] RobO> heh
[10:36] RobO> cool

Okay, rockin' now. Again, get Mongrel:

1
2
3
4
rob@unicron:~$ sudo gem install Mongrel
...
rob@unicron:~$ sudo gem install mongrel_cluster
Successfully installed mongrel_cluster-0.2.1

Get the source, Luke:

1
2
3
4
rob@unicron:~$ sudo mkdir /var/www/blog.tupleshop.com
rob@unicron:~$ sudo chown rob /var/www/blog.tupleshop.com/
rob@unicron:~$ cd /var/www/blog.tupleshop.com/
...

Uh oh... tried to "svn up" and looks like svn has not been configured "--with-ssl". I'll just scp 'till we get that sorted out:


$ scp -r /var/www/mephisto-blog rob@85.10.241.146:/var/www/blog.tupleshop.com

My outbound dsl speed is sloow. This takes a while. While I wait, I'll set up MySQL:

1
2
rob@unicron:~$ sudo su -    
unicron:~# mysql

More MySQL:

1
2
3
4
mysql> create database mephisto_prod;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on mephisto_prod.* to UUSSEERR@'localhost' identified by 'PPAASSWWOORRDD';
Query OK, 0 rows affected (0.00 sec)

Hmm, still waiting on the 'scp' command. Sending files is sloooow. But, after all, this is why I joined the group to get on the beefy remote server with unlimited bandwidth.

Well, the good news is that the DNS (blog.tupleshop.com) has propagated. :)

Okay, dump and move over my Mephisto database:

1
2
root@teak:~# mysqldump mephisto_prod > mephisto_prod_3-12-2007
root@teak:~# scp mephisto_prod_3-12-2007 rob@85.10.241.146:~

Add some MySQL default login info (into .my.cnf) and load up the data:

1
2
rob@unicron:~$ vi .my.cnf  
rob@unicron:~$ mysql < mephisto_prod_3-12-2007

Let's see how Apache is doing (I don't find 'lsof' so I install it.):

1
2
3
4
5
6
7
8
9
unicron:/etc/apache2/sites-enabled# aptitude install lsof
unicron:/etc/apache2/sites-enabled# lsof -i -P | grep 8080
apache2   5753        root    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5754    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5755    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5756    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5757    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5758    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)
apache2   5759    www-data    5u  IPv4  23876       TCP 85-10-241-146.clients.your-server.de:8080 (LISTEN)

Cool, so Apache is listening as expected. Let's get the Mongrel cluster started:

1
2
rob@unicron:/var/www$ sudo chown -R www-data:staff blog.tupleshop.com/
rob@unicron:/var/www$ sudo chmod -R 775 blog.tupleshop.com/

Set up the mongrel_cluster config file:

1
2
3
4
5
6
7
8
9
rob@unicron:/var/www/blog.tupleshop.com$ cat config/mongrel_cluster.yml 
user: www-data
cwd: /var/www/blog.tupleshop.com
port: "4000"
environment: production
group: www-data
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 2

Finially, start the mongrels:

1
2
rob@unicron:/var/www/blog.tupleshop.com$ sudo mongrel_rails cluster::start
Starting 2 Mongrel servers...

Verify it's they are really running:

1
2
3
rob@unicron:/var/www/blog.tupleshop.com$ sudo lsof -i -P | grep mongrel
mongrel_r 6003    www-data    3u  IPv4  28127       TCP localhost:4000 (LISTEN)
mongrel_r 6006    www-data    3u  IPv4  28133       TCP localhost:4001 (LISTEN)

Good. Now check http://blog.tupleshop.com:8080/ in a browser...

It's looks good... except for that lame port. Let's fix that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unicron:/etc/apache2# cat sites-available/tupleshop.com 
<Proxy balancer://prncluster>
   # cluster members
   BalancerMember http://127.0.0.1:4000
   BalancerMember http://127.0.0.1:4001
</Proxy>

ProxyRequests Off
<Proxy *>
   Order deny,allow
   Allow from all
</Proxy>

<VirtualHost 85.10.241.146:*>
   ServerName   blog.tupleshop.com
   ServerAdmin  webmaster@tupleshop.com
   ProxyPass / balancer://prncluster/
   ProxyPassReverse / balancer://prncluster/
</VirtualHost>

and restart Apache:


rob@unicron:~$ sudo apache2ctl restart

Let me just make sure that I'm really getting all the way to Germany:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ traceroute blog.tupleshop.com 
traceroute to blog.tupleshop.com (85.10.241.146), 64 hops max, 40 byte packets
 1  192.168.0.1 (192.168.0.1)  1.475 ms  0.738 ms  0.684 ms
 2  69-12-146-1.dsl.static.sonic.net (69.12.146.1)  10.795 ms  10.305 ms  9.253 ms
 3  105.at-2-2-0.gw4.200p-sf.sonic.net (69.12.242.29)  14.572 ms  10.127 ms  11.029 ms
 4  0.as0.gw3.200p-sf.sonic.net (64.142.0.225)  9.857 ms  9.760 ms  14.225 ms
 5  200.ge-1-2-0.gw2.equinix-sj.sonic.net (64.142.0.210)  12.632 ms  11.456 ms  11.177 ms
 6  gigabitethernet1-0.gw1.sjc7.alter.net (157.130.214.177)  11.811 ms  11.448 ms  11.932 ms
 7  pos1-0.xr2.sjc7.alter.net (152.63.53.194)  11.469 ms  12.052 ms  11.416 ms
 8  0.so-7-0-0.xl2.scl2.alter.net (152.63.48.1)  13.729 ms  13.832 ms  13.154 ms
 9  0.so-7-0-0.br1.scl2.alter.net (152.63.57.101)  12.232 ms  14.482 ms  16.716 ms
10  sl-bb20-sj-6-1.sprintlink.net (144.232.9.1)  16.736 ms  13.101 ms  14.062 ms
11  sl-bb23-sj-12-0.sprintlink.net (144.232.3.194)  18.569 ms  17.817 ms  14.657 ms
12  sl-bb25-rly-0-0.sprintlink.net (144.232.20.10)  90.650 ms  90.360 ms  90.277 ms
13  sl-bb24-rly-12-0.sprintlink.net (144.232.14.149)  122.399 ms  100.446 ms  267.436 ms
14  sl-st22-ash-6-0.sprintlink.net (144.232.20.189)  91.498 ms  88.574 ms  91.257 ms
15  sl-tisca1-3-0.sprintlink.net (144.223.246.30)  90.395 ms  87.782 ms  87.099 ms
16  so-4-0-0.fra10.ip.tiscali.net (213.200.82.5)  174.162 ms  174.821 ms  178.150 ms
17  hetzner-gw.ip.tiscali.net (213.200.86.90)  183.653 ms  188.186 ms  190.110 ms
18  hos-bb2.juniper2.rz6.hetzner.de (213.239.240.141)  184.168 ms  182.178 ms  181.215 ms
19  et.2.16.rs3k27.rz6.hetzner.de (213.239.242.136)  183.679 ms  182.039 ms  182.089 ms
20  85-10-241-146.clients.your-server.de (85.10.241.146)  182.651 ms  182.802 ms  182.692 ms

Yup, and hitting it in browser shows everything is running find.

So, that's it. I'm done. Obviously, there's much more I can and will do. I can get svn working and set up capistrano, but for now, I've got to hit the sack (11:30pm). Looks like I missed my 1 hour goal, but I got side tracked a couple of times. That's okay. :)

Opps! Spoke too soon. In trying to log into the admin area of Mephisto and I realize that I was just getting static, cached pages. I check the logs (the Rails logs) and see that there is a MySQL problem:

1
2
No such file or directory - /tmp/mysql.sock
/var/www/blog.tupleshop.com/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:107:in `initialize'

Hmm, I forgot to install the mysql gem. I'll do that now:

1
2
3
4
rob@unicron:~$ sudo aptitude install libmysql-ruby1.8
rob@unicron:~$ irb
irb(main):001:0> require 'mysql'
=> true

Okay, *now* everything is running. Time: 11:42pm. (Time for bed.)

Hope this helps you.


Comments

Leave a response

  1. Damien MerenneMarch 13, 2007 @ 06:11 AM
    Just to say that you can use ssh-copy-id which takes care of creating .ssh, setting permissions, copy keys, etc.
  2. Rob OrsiniMarch 14, 2007 @ 12:55 AM
    @Damien: Hey, cool tool (ssh-copy-id). Thanks for the tip.
  3. noodlMarch 14, 2007 @ 09:11 AM
    More ssh goodies: You can background running ssh processes with ~ ctrl-z (hit tilde then ctrl-z). 'fg' to foreground as usual. Even funkier, ssh connections can be multiplexed. Add this to your .ssh/config (on the local machine): Host * ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p Then, anytime you create a connection to a server it'll become the master. That way your subsequent scp commands and ssh connections don't need to renegotiate the connection (as long as the initial one is still running). So it's um, quicker.
  4. DMMarch 15, 2007 @ 05:50 AM
    >You can background... there is a nice tool called "screen" - terminal multiplexor. With such thing there is no need to use ctrl+z/fg more ;) And one more useful thing about screen: if you are ssh-ed to some host and are working in screen there, and if network fails - screen session still works. After network is up again, you could ssh to host and restore your session - just on the poit where you was interrupted (very useful for long-time-taking-things, like kernel compilation).