ラベル redmine の投稿を表示しています。 すべての投稿を表示
ラベル redmine の投稿を表示しています。 すべての投稿を表示

2015年6月10日水曜日

redmineの導入 redmineの移行作業

記事概要


既存のredmineのデータを、新規のredmineに移行する手順についてまとめました。

redmineのインストール記事はこちら
redmineの環境構築記事はこちら

環境

  • centos6.6
  • nginx, unicorn, redmine2.2.3

データ移行に必要なデータ


redmineの移行に必要なデータは以下の二つになります。

  • Redmineのインストールディレクトリ直下のfilesディレクトリ
  • データベースのバックアップ

移行作業を行う前に、上記のデータを取得しておいてください。

データ移行環境の注意点


移行前のredmineのバージョンと移行後のredmineのバージョンは一致させる必要があります
もし、移行後のredmineのバージョンを最新にあげたい場合は、

  1. 同じredmineのバージョンでデータ移行を実施
  2. データ移行したredmineを最新にバージョンアップ

という手順を踏む必要があります。

では、次から詳細なやり方を示していきます。

filesディレクトリのリカバリ


移行するバックアップのfilesディレクトリを用意し、パスを確認します。


/home/{username}/before_redmine/files

移行先のredmineのfilesディレクトリのパスを確認します。


/var/www/rails/redmine/files

移行先へファイルをコピーします。


