2010年2月26日金曜日

RedmineをPostgreSQLで構築

ubuntu8.04 LTS Serverに、データベースをPostgreSQLを使ってRedmineサーバーを構築した時の手順です。
Redmine用のユーザーとデータベースを次の構成で作成します。
ubuntuのユーザー名redmine
redmineのホームディレクトリ/home/redmine
データベース名redmine
データベースのユーザー名redmine

Apache2をインストールします。
$ sudo apt-get install apache2

PostgreSQLをインストールします。
$ sudo apt-get install postgresql
$ su - postgres
$ createuser -P redmine
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
$ createdb redmine -O redmine -E UTF8
$ exit

rubyとruby on Railsをインストールします。
$ cd
$ sudo apt-get install ruby
$ sudo apt-get install libpgsql-ruby
$ sudo apt-get install rdoc irb ri ruby1.8-dev libyaml-ruby libzlib-ruby libopenssl-ruby
$ sudo apt-get install imagemagick librmagick-ruby1.8 build-essential
$ wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
$ tar zxvf rubygems-1.3.5.tgz
$ cd rubygems-1.3.5
$ sudo ruby setup.rb
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
$ sudo gem update --system
$ sudo gem install rails --version 2.1.2
$ sudo gem install postgres-pr
$ sudo gem install rake

Redmineをインストールします。
$ cd
$ wget http://rubyforge.org/frs/download.php/67144/redmine-0.8.7.tar.gz
$ tar zxvf redmine-0.8.7.tar.gz
$ mv redmine-0.8.7 redmine
$ cd redmine
$ cp config/database.yml.example config/database.yml
$ vi config/database.yml
内容を次のように変更します。
production:
  adapter: postgresql
  database: redmine
  host: localhost
  username: redmine
  password: パスワードを指定します。
  encoding: utf8
続けて
$ rake config/initializers/session_store.rb
$ rake db:migrate RAILS_ENV=production
$ rake load_default_data RAILS_ENV=production
(in /home/redmine/rubygems-1.3.5/redmine)

Select language: bg, ca, cs, da, de, en, es, fi, fr, he, hu, it, ja, ko, lt, nl, no, pl, pt, pt-br, ro, ru, sk, sr, sv, th, tr, uk, vn, zh, zh-tw [en] ja
「languageを選択して」といわれるので、jaと入力します。
====================================
Default configuration data loaded.

Note: The rake task load_default_data has been deprecated, please use the replacement version redmine:load_default_data
$ cp config/email.yml.example config/email.yml
$ vi config/email.yml
次のように変更します。
production:
  delivery_method: :smtp
  smtp_settings:
    address: SMTPサーバーを指定します。
    port: SMTPのポートを指定します。
    domain: ドメインを指定します。
    #authentication: :login
    #user_name: redmine@example.net
    #password: redmine

ここで、一旦サーバーを起動してテストしてみます。
$ script/server -e production
ウェブブラウザから、http://サーバーアドレス:3000/にアクセスしてみます。
このとき、ログインユーザーはadminでパスワードもadminです。
無事ログインできたら、Administration→Settingをクリックして、以下の設定を変更します。
  • Default languageをJapaneseにします。
  • Users display formatをAdmin Redmineにします(名前の表示を氏 名の順に表示)。
  • Attachment max. sizeを、添付ファイルの上限サイズに変更します(Kbyte単位)。
  • Host name and pathをホストアドレスにします。
これで、ウェブブラウザを閉じて、ターミナルもCtrl+Cでサーバースクリプトを停止します。

Passenger(Ruby on RailsアプリケーションをApacheで動かすためのソフトウエア)をインストールします。
$ sudo apt-get install apache2-prefork-dev libapr1-dev libaprutil1-dev
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v2.2.8.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.
1
1を入力します。
~中略~
--------------------------------------------
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.8
   PassengerRuby /usr/bin/ruby1.8

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.


--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

   <virtualhost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /usr/lib/ruby/gems/1.8/gems/passenger-2.2.8/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
と表示されたらOK。
Apache2の設定方法も親切に教えてくれるので、それを参考にApache2の設定を行います。
$ cd /etc/apache2/mods-available/
$ sudo vi passenger.load
次のように編集します。
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
続けて
$ sudo vi passenger.conf
次のように編集します。
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.8
PassengerRuby /usr/bin/ruby1.8
続けて
$ sudo a2enmod passenger
$ cd /etc/apache2/sites-available/
$ sudo cp default default.org
$ sudo vi default
DocumentRootを
        DocumentRoot /var/www/
から
        DocumentRoot /home/redmine/redmine/public
に変更します。またDocumentRootの下に以下を追加します。
        <directory /home/redmine/redmine/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
続けて
$ sudo a2enmod rewrite
$ sudo /etc/init.d/apache2 restart
でapacheを再起動します。
これで、ウェブブラウザでサーバーに接続できればインストール完了です。


[おまけ]
・PDFのCSVの文字化けを回避する方法。
/home/redmine/redmine/lang/ja.ymlを
general_csv_encoding: SJIS
general_pdf_encoding: UTF-8
から
general_csv_encoding: CP932
general_pdf_encoding: CP932
に変更します。

・リポジトリのソースコードのエンコーディングを設定。
管理→設定→リポジトリ→リポジトリのエンコーディングの欄に
SO-2022-JP, EUC-JP, UTF-8, SHIF_JIS, WINDOWS-31J
を設定します。

0 コメント :

コメントを投稿