Erinevus lehekülje "Ruby on rails" redaktsioonide vahel
| 24. rida: | 24. rida: | ||
kausta. start_mongreli sees määra USER ja GROUP, kellena see server | kausta. start_mongreli sees määra USER ja GROUP, kellena see server | ||
jooksma peaks. | jooksma peaks. | ||
| + | |||
| + | Meil on kaks eraldi railsis loodud programmi | ||
| + | |||
| + | asuvad nad | ||
| + | |||
| + | /home/rails/progeadmin/ | ||
| + | /home/rails/veebiadmin/ | ||
/usr/local/etc/rails.conf või muusse faili (muuda vastavalt rcrails skripti) | /usr/local/etc/rails.conf või muusse faili (muuda vastavalt rcrails skripti) | ||
| 33. rida: | 40. rida: | ||
" | " | ||
| − | start_mongrel | + | ehitame näiteks ruudu alla skripti mis stardib mongreleid nimega |
| + | rcrails | ||
| + | |||
| + | #!/usr/local/bin/bash | ||
| + | # | ||
| + | # This is proxy skript to start-stop mongrel_rails servers | ||
| + | # This script can be placed in /etc/init.d or other rc startup directory | ||
| + | # and it will pass its first argument to each rails start script. | ||
| + | |||
| + | conf="/usr/local/etc/mongrel.conf" | ||
| + | |||
| + | if [ -f $conf ] | ||
| + | then | ||
| + | source $conf | ||
| + | fi | ||
| + | |||
| + | # function to do actual calling | ||
| + | start_stop_rails(){ | ||
| + | echo "" | ||
| + | echo "Rails directory: $1" | ||
| + | cd $1 | ||
| + | ./script/start_mongrel $2 | ||
| + | } | ||
| + | |||
| + | # set CMD to first argument | ||
| + | CMD=$1 | ||
| + | |||
| + | for i in $RAILS_SERVERS | ||
| + | do | ||
| + | start_stop_rails $i $CMD | ||
| + | done | ||
| + | |||
| + | |||
| + | |||
| + | loome skripti | ||
| + | start_mongrel ja kopeeirme kausta /home/rails/progeadmin/ | ||
| + | |||
#!/usr/local/bin/bash | #!/usr/local/bin/bash | ||
| 67. rida: | 110. rida: | ||
esac | esac | ||
| − | + | teeme teise skripti | |
| − | + | start_mongrel ning kopeerime /home/rails/veebiadmin/ | |
#!/usr/local/bin/bash | #!/usr/local/bin/bash | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | USER="root" | |
| + | GROUP="wheel" | ||
| + | |||
| − | + | case $1 in | |
| − | + | start) | |
| − | + | /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8101 -a 127.0.0.1 -P rails-8101.pid | |
| − | + | /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8102 -a 127.0.0.1 -P rails-8102.pid | |
| + | /usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8103 -a 127.0.0.1 -P rails-8103.pid | ||
| + | ;; | ||
| + | restart) | ||
| + | /usr/local/bin/mongrel_rails restart -P rails-8101.pid | ||
| + | /usr/local/bin/mongrel_rails restart -P rails-8102.pid | ||
| + | /usr/local/bin/mongrel_rails restart -P rails-8103.pid | ||
| + | ;; | ||
| + | stop) | ||
| + | /usr/local/bin/mongrel_rails stop -P rails-8101.pid | ||
| + | /usr/local/bin/mongrel_rails stop -P rails-8102.pid | ||
| + | /usr/local/bin/mongrel_rails stop -P rails-8103.pid | ||
| + | ;; | ||
| + | *) | ||
| + | cat <<EOF | ||
| − | + | USAGE: $0 <start|stop|restart> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Mongrel places it's pid files in the RAILS_ROOT directory, which must be | |
| − | + | writable by the calling user. | |
| − | + | EOF | |
| − | + | esac | |
| − | |||
| − | |||
httpd.conf | httpd.conf | ||
| 110. rida: | 157. rida: | ||
LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so | LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so | ||
| + | nüüd loome kummagile progele nende vhostid | ||
<VirtualHost 193.40.0.10:80> | <VirtualHost 193.40.0.10:80> | ||
| − | ServerName | + | ServerName progeadmin.katse.ee |
| − | DocumentRoot /home/rails/ | + | DocumentRoot /home/rails/progeadmin/ |
| − | <Directory "/home/rails/ | + | <Directory "/home/rails/progeadmin/"> |
Options FollowSymLinks | Options FollowSymLinks | ||
AllowOverride None | AllowOverride None | ||
| 130. rida: | 178. rida: | ||
</VirtualHost> | </VirtualHost> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<VirtualHost 193.40.0.10:80> | <VirtualHost 193.40.0.10:80> | ||
| − | ServerName | + | ServerName veebiadmin |
| − | DocumentRoot /home/ | + | DocumentRoot /home/rails/veebiadmin/ |
| − | <Directory "/home/ | + | <Directory "/home/rails/veebiadmin/"> |
Options FollowSymLinks | Options FollowSymLinks | ||
AllowOverride None | AllowOverride None | ||
| 147. rida: | 189. rida: | ||
Allow from all | Allow from all | ||
</Directory> | </Directory> | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
RewriteEngine On | RewriteEngine On | ||
| 179. rida: | 215. rida: | ||
BalancerMember http://127.0.0.1:8003 | BalancerMember http://127.0.0.1:8003 | ||
</Proxy> | </Proxy> | ||
| + | |||
| + | ehitame balanceri | ||
| + | |||
| + | <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 proxy neile | ||
Listen 8000 | Listen 8000 | ||
Redaktsioon: 23. jaanuar 2007, kell 22:53
Apache22 ruby on rails and mongrel
Süsteem toimib nii ,et apache suunab vhostide info mongrel serverile mis siis railsi skripte esilemanab
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
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
asuvad nad
/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/ "
ehitame näiteks ruudu alla skripti mis stardib mongreleid nimega rcrails
#!/usr/local/bin/bash
#
# This is proxy skript to start-stop mongrel_rails servers
# This script can be placed in /etc/init.d or other rc startup directory
# and it will pass its first argument to each rails start script.
conf="/usr/local/etc/mongrel.conf"
if [ -f $conf ]
then
source $conf
fi
# function to do actual calling
start_stop_rails(){
echo ""
echo "Rails directory: $1"
cd $1
./script/start_mongrel $2
}
# set CMD to first argument
CMD=$1
for i in $RAILS_SERVERS
do
start_stop_rails $i $CMD
done
loome skripti start_mongrel ja kopeeirme kausta /home/rails/progeadmin/
#!/usr/local/bin/bash
USER="root"
GROUP="wheel"
case $1 in
start)
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8001 -a 127.0.0.1 -P rails-8001.pid
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8002 -a 127.0.0.1 -P rails-8002.pid
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8003 -a 127.0.0.1 -P rails-8003.pid
;;
restart)
/usr/local/bin/mongrel_rails restart -P rails-8001.pid
/usr/local/bin/mongrel_rails restart -P rails-8002.pid
/usr/local/bin/mongrel_rails restart -P rails-8003.pid
;;
stop)
/usr/local/bin/mongrel_rails stop -P rails-8001.pid
/usr/local/bin/mongrel_rails stop -P rails-8002.pid
/usr/local/bin/mongrel_rails stop -P rails-8003.pid
;;
*)
cat <<EOF
USAGE: $0 <start|stop|restart>
Mongrel places it's pid files in the RAILS_ROOT directory, which must be
writable by the calling user.
EOF
esac
teeme teise skripti start_mongrel ning kopeerime /home/rails/veebiadmin/
#!/usr/local/bin/bash
USER="root"
GROUP="wheel"
case $1 in
start)
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8101 -a 127.0.0.1 -P rails-8101.pid
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8102 -a 127.0.0.1 -P rails-8102.pid
/usr/local/bin/mongrel_rails start -d --user $USER --group $GROUP -p 8103 -a 127.0.0.1 -P rails-8103.pid
;;
restart)
/usr/local/bin/mongrel_rails restart -P rails-8101.pid
/usr/local/bin/mongrel_rails restart -P rails-8102.pid
/usr/local/bin/mongrel_rails restart -P rails-8103.pid
;;
stop)
/usr/local/bin/mongrel_rails stop -P rails-8101.pid
/usr/local/bin/mongrel_rails stop -P rails-8102.pid
/usr/local/bin/mongrel_rails stop -P rails-8103.pid
;;
*)
cat <<EOF
USAGE: $0 <start|stop|restart>
Mongrel places it's pid files in the RAILS_ROOT directory, which must be
writable by the calling user.
EOF
esac
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 kummagile 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>
<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>
ehitame balanceri
<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 proxy neile
Listen 8000 <VirtualHost 193.40.0.10:8000> <Location /> SetHandler balancer-manager Deny from all Allow from localhost </Location> </VirtualHost>