cp -ar /home/{username}/before_redmine/files/* /var/www/rails/redmine/files

// ファイルが移行していることを確認する
ls -l /var/www/rails/redmine/files

ファイル移行が終了した後は、データベースのバックアップを行います。

データベース(mysql)のリカバリ


データベースのバックアップファイルがあるフォルダに移動します


cd /home/{username}/before_redmine/

ls -l

// 受け取ったmysqlのdump
redmine.gz

// 解凍
gunzip redmine.gz

データベースのバックアップファイルの解凍を行わないでリストアコマンドを叩くと、以下のようなエラーが発生することがあります。


Warning: Using a password on the command line interface can be insecure.
ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: '
                                               '.

上記のエラーを防ぐためにもgunzipで解凍をしておきましょう。

続いて、データベースをリストアします。


mysql -u root -proot_test redmine < redmine
Warning: Using a password on the command line interface can be insecure.
                                               '.

エラーがおきなければ成功です。
unicornとnginxを再起動して、ブラウザでURLを入力すれば移行したデータが反映されたredmineが利用できます。

以上

関連記事
参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加

2015年5月27日水曜日

redmineの導入 redmineをunicornとnginxで動かす

  • 公開日:2015年05月27日
  • 最終更新日:2015年05月28日

以前の記事でredmineのインストール手順を記載しました。
今回はunicornとnginxを使ってredmineを動かす設定をします。

環境

  • centos6.6
  • redmine2.2.3(ruby1.9.3, rails3.2.12)
  • nginx1.8.0

注意

railsのアプリでunicornとnginxの連携をやったことがないと、理解できない可能性があります。
無理だと思ったら諦めて、インストーラーを使って動作させるのも選択の一つです。redmineは所詮ツールだということを忘れないようにしましょう。

unicornをインストール


// redmineのフォルダに移動
cd /var/www/rails/redmine

// Gemfileを開く
vi Gemfile

Gemfile

Gemfileにunicornを記載します。


gem "unicorn"

unicornをインストール


bundle install

unicornの導入に成功したかどうかを、仮起動で確かめます。


bundle exec unicorn_rails -l 8081 -E production

localhost:8081でredmineの画面が表示されることが確認できれば、導入は成功です。

設定ファイル

導入に成功したら、細かな設定をするためのconfigファイルを用意します。


// プロジェクトルートに移動
cd /var/www/rails/redmine
// unicorn.rbを作成
touch config/unicorn.rb

unicorn.rb

unicorn.rbには以下のように設定を記載します


@app_path = '/var/www/rails/redmine'

worker_processes 2
working_directory "#{@app_path}/"
preload_app true
timeout 30
listen "/tmp/unicorn.sock", :backlog => 64
listen 8081, :tcp_nopush => true
pid "/tmp/unicorn.pid"
stderr_path "#{@app_path}/log/unicorn.stderr.log"
stdout_path "#{@app_path}/log/unicorn.stdout.log"

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
  old_pid = "#{server.config[:pid]}.oldbin"

  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
  sleep 1
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

動作確認

作成したconfigファイルを指定して動かします。nginxとの連携を考慮し、バックグラウンドで動かします。


// プロジェクトルートに移動
cd /var/www/rails/redmine

// unicorn起動
bundle exec unicorn_rails -c config/unicorn.rb -E production -D

動作停止

バックグラウンドで動かしているので、コマンドで停止します。


cat /tmp/unicorn.pid | xargs kill

画面が非表示になればunicornでの起動と停止は成功です。

nginxとunicornの連携

さて次はnginxとunicornを連携する設定をおこないます。

/etc/nginx/nginx.conf


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    # 以下を追記
    upstream unicorn-redmine {
        server unix:/tmp/unicorn.sock;
    }

    include /etc/nginx/conf.d/*.conf;
    
}

upstream unicorn-redmineの箇所を追加しています。unicornのソケット通信との連携を設定しています。

/etc/nginx/conf.d/default.conf


server {
    listen       80;
    client_max_body_size 1G;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root /var/www/rails/redmine/public;
        try_files $uri/index.html $uri.html $uri @app;
    }
    
    location @app {
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_connect_timeout 60;
        proxy_read_timeout 60;
        proxy_send_timeout 600;

        # If you don't find the filename in the static files
        # Then request it from the unicorn server
        if (!-f $request_filename) {
            proxy_pass http://unicorn-redmine;
            break;
        }
    }
    

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginxの設定は以上になります。

nginxの再起動とunicornの起動


// unicorn起動
bundle exec unicorn_rails -c config/unicorn.rb -E production -D

// nginx再起動

localhostでredmineのトップページが確認できれば成功です。ポートの8081を指定すると、unicornだけで動作しているのも確認できると思います。

以上

参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加

2015年5月23日土曜日

redmineの導入 redmineの導入とバージョンアップを行う

redmineのインストール手順の記載。
以下の手順で実装

  • 既存のredmineを異なるサーバーに移行
  • 移行したredmineを最新バージョンにアップデート

今回の説明では珍しくchefは使いません。chef版はまた今後記載します。

環境

  • centos6.6

gitをインストール

git cloneが必要なのでgitをインストールします。


yum -y install git

rbenvをインストール

rbenvはrubyのバージョンを管理するツールです。

今回はrubyのバージョンを管理したいのでrbenvをインストールします。


// rbenvを取得
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

// PATH に追加
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

// .bash_profile に追加
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

// 設定の再読み込み
$ exec $SHELL -l

// rbenvの確認
rbenv --version
rbenv 0.4.0-148-g5b9e4f0

ruby-buildをインストール

読んで時の如く、rubyのbuildに必要なライブラリです。


git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

パッケージをインストール

rubyのビルドに必要なパッケージをインストールします


yum -y install openssl-devel
yum -y install gcc

rubyをインストール

rubyの1.9.3と2.2.2をインストールします


rbenv install 1.9.3-p551
rbenv install 2.2.2

rbenv versions
  1.9.3-p551
  2.2.2

デフォルトのruby設定

デフォルトのrubyを1.9.3に指定します


rbenv global 1.9.3-p551

ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]

bundlerの導入

Gemパッケージの管理をできるようにします。


gem install bundler

rehash

rbenvを再読み込みします


rbenv rehash

redmineのinstall準備


// 必要なパッケージ(postgrres) gemfileのコメントアウトでも良い
yum -y install postgresql-devel

// sqlite3 gemfileのコメントアウトでも良い
yum -y install sqlite sqlite-devel

// rmagic gemfileのコメントアウトでも良い
yum -y install ImageMagick ImageMagick-devel

無駄にパッケージを入れるより、Gemfileをコメントアウトするほうをおすすめします。railsでの開発経験がない人は、パッケージをいれておきましょう。

redmineソースを取得


// フォルダを作成
mkdir -p /var/www/app

// フォルダに移動
cd /var/www/app

// バージョンを指定して取得
svn checkout http://svn.redmine.org/redmine/tags/2.2.3/ redmine2.2.3

cd redmine2.2.3

ここでは最新版でなく、古いredmineをダウンロードします。redmineのバージョンごとの取得方法はここで記載しています。

DBの作成

DBはmysqlがインストール済みの前提で進めます。


mysql -uroot -p

create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'password';
grant all privileges on redmine.* to 'redmine'@'localhost';

DB設定ファイル変更

上記で作成したDBに接続するための設定ファイルを作成します。


// コピー
cp database.yml.example database.yml

// 上記で設定したデータに変更
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: password
  encoding: utf8

mysqlのバージョンが5.1以降の場合は、adapter: mysqlをadapter: mysql2に変更する必要があります。

セッションの生成


cd redmine2.2.3

bundle exec rake generate_secret_token

テーブル作成


RAILS_ENV=production bundle exec rake db:migrate

デフォルトデータをデータベースに登録


RAILS_ENV=production  bundle exec rake redmine:load_default_data

起動テスト


ruby script/rails server webrick -e production

ブラウザアクセステスト


http://localhost:3000/

画面が表示されればOK。

以上

参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加

2015年5月21日木曜日

redmineの導入 バージョンを指定してredmineのソースを取得する

redmineのインストールのまとめ。
色々な人が参照できるように、今回はchefは使いません。

環境

  • centos6.6

svnをインストール

ソースコードの取得にはSubversionが必要なので、ない場合はsvnをインストールします。


yum -y install subversion

redmineをインストール

redmineのバージョンを複数管理したいので、複数取得します。

version2.2.3を取得する


svn checkout http://svn.redmine.org/redmine/tags/2.2.3/ redmine2.2.3

version3.0.3を取得する


svn checkout http://svn.redmine.org/redmine/tags/3.0.3/ redmine3.0.3

上記のようにsvnを利用してリポジトリからソースコードを取得してやれば大丈夫です。

以上

参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加
Related Posts Plugin for WordPress, Blogger...