先确保安装mongrel and mongrel_cluster,用gem装。
然后生成一个配置文件,使用mongrel_rails :
mongrel_rails cluster::configure -p 8000 -N 3 -c /project/dir/ -a 127.0.0.1
-a 是服务器监听地址
-p 是起始端口号
-N 是进程数
-c 是rails项目目录
将会在config下生成一个mongrel_cluster.yml
自己编辑也可以。
然后在项目目录下启动:
mongrel_rails cluster::start
顺利启动三个服务进程就成功了,监听端口分别是8000, 8001, 8002。
然后再配置apache,弄个proxy和虚拟机就行了:
在httpd.conf里配置,如果是用xampp,则可以extra目录下的httpd-vhosts.conf里配置,当然要把httpd.conf里打开这个文件的引用。
这个配置就是指示集群的三个服务器地址和端口,如果是多机集群,那么只需要改变ip地址就行了,也不复杂。
实际上单机集群就是起多个服务进程而已,可以充分利用服务器资源,是伪集群,只是配置方法一样。
关于session复制的问题,请放在数据库里比较好一点。
mongrel官网上有介绍:
mongrel.rubyforge.org/docs/apache.html
然后生成一个配置文件,使用mongrel_rails :
mongrel_rails cluster::configure -p 8000 -N 3 -c /project/dir/ -a 127.0.0.1
-a 是服务器监听地址
-p 是起始端口号
-N 是进程数
-c 是rails项目目录
将会在config下生成一个mongrel_cluster.yml
ruby 代码
- ---
- cwd: /project/dir/
- log_file: log/mongrel.log
- port: "8000"
- address: 127.0.0.1
- pid_file: tmp/pids/mongrel.pid
- servers: 3
自己编辑也可以。
然后在项目目录下启动:
mongrel_rails cluster::start
顺利启动三个服务进程就成功了,监听端口分别是8000, 8001, 8002。
然后再配置apache,弄个proxy和虚拟机就行了:
xml 代码
- ProxyRequests Off
- <Proxy balancer://mongrel_cluster>
- BalancerMember http://127.0.0.1:8000
- BalancerMember http://127.0.0.1:8001
- BalancerMember http://127.0.0.1:8002
- </Proxy>
- <VirtualHost *:80>
- ServerName webcs
- ProxyPass /images !
- ProxyPass /stylesheets !
- ProxyPass /javascripts !
- ProxyPass /stylesheets !
- ProxyPass /yui !
- ProxyPass /enter_chat.html !
- ProxyPass /license.html !
- ProxyPass /favicon.ico !
- Alias /images /home/magicgod/workspace/webcs/public/images
- Alias /stylesheets /home/magicgod/workspace/webcs/public/stylesheets
- Alias /javascripts /home/magicgod/workspace/webcs/public/javascripts
- Alias /yui /home/magicgod/workspace/webcs/public/yui
- Alias /enter_chat.html /home/magicgod/workspace/webcs/public/enter_chat.html
- Alias /license.html /home/magicgod/workspace/webcs/public/license.html
- Alias /favicon.ico /home/magicgod/workspace/webcs/public/favicon.ico
- ProxyPass / balancer://mongrel_cluster
- ProxyPassReverse / balancer://mongrel_cluster
- ProxyPreserveHost on
- ErrorLog /var/log/apache2/webcs-error_log
- CustomLog /var/log/apache2/webcs-access_log common
- </VirtualHost>
在httpd.conf里配置,如果是用xampp,则可以extra目录下的httpd-vhosts.conf里配置,当然要把httpd.conf里打开这个文件的引用。
这个配置就是指示集群的三个服务器地址和端口,如果是多机集群,那么只需要改变ip地址就行了,也不复杂。
实际上单机集群就是起多个服务进程而已,可以充分利用服务器资源,是伪集群,只是配置方法一样。
关于session复制的问题,请放在数据库里比较好一点。
mongrel官网上有介绍:
mongrel.rubyforge.org/docs/apache.html