日期:2014-05-17  浏览次数:21024 次

ubuntu下安装配置mongrel和apache2
ubuntu下安装配置mongrel和apache2

1、安装mongrel
gem install mongrel
gem install mongrel_cluster

出错:
root@kiko:~# gem install mongrel
Building native extensions. This could take a while...
ERROR: Error installing mongrel:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install mongrel
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:1


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.1/ext/fastthread/gem_make.out

在线升级系统
apt-get update
apt-get dist-upgrade

对升级系统进行确认
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get -f install
sudo dpkg --configure -a

安装ruby on rails
apt-get install ruby
apt-get install rubygems
gem update --system (先更新gem再装rails否则出错)

升级后命令变成了gem1.8了,使用起来不习惯,所以加个软链接

ln -s /usr/bin/gem1.8 /usr/bin/gem

或者直接使用

gem1.8 install rails --include-dependencies


gem install rails --include-dependencies
apt-get install imagemagick
apt-get install libmagick9-dev ruby1.8-dev
gem install rmagick

安装mongrel服务报错如下:

make
cc -I. -I/usr/lib/ruby/1.8/i486-linux -I/usr/lib/ruby/1.8/i486-linux -I. -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -c fastthread.c
make: cc: Command not found
make: *** [fastthread.o] Error 127

原来是少安装了gcc和make


apt-get install gcc

apt-get install make

再次安装application服务器

gem install mongrel
gem install mongrel_cluster

运行服务器
mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 2 -c /usr/local/redmine-0.7.3

-e 指定运行环境,有production(生产)、development(开发)、test(测试)三个选项。
-p 指定监听端口
-a 0.0.0.0 指定Mongrel在localhost下监听
-N 2 启动两个Mongrel进程,端口从8000~8001

运行后,会在应用程序目录 config/mongrel_cluster.yml, 以后有什么变化,直接修改这个文件就可以了。

报错如下:
!!! Path to config file not valid: config/mongrel_cluster.yml
cluster::configure reported an error. Use mongrel_rails cluster::configure -h to get help.

mv redmine-0.7.3 redmine
把名字改掉后再运行

mongrel_rails cluster::configure -e production -p 8000 -a 0.0.0.0 -N 2 -c /usr/local/redmine/

在终端下输入以下命令启动Mongrel:
代码:
/usr/local/redmine/mongrel_rails cluster::start

要停止则输入:
代码:
/usr/local/redmine/mongrel_rails cluster::stop

2、配置apache转发
启动mod_proxy模块.
cd /etc/apache2/mods-enabled/
sudo ln -s ../mods-available/proxy_balancer.load proxy_balancer.load
sudo ln -s ../mods-available/proxy_http.load proxy_http.load (配置转发JBOSS已加)
sudo ln -s ../mods-available/proxy.load proxy.load (配置转发JBOSS已加)
sudo ln -s ../mods-available/proxy.conf proxy.conf (配置转发JBOSS已加)

修改proxy.conf文件
vi /etc/apache2/mods-available/proxy.conf
#Allow from .example.com
改为
Allow from all

修改 /etc/apache2/apache2.conf 文件(默认是在最后一行):
Include /etc/apache2/sites-enabled/
改为:
#Include /etc/apache2/sites-enabled/

然后在/etc/apache2/httpd.conf里添加以下部分:
代码:
<Proxy balancer://mongrel>
BalancerMember http://192.168.50.90:8000
BalancerMember http://192.168.50.90:8001
</Proxy>

<VirtualHost *:80>
ProxyPass / balancer://mongrel/
ProxyPassReverse / balancer://mongrel/
</VirtualHost>

重启apache2让设置生效
/etc/init.d/apache2 restart