Ads 468x60px

Pages

2011年4月18日 星期一

安裝 Remine 及 Migrate Trac to Redmine 之解決 wiki format 的相容問題(一)


Requirements:
  • CentOS 5.x
  • Redmine 1.1.x
  • Ruby 1.8.7
  • RubyGems: 1.3.7
  • Sqlite: 3.6.16 (For migration Trac to Redmine)
  • Rails: 2.3.5
  • Rack: 1.0.1
  • MySQL 5.1 or higher (recommended)
  • openssl + openssl-devel
  • zlib + zlib-devel
官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineInstall


原本想說,直接用現有的 rpm packages 來安裝以上的軟體就好了,可是最新的 ruby rpm 只有到 1.8.5 而已,所以只能用自己 compile 的方式來解決。


0. 安裝 compile 所需要的 packages
# yum install zlib-devel curl-devel expat-devel gettext-devel gcc make
1. 安裝 ruby 1.8.7:
~# cd ~
~# wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz
~# tar zxvf ruby-1.8.7-p334.tar.gz
~# cd ruby-1.8.7-p334
~/ruby-1.8.7-p334 # ./configure --prefix=/usr
~/ruby-1.8.7-p334 # make
~/ruby-1.8.7-p334 # make install
~/ruby-1.8.7-p334 # which ruby
/usr/bin/ruby
~/ruby-1.8.7-p334 $ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
 3. 安裝 sqlite 3.6.16:
~ # cd ~
~ # wget http://www.sqlite.org/sqlite-amalgamation-3.6.16.tar.gz
~ # tar xvzf sqlite-amalgamation-3.6.16.tar.gz
~ # cd sqlite-3.6.16
~ /sqlite-3.6.16 # ./configure --prefix=/usr
~ /sqlite-3.6.16 # make
~ /sqlite-3.6.16 # make install
~ /sqlite-3.6.16 # sqlite3 -version
3.6.16
4. 安裝 rubygem 1.3.7
~ # wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
~ # tar xvfz rubygems-1.3.7.tgz
~ # cd rubygems-1.3.7
~ /rubygems-1.3.7 # ruby setup.rb
5. 安裝 rails & rack & sqlite3
~ # gem install rails -v=2.3.5
~ # gem install rack -v=1.0.1
~ # gem install i18n -v=0.4.2
~ # gem install sqlite3-ruby
6. 安裝 mysql
~ # yum install mysql-server
~ # yum install mysql.x86_64
~ # yum install mysql-devel
~ # yum install ruby-mysql
~ # gem install mysql
7. 安裝 apache, fcgid(fastcgi)
~ # yum install httpd.x86_64
~ # yum install fcgi.x86_64   
~ # yum install fcgi-devel.x86_64
~ # yum install mod_fcgid.x86_64
~ # gem install fcgi
8. 安裝 redmine
~ # wget http://rubyforge.org/frs/download.php/74419/redmine-1.1.2.tar.gz
~ # tar xvfz redmine-1.1.2.tar.gz
~ # mkdir /var/www
~ # mv redmine-1.1.2 /var/www/redmine
9. 設定 redmine (依照官方說明即可)

2. Create an empty database and accompanying user named redmine for example.
For MySQL:
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'@'localhost';

3. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
Example for a MySQL database:
production:
  adapter: mysql
  database: redmine
  host: localhost
  port: 3306
  username: redmine
  password: my_password
4. Generate a session store secret.
rake generate_session_store
5. Create the database structure, by running the following command under the application root directory:
RAILS_ENV=production rake db:migrate
6. Insert default configuration data in database, by running the following command:
RAILS_ENV=production rake redmine:load_default_data
7. Setting up permissions
NB: Windows users have to skip this section.
The user who runs Redmine must have write permission on the following subdirectories: files, log, tmp (create the last one if not present).
Assuming you run Redmine with a redmine user:
mkdir tmp public/plugin_assets
sudo chown -R redmine:redmine files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets
8. Test the installation by running WEBrick web server:
ruby script/server webrick -e production
Once WEBrick has started, point your browser to http://localhost:3000/. You should now see the application welcome page.
Note: Webrick is not suitable for normal use, please only use webrick for testing that the installation up to this point is functional. It is not recommended to use webrick for anything other than development. Use one of the many other guides in this wiki to setup redmine to use either passenger (aka mod_rails) or mongrel to serve up your redmine.
9. Use default administrator account to log in:
  • login: admin
  • password: admin
10. 設定 Apache config & fastcgi
# vi /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
      ServerName doc1.corp.muchiii.com
      DocumentRoot /home/m/share/htdocs/redmine/public/
      ErrorLog logs/redmine_error_log

      <Directory /home/m/share/htdocs/redmine/public/>
         AllowOverride all
         Options Indexes ExecCGI FollowSymLinks
         Order Deny,Allow
         Deny from all
         Allow from 122.146.2.130 172.17.8.31
      </Directory>
</VirtualHost>
# vi /var/www/redmine/public/.htaccess
<IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi
</IfModule>
<IfModule mod_cgi.c>
        AddHandler cgi-script .cgi
</IfModule>
Options  FollowSymLinks  ExecCGI

RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.] )$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
<IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
Save the config and restart your httpd server
# /usr/sbin/service httpd configtest
# /usr/sbin/service httpd restart
Open your browser and hit http://redmine.mydomain.com, use default administrator account to log in.



11. Migrate Trac to Redmine, 轉移 Trac 的 project(sqlite3 格式) 到 Redmine 上。官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineMigrate, 由於預設安裝的 migrate_from_trac.rake 會有一點點小問題(http://www.redmine.org/issues/6868),所以需要手動改一下 source codes (/var/www/redmine/lib/tasks/migrate_from_trac.rake).


The problem seems to be that function Time.fake() has problem to handle when the given input is nil.
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
To solve that issue I modified this function in such way :
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
         time = 0 if time.nil? 
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
接下來,就照著官方文件的步驟:
1. Run the following command, where test is your Redmine target environment:
rake redmine:migrate_from_trac RAILS_ENV="test"
2. The script (source:trunk/lib/tasks/migrate_from_trac.rake) asks you for your Trac settings:
Trac directory []: /var/trac/myproject
Trac database adapter (sqlite, sqlite3, mysql, postgresql) [sqlite]:
Database encoding [UTF-8]:
Target project identifier []: myproject
Trac directory is the root directory of your Trac environment. Redmine will look in this directory for db/trac.db (if you choose sqlite/sqlite3 database) and the attachments directory.
When using a mysql or postgresql Trac database, the script will ask you for the connection parameters (host, database name, username and password).
Target project identifier is the identifier of the Redmine project in which the data will be loaded (the project is created if not found).
4. The script migrates your data:
Deleting data
Migrating components..............................
Migrating milestones..............
Migrating custom fields.......
Migrating tickets.................................
Migrating wiki...........

Components: 29/30
Milestones: 14/14
Tickets: 1275/1275
Ticket files: 106/106
Custom values: 4409/4409
Wiki edits: 102/102
最後的問題會是 wiki 轉到 redmine 之後,所有的 wiki link 都亂掉了。預計用一個 script 來解決。


待續...

0 意見:

張貼留言