Joyent

Translations of this page:

Konfiguration einer Rails Applikation mit Mongrel und Apache

Diese Anleitung geht davon aus, dass Ihnen der Rest des Rails Applikationskrams bekannt ist: Die Dateien irgendwohin packen, die database.yml konfigurieren (und natürlich MySQL und MySQL User zu konfigurieren).

1) Fügen Sie Ihrer Applikation eine mongrel_cluster.yml Datei hinzu die ihre private IP automatisch ermittelt und Hostname-spezifische PIDs erstellt.

# cd /home/PFAD/ZU/IHRER/RAILS/APP
# svn export http://svn.joyent.com/public/accelerators/configs/mongrel/mongrel_cluster.yml config/mongrel_cluster.yml

2) Starten Sie die Applikation.

# cd /home/PFAD/ZU/IHRER/RAILS/APP
# mongrel_rails cluster::start

3) Überprüfen Sie, ob Sie eine Ausgabe zurückbekommen.

# curl `myprivateip`:8000
# curl -I `myprivateip`:8000

Der zweite Befehl sollte “200” zurückgeben, ungefähr so:

HTTP/1.1 200 OK
Connection: close
Date: Tue, 06 Mar 2007 07:09:13 GMT
Status: 200 OK
Server: Mongrel 1.0.1
Content-Type: text/html
Content-Length: 0

Wenn nichts passiert, überprüfen Sie die Einträge im production.log

4) Konfigurieren Sie einen virtuellen Apache Host um Proxy Balancing für diese Mongrels zu ermöglichen.

# cd /opt/csw/apache2/etc/virtualhost
# nano myrailsapp-domain.conf

Der Inhalte sollte so aussehen:

<VirtualHost IHRE-PUBLIC-IP:80>
ServerName IHREDOMAIN.de                                                                                                                                                                       ServerAlias *.IHREDOMAIN.de 
DocumentRoot /home/PFAD/ZU/IHRER/RAILS/APP                                                                                                                                                                            
<Directory "/home/PFAD/ZU/IHRER/RAILS/APP/public/">                                                                                                                                                                               
Options FollowSymLinks                                                                                                                                                                                                  
AllowOverride None                                                                                                                                                                                                      
Order allow,deny                                                                                                                                                                                                        
Allow from all                                                                                                                                                                                                        
</Directory>           
<Proxy balancer://app1-mongrels>                                                                                                                                                                                   
BalancerMember http://IHRE-PRIVATE-IP:8000                                                                                                                                                                                    
BalancerMember http://IHRE-PRIVATE-IP:8001                                                                                                                                                                                    
BalancerMember http://IHRE-PRIVATE-IP:8002                                                                                                                                                                                    
BalancerMember http://IHRE-PRIVATE-IP:8003                                                                                                                                                                                    
</Proxy>                                                                        
ProxyPass /images !                                                                                                                                                                                                     
ProxyPass /stylesheets !                                                                                                                                                                                                
ProxyPass / balancer://app1-mongrels/                                                                                                                                                                              
ProxyPassReverse / balancer://app1-mongrels/                                                                                                                                                                       
ProxyPreserveHost On  
</VirtualHost>
# apachectl restart

Sie benötigen einen einzigartigen Namen für “balancer://app1-mongrels”. Die Ports die Sie nutzen sind die gleichen, die Sie in Ihrer mongrel_cluster.yml angegeben haben.

5) Stellen Sie nun sicher, dass Ihre Applikation via SMF bei einem Neustart wieder gestartet wird.

Ersetzen Sie dazu IHREAPP, den Pfad /HOME/PFAD/ZU/IHRER/RAILS/APP, und den USER und die GROUP

<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='mongrel/YOURAPP-production'>
  <service name='network/mongrel/IHREAPP-production' type='service' version='0'>
    <create_default_instance enabled='true'/>
    <single_instance/>    
    <dependency name='fs' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/system/filesystem/local'/>
    </dependency>
    <dependency name='net' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/network/loopback'/>
      <!-- need nfs/client because the mongrel stuff is on /home which is nfs mounted -->
      <service_fmri value='svc:/network/nfs/client'/>
    </dependency>
    <dependent name='mongrel_multi-user' restart_on='none' grouping='optional_all'>
      <service_fmri value='svc:/milestone/multi-user'/>
    </dependent>    
    <exec_method name='start' type='method' exec='/opt/csw/bin/mongrel_rails cluster::start' timeout_seconds='60'>
      <method_context working_directory='/HOME/PFAD/ZU/IHRER/RAILS/APP'>
        <method_credential user='USER' group='GROUP' />
        <method_environment>
          <envvar name="PATH" value="/usr/bin:/bin:/opt/csw/bin" />
        </method_environment>
      </method_context>
    </exec_method>
    <exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'>
      <method_context/>
    </exec_method>
  </service>
</service_bundle>

Speichern Sie diese XML Datei unter:

# nano /HOME/PFAD/ZU/IHRER/RAILS/APP/mongrel-app-smf.xml
# cd /HOME/PFAD/ZU/IHRER/RAILS/APP
# mongrel_rails cluster::stop
# rm log/*.pid
# svccfg import /HOME/PFAD/ZU/IHRER/RAILS/APP/mongrel-app-smf.xml
# svcadm enable mongrel/IHREAPP-production
# svcs -v | grep mongrel
 
de/accelerators/apache_rails_mongrel.txt · Last modified: 2007/06/02 20:11 by sebastiann
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki