FreeBSD8.1+Redmine(BTS)+Rails+thin+lighttpdをインストール

はじめに

FreeBSD8.1を使いバグトラッキングシステムの1つであるRedmineをインストールします。 Redmineはソフトウェア開発などITプロジェクトでの利用に最も適したwebアプリケーションで、それ以外の業務においてもタスクとその進捗の管理、情報共有に活用することができます。

今回の構成はフロントにlighttpdでリクエストを受け付け、バックエンドで動いているthinサーバ(rubyで書かれたwebサーバ)でrails(webアプリフレームワーク)を使って動くRedmine(localhost:9000)にリクエストをリバースproxyさる構成をとります。この辺りがややこしいのですがthinサーバの上にrailsが載りその上にredmineが載ってるようなイメージです?またデータベースにはsqlite3を利用します。

install

ports を利用してinstall

※依存関係によりその他のportsもろもろインストールされます。

# portinstall lighttpd
# portinstall redmine
# portinstall sqlite3

ruby関係のアプリはgemを使いインストールします

# gem install rails
# gem install rack
# gem install thin

sqlite3のruby用ドライバを入れます

# gem install sqlite3-ruby

redmineのdb等のconfig

/usr/local/www/redmine/config/database.yml

production:
  adapter: sqlite3
  database: db/redmine.db

redmine初期化を行う

# cd /usr/local/www/redmine
# RAILS_ENV=production rake config/initializers/session_store.rb
# RAILS_ENV=production rake db:migrate
# RAILS_ENV=production rake redmine:load_default_data

組み込みのウェブサーバーwebrickを使ってredmineの動作を確認

 ruby script/server webrick -e production

ブラウザからhttp://127.0.0.1:3000/でアクセスできればテスト成功です

thinで利用するディレクトリ作成

# mkdir /usr/local/www/redmine/thin/
# chown -R www:www /usr/local/www/redmine/
# chmod a+rwx /usr/local/www/redmine/tmp/pids/

redmineをthinサーバ上で動かすためのconfig

  • 主な設定内容
  • 動作ユーザ:www
  • ポート番号:9000
  • 起動サーバ数:4

/usr/local/www/redmine/thin/redmine.yml

---
group: www
pid: tmp/pids/thin.pid
wait: 30
timeout: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 4
user: www
daemonize: true
port: 9000
chdir: /usr/local/www/redmine

thinサーバ起動

# thin -C thin/redmine.yml start

thinで動くアプリケーションサーバ(redmineが載っている)は

  • localhost:9000
  • localhost:9001
  • localhost:9002
  • localhost:9003

の4つのサーバでリクエストを待ちます。

フロントで動くlighttpdサーバの設定

lightyの設定でのキモはredmine.example.orgでアクセスを一手にうけつけ、 redmineへのリクエストをロードバランスしlocalhost上で動いている各4つのthinサーバにリクエストを振り分ける設定をします。

/usr/local/etc/lighttpd.conf

# mod_proxyを有効にする
server.modules = (
                    色々なモジュール~省略
                  "mod_proxy",
)


# バーチャルホストの設定redmine.example.orgのドメインにアクセスすると
# バックエンドで動くredmineアプリlocalhost:9000-9003に
# リバースプロクシしてredmineにアクセスできるようにします

$HTTP["host"] == "redmine.example.org" {

  $HTTP["url"] !~ "^/(stylesheets|javascripts|[^.]+\.html|[^.]+\.htm|[^.]+\.css|[^.]+\.xml|robots\.txt)" {
        server.max-keep-alive-requests = 0
        setenv.add-request-header = ("X-Forwarded-Host" => "redmine.example.org" )
        proxy.server    = ("" =>
            (
                ("host" => "127.0.0.1", "port" => "9000" ),
                ("host" => "127.0.0.1", "port" => "9001" ),
                ("host" => "127.0.0.1", "port" => "9002" ),
                ("host" => "127.0.0.1", "port" => "9003" ),

            )
        )
  }

  server.document-root   = "/usr/local/www/redmine/public/"
  alias.url  += (
                "/javascripts/" => "/usr/local/www/redmine/public/javascripts",
                "/stylesheets/" => "/usr/local/www/redmine/public/stylesheets",
                 )
}

参考)thinサーバを起動するスクリプト

#!/bin/sh

# $FreeBSD: ports/www/redmine/files/redmine.in,v 1.3 2010/03/16 02:02:52 dougb Exp $

# PROVIDE: redmine
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following line to /etc/rc.conf[.local] to enable redmine
#
# redmine_enable (bool):        Set to "NO" by default.
#                               Set it to "YES" to enable redmine.
# redmine_flags (str):          Custom additional arguments to be passed
#                               to redmine.

. /etc/rc.subr

name="redmine"
rcvar=`set_rcvar`
command=ruby18

pidfile="/usr/local/www/redmine/tmp/pids/thin.pid"

load_rc_config $name

# set defaults
: ${redmine_enable="NO"}
: ${redmine_flags=""}

command_args="-C /usr/local/www/redmine/thin/redmine.yml"
start_cmd="/usr/local/bin/thin ${command_args} ${redmine_flags} start"

run_rc_command "$1"
created:

Back to top