---
title: "Fedora Core 6 上安裝 beast"
author: "thegiive"
date: "2007-08-14T14:48:43Z"
tags: []
slug: "fedora-core-6-beast"
draft: false
lastmod: "2007-08-14T14:48:43Z"
id: 112296
url: "https://thegiive.iteye.com/blog/112296"
---

我選擇 apache2.2 + mongrel\_cluster + postgresql

安裝 apache 和其他的東西。  
sudo yum install httpd  
sudo yum install httpd-devel  
sudo yum install openssl  
sudo yum install readline

安裝 ruby  
sudo yum install ruby  
sudo yum install ruby-devel  
sudo yum install ruby-libs  
sudo yum install rdoc  
sudo yum install irb

安裝 postgresql  
sudo yum install postgresql  
sudo yum install postgresql-devel  
sudo yum install postgresql-libs  
sudo yum install postgresql-server

初始化 postgres  
sudo mkdir -p /var/db/postgresql81/defaultdb  
sudo chown postgres:postgres /var/db/postgresql81/defaultdb  
sudo -u postgres initdb -D /var/db/postgresql81/defaultdb  
sudo -u postgres pg\_ctl -D /var/db/postgresql81/defaultdb \\  
\-l /var/db/postgresql81/defaultdb/postgres.log start

拿來抓 beast... 捨 svn 取 svk 因為我討厭一堆 .svn  
sudo yum install perl-SVK

sudo yum install rubygems

至少要用這些 gem  
sudo gem install rails -y  
sudo gem install mongrel\_cluster -y  
sudo gem install redcloth -y  
sudo gem install ruby-openid -y  
sudo gem install ruby-postgres -y

建立目錄。  
mkdir -p ~/projects/beast  
cd ~/projects/beast

用 svk 抓不會有一堆 .svn 礙眼。  
svk mirror //mirror/beast \\  
http://svn.techno-weenie.net/projects/beast/branches/stable-1.0/  
svk sync -s HEAD //mirror/beast  
cd stable-1.0

產生讓 beast 用的資料庫。  
sudo -u postgres createdb beast\_prod

設定資料庫設定檔。  
cp config/database.example.yml config/database.yml

nano config/database.yml  
\=========================  
production:  
  database: beast\_prod  
  adapter: postgresql  
  host: localhost  
  username: postgres  
  password:  
\=========================

初始化 beast 資料庫。  
rake db:schema:load RAILS\_ENV=production

非常囉唆的 cluster 設定，user 可以開 mongrel,  
不過因為我懶所以用自己的帳號跑。  
sudo mongrel\_rails cluster::configure -e production \\  
\-p 2000 -N 3 -c /home/YOUR\_NAME/projects/beast/stable-1.0 \\  
\-a 0.0.0.0 --user YOUR\_NAME --group YOUR\_NAME

啟動 mongrel\_cluster 吧。  
sudo mongrel\_rails cluster::start

接著是 apache2.2 的 mod\_proxy\_balancer 的設定，  
如果 mod\_proxy\_balancer 沒有啟動記得把他打開。

建立 balancer 導向 port 2000~2002  
sudo nano /etc/httpd/conf/httpd.conf  
\=====================================  
&lt;Proxy balancer://YOUR\_BALANCER&gt;  
  BalancerMember http://YOUR\_ADDRESS:2000  
  BalancerMember http://YOUR\_ADDRESS:2001  
  BalancerMember http://YOUR\_ADDRESS:2002  
&lt;/Proxy&gt;

Listen 80  
&lt;VirtualHost \*:80&gt;  
  ServerAdmin YOUR\_EMAIL  
  ServerName YOUR\_ADDRESS  
  ProxyPass / balancer://YOUR\_BALANCER/  
  ProxyPassReverse / balancer://YOUR\_BALANCER/  
  ProxyPreserveHost on  
  ErrorLog /home/YOUR\_NAME/projects/beast/stable-1.0/log/apache\_error.log  
  CustomLog /home/YOUR\_NAME/projects/beast/stable-1.0/log/apache\_access.log combined

  ProxyPass /images !  
  ProxyPass /stylesheets !  
  ProxyPass /javascripts !  
  Alias /images /home/YOUR\_NAME/projects/beast/stable-1.0/public/images  
  Alias /stylesheets /home/YOUR\_NAME/projects/beast/stable-1.0/public/stylesheets  
  Alias /javascripts /home/YOUR\_NAME/projects/beast/stable-1.0/public/javascripts  
&lt;/VirtualHost&gt;  
\=====================================

接著啟動 apache 就 ok 了。  
sudo apachectl start

最後來設定 beast 的 smtp, 如果想用 gmail 寄信的話，  
我之前試過兩個方式，一個是使用 msmtp,  
另一個是有人有寫一小段 ssl smtp 的 patch, 可以參考這裡：  
[http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html](http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html)

nano config/environment.rb  
加入：  
\===========================  
ActionMailer::Base.smtp\_settings = {  
  :address =&gt; "smtp.gmail.com",  
  :port =&gt; 587,  
  :domain =&gt; 'YOUR\_DOMAIN',  
  :user\_name =&gt; "YOUR\_GMAIL\_ACCOUNT",  
  :password =&gt; 'YOUR\_GMAIL\_PASSWORD',  
  :authentication =&gt; :plain  
}  
\===========================

nano app/models/user\_mailer.rb  
\===============================  
@from = 'YOUR\_GMAIL\_ACCOUNT@gmail.com'  
\===============================  
我不是很確定這一步要不要做，我猜不做會被 gamil 擋掉。

接下來把那段程式碼 copy 到可以被 require 的地方，我是放在 lib 下：  
nano lib/smtp\_tls.rb  
接著把他 require 進去：  
nano config/environment.rb  
\===========================  
require 'smtp\_tls'  
\===========================

sudo mongrel\_rails cluster::restart  
註冊一下試試寄信吧！如果失敗的話，那篇連結裡有個 workaround:

nano lib/smtp\_tls.rb  
\=====================  
rescue EOFError  
  ;  
rescue OpenSSL::SSL::SSLError =&gt; e  
  puts('Unexpected Exception: ' + e.message + ' : ' +  
    e.backtrace.join("\\n") )  
end  
\=====================

我之前用是沒有這個問題，但在這台 fedora 上卻有這個問題，  
也許是要更新 openssl 的版本？不管如何，加入上面那段暫時可用。

結論：  
還是 macports 好用，速度快，更新快，只是 build 要很久就是了。