apache2.2.6 + mongrel_cluster1.0.5负载均衡





=========================================

HTTPS方式的访问时浏览器和服务器间要建立安全连接,服务器端要配置证书之类的。具体参考文档或者GOOGLE吧。
=========================================


(1)apache + 单进程mongrel
mongrel (1.1.5)
gem install mongrel


cd ${your_rails_app_root}
mongrel_rails start -e development -p 8080 -r public -l log/m.log -P tmp/pids/dispatch.0.pid -d
mongrel_rails start -h

/usr/local/apache2/bin/httpd -version

vi /etc/httpd/conf/httpd.conf
文件最后加入:

<VirtualHost *:80>
   ServerName www.abc.com
   ErrorLog logs/space.mo.com-error_log
   CustomLog logs/space.mo.com-access_log common
 
   ProxyPass / http://127.0.0.1:8080/
   ProxyPassReverse / http://127.0.0.1:8080/
   ProxyPreserveHost on
</VirtualHost>


注意:
1)上面对于apache得配置很粗糙,把所有的请求到推倒了mongrel实例,产品环境中显然是不行的,apache作为反向代理,最好是指把动态请求推给mongrel实例。
2)  仅有单个mongrel实例使得请求变成了单进程,并发性能不太好
对于小流量的网站无所谓,一旦压力增大,恐怕就的考虑Apache+Mongrel_cluster



(2)apache + mongrel_cluster
mongrel_cluster (1.0.5)
sudo gem install mongrel_cluster

You need to run (mongrel_rails cluster::configure)
from within the root directory of your rails project.

cd #{your_rails_app_root}
mongrel_rails cluster::configure -e development -p 4000 -N 4 -c #{your_rails_app_root} -a 127.0.0.1
 
上面命令在#{your_rails_app_root}/config产生如下配置文件mongrel_cluster.yml


address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
environment: development
port: "4000"
log_file: log/mongrel.log
servers: 4
cwd: /home/pingan/iche2/trunk/iche


上面已经安装和配置好mongrel_cluster

cd #{your_rails_app_root}
mongrel_rails cluster::start

安装apache2.2.6
cd /usr/local
 
wget http://apache.mirror.phpchina.com/httpd/httpd-2.2.6.tar.gz
 
tar xvzf httpd-2.2.6.tar.gz
 
cd httpd-2.2.6
 
./configure --prefix=/usr/local/apache2.2.22 --enable-so --enable-mods-shared=all --enable-proxy --enable-proxy_http --enable-proxy-balancer --enable-rewrite --enable-cache
 
./configure --prefix=/usr/local/apachel --enable-so --enable-mods-shared=all --enable-rewrite --enable-cache
 
 
 
make && make install
 
由于apache2.2.6的配置文件中已经引入了,所以你无需在配置文件加入这些
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
 

但你必须加上如下部分
 
<Proxy balancer://spacecluster>
    # cluster members
    BalancerMember http://127.0.0.1:4000
    BalancerMember http://127.0.0.1:4001
    BalancerMember http://127.0.0.1:4002
    BalancerMember http://127.0.0.1:4003
  
    #BalancerMember http://192.168.100.234:4000
   
</Proxy>

ExtendedStatus On
<Location /server-status>
    SetHandler server-status
</Location>

<Location /balancer-manager>
    SetHandler balancer-manager
</Location>

<VirtualHost *:80>
    ServerName www.abc.com

    ProxyRequests Off

    ProxyPass /balancer-manager !
    ProxyPass /server-status !
    ProxyPass / balancer://spacecluster/
    ProxyPassReverse / balancer://spacecluster/
</VirtualHost>
 
到此你的 apache + mongrel cluster就安装配置好了,你可以用浏览器访问apache看看是否生效了


==================================
一,查看有没有安装过mod_proxy之类的东西

[zhangy@BlackGhost ~]$ /usr/local/apache2/bin/httpd -l

如果没有发现mod_proxy,我们就到apache安装目录下的modules里面看看有没有mod_proxy.so文件,如果都没有,则说明没有加载负载均衡的模块

二,安装mod_proxy,proxy_balancer_module等

进入apache的解压目录,就是你从网上下载下来的压缩文件,然后解压产生的目录。

cd   apache的解压目录/modules/proxy

[root@BlackGhost proxy]# /usr/local/apache2/bin/apxs -c -i mod_proxy.c proxy_util.c

注意:上面如果不加proxy_util.c的话,LoadModule proxy_module modules/mod_proxy.so会报错的,提示你找不到mod_proxy.so文件

[root@BlackGhost proxy]# /usr/local/apache2/bin/apxs -c -i mod_proxy_balancer.c

[root@BlackGhost proxy]# /usr/local/apache2/bin/apxs -c -i mod_proxy_http.c

出现下面的东西说明装好了。

Libraries have been installed in:
/usr/local/apache2/modules

#要安装的模块装好了
[zhangy@BlackGhost apache2]$ ls ./modules/
httpd.exp     mod_fastcgi.so    mod_proxy.so           mod_rewrite.so
libphp5.so    mod_fcgid.so      mod_proxy_balancer.so
mod_cache.so  mod_mem_cache.so  mod_proxy_http.so

三,配置httpd.conf,测试负载均衡


====================================
注意httpd各个版本之间的差异

httpd2.0.64 vs httpd2.2.22:

httpd2.2.22 is a major release of the 2.2 stable branch. New features include Smart Filtering, Improved Caching, AJP Proxy, Proxy Load Balancing, Graceful Shutdown support, Large File Support, the Event MPM, and refactored Authentication/Authorization.

httpd2.2.22 源码modules/proxy/中mod很丰富,像mod_proxy_balancer.c和mod_proxy_http.c都是新增的


===========================================

启动和停止apache
启动:sudo /usr/local/apache2/bin/httpd -k start

启动时提示:

  httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName.
解决办法是在http.conf中加一行:
  ServerName 127.0.0.1:80

停止:sudo /usr/local/apache2/bin/httpd -k stop


让Ubuntu开机自动启动apache.

1). 复制 /usr/local/apache2/bin/apachectl到/etc/init.d
2). 加载为服务
     sudo update-rc.d apachectl defaults

开机重启访问http://localhost/如果显示apache的网页,就说明自动启动成功了。



reload Apache:

sudo /etc/init.d/apache2.2 -k restart|stop






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值