Ruby on rails
Apache22 ruby on rails and mongrel
Süsteem toimib nii, et Apache suunab vhostide info mongrel serverile, mis siis railsi skripte esile manab.
Installime vajalikud päkitsad
cd /usr/ports/apache22 make install with_proxy_modules=yes
cd /usr/ports/lang/ruby18 make install && make clean
cd /usr/ports/devel/ruby-gems make install && make clean
gem install mongrel gem install rails gem install mongrel-cluster
Loome vajalikud skriptid
pane rcrails /etc/init.d vms kausta ja start_mongrel iga railsi script kausta. start_mongreli sees määra USER ja GROUP, kellena see server jooksma peaks.
Meil on kaks eraldi railsis loodud programmi, mis asuvad
/home/rails/progeadmin/ /home/rails/veebiadmin/
/usr/local/etc/rails.conf või muusse faili (muuda vastavalt rcrails skripti) kirjuta näiteks:
RAILS_SERVERS=" /home/rails/progeadmin/ /home/rails/veebiadmin/
Mongrel Cluster Setup
With mongrel working and our webapp directory prepared we can proceed with the mongrel_cluster configuration step:
$ sudo mongrel_rails cluster::configure -e production \ -p 8000 -N 3 -c /var/www/apps/testapp -a 127.0.0.1 \ --user mongrel --group mongrel
This will write a configuration file in config/mongrel_cluster.yml. We have setup to run our cluster in production mode as the user mongrel and will start 3 mongrel servers listening on ports 8000, 8001, and 8002. Now, lets do a quick test of what we have setup so far:
$ sudo mongrel_rails cluster::start
Checking our host on ports 8000, 8001, and 8002 we should now be able to see our test application. We can stop all of those mongrels with sudo mongrel_rails cluster::stop.
cat home/progeadmin/rails/config/mongrel_cluster.yml
---
user: programm
cwd: /home/progeadmin/rails/
port: "8000"
environment: production
group: konkurss
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3
httpd.conf
Kontrollime, et read oleksid
LoadModule proxy_module libexec/apache22/mod_proxy.so LoadModule proxy_connect_module libexec/apache22/mod_proxy_connect.so LoadModule proxy_ftp_module libexec/apache22/mod_proxy_ftp.so LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so LoadModule proxy_ajp_module libexec/apache22/mod_proxy_ajp.so LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so
Nüüd loome mõlemale progele nende vhostid
<VirtualHost 193.40.0.10:80> ServerName progeadmin.katse.ee DocumentRoot /home/rails/progeadmin/ <Directory "/home/rails/progeadmin/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Redirect all non-static requests to cluster #RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] </VirtualHost>
<VirtualHost 193.40.0.10:80> ServerName veebiadmin DocumentRoot /home/rails/veebiadmin/ <Directory "/home/rails/veebiadmin/"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On # Rewrite to trailing slash RewriteRule ^/admin$ /admin/ [R,L] # test if this is /admin request RewriteCond %{REQUEST_URI} ^/admin(/.*) # strip off /admin and put result in ENV RewriteRule ^/admin(.*) /admin$1 [E=AdminReq:$1] RewriteCond /home/rails/admin/public/%{ENV:AdminReq} -f # serve static files RewriteRule ^/admin/(.*) /home/rails/admin/public/$1 [L] # If request is not static, proxy to rails RewriteRule ^/(admin/.*)$ balancer://mongrel_cluster2/$1 [P,QSA,L] </VirtualHost>
Ehitame proxyd
<Proxy balancer://mongrel_cluster2> BalancerMember http://127.0.0.1:8001 BalancerMember http://127.0.0.1:8002 BalancerMember http://127.0.0.1:8003 </Proxy>
<Proxy balancer://mongrel_cluster> BalancerMember http://127.0.0.1:8101 BalancerMember http://127.0.0.1:8102 BalancerMember http://127.0.0.1:8103 </Proxy>
ja balaceri
Listen 8000 <VirtualHost 193.40.0.10:8000> <Location /> SetHandler balancer-manager Deny from all Allow from localhost </Location> </VirtualHost>
Lingid