2012年2月24日金曜日

Redmineデータバックアップスクリプト


Redmineのデータをバックアップするスクリプトの例です。
概要は、Redmineで使用しているデータベースをダンプし、
添付ファイルをアーカイブしてダンプファイルとともに別
領域にコピーします。

バージョン1.3.1で動作確認済みです。


■仕様
バックアップ対象:
 MySQLのデータベース、db_redmineのダンプ
 /opt/redmine1.3.1 ディレクトリ全体をアーカイブ
 ※本来は添付ファイルだけでよいので/opt/redmine1.3.1/publicを対象とすればよい。

バックアップ開始時刻:午前3時33分
 /etc/crontabに登録しています。

バックアップ世代:10世代
 10日以上前のバックアップは自動削除されます。
 構築直後のデータサイズは全部で約10MB以下です。

バックアップ先:別Linuxサーバの/home/backup/redmine
 ※筐体の異なる物理サーバ上のVMの領域をNFSマウントします。


■マウントポイント作成
[root@redmine ~]# mkdir -p /opt/bk_redmine/backup


■バックアップスクリプト
[root@redmine ~]# cat /opt/bk_redmine/bk_redmine.sh
#!/bin/sh
#######################################################################
# << 機能概要 >>
# Redmineのデータを別サーバのマウント領域にバックアップする
#
# << 前提 >>
# /opt/bk_redmine/backup ディレクトリが存在すること
# /opt/bk_redmine/bk_redmine.sh としてこのファイルが存在すること
#
# <<変更履歴>>
# Version  変更日      変更者        変更内容
# --------+-----------+-------------+----------------------------------
#     1.0  2012/02/21  tanyao        新規作成
#######################################################################

BASE_DIR=/opt/bk_redmine
MOUNT_POINT=$BASE_DIR/backup
LOG_FILE=$0.log

echo "`date \"+%Y%m%d %H:%M:%S\"` INFO: bk_redmine start." >> $LOG_FILE

# mount settings
mount -t nfs 192.168.xxx.195:/home/backup/redmine $MOUNT_POINT

mount_chk=`mount | grep 192.168.xxx.195 | wc -l`
if [ $mount_chk -ge 1 ]; then
    echo "`date \"+%Y%m%d %H:%M:%S\"` INFO: mount check OK." >> $LOG_FILE
else
    echo "`date \"+%Y%m%d %H:%M:%S\"` ERROR: mount check error." >> $LOG_FILE
    echo "" >> $LOG_FILE
    exit 1
fi

# Backup DataBase
/usr/bin/mysqldump -u root db_redmine > $MOUNT_POINT/db_redmine_`date +%Y%m%d`.dbf

# Backup files
cd /opt/
tar -zcf $MOUNT_POINT/redmine-1.3.1_`date +%Y%m%d`.tar.gz redmine-1.3.1
cd -

# 10日以前のバックアップは削除
find $MOUNT_POINT -mtime +10 -iregex ".*\.dbf$\|.*\.gz$" > $BASE_DIR/delete.list
for i in `cat $BASE_DIR/delete.list`
do
    rm -rf $i
    echo "`date \"+%Y%m%d %H:%M:%S\"` INFO: $i is deleted." >> $LOG_FILE
done

# unmount
umount $MOUNT_POINT

echo "`date \"+%Y%m%d %H:%M:%S\"` INFO: Backup of Redmine data has been completed." >> $LOG_FILE
echo "" >> $LOG_FILE

exit 0
[root@redmine ~]#

■動作確認(cron実行させるため直近の時刻を設定)
[root@redmine ~]# grep -i redmine /etc/crontab
# Backup of Redmine
31 13  *  *  * root /opt/bk_redmine/bk_redmine.sh
[root@redmine ~]#

[root@redmine ~]# tail -f /opt/bk_redmine/bk_redmine.sh.log
20120221 13:31:01 INFO: bk_redmine start.
20120221 13:31:01 INFO: mount check OK.
20120221 13:31:04 INFO: /opt/bk_redmine/backup/db_redmine_20120105.dbf is deleted.
20120221 13:31:04 INFO: /opt/bk_redmine/backup/db_redmine_20120107.dbf is deleted.
20120221 13:31:04 INFO: Backup of Redmine data has been completed.


バックアップ先サーバ(バックアップ前)
[root@bksrv02 redmine]# ll
合計 12204
-rw-r--r--  1 root root   770214  1月  5 11:11 db_redmine_20120105.dbf
-rw-r--r--  1 root root   770214  1月  7 11:11 db_redmine_20120107.dbf
-rw-r--r--  1 root root   770214  2月 15 11:11 db_redmine_20120215.dbf
-rw-r--r--  1 root root 10144029  2月 21 10:19 redmine-1.3.1_20120221.tar.gz
[root@bksrv02 redmine]#

バックアップ先サーバ(バックアップ後)
[root@bksrv02 redmine]# ll
合計 11468
-rw-r--r--  1 root root   770214  2月 15 11:11 db_redmine_20120215.dbf
-rw-r--r--  1 root root   786275  2月 21 13:31 db_redmine_20120221.dbf
-rw-r--r--  1 root root 10154630  2月 21 13:31 redmine-1.3.1_20120221.tar.gz
[root@bksrv02 redmine]#

→10日以前のバックアップは削除される。同名のバックアップファイルがあったとしても上書きされる。

2012年2月16日木曜日

CentOS6.2 Redmine1.3.1構築メモ(3)

CentOS6.2にRedmine1.3.1を構築する手順をまとめてみました。
 Step1. パッケージおよびインストーラの準備
 Step2. MySQLの準備
 Step3. Ruby Enterprise Edition インストール
 Step4. Redmine インストール
 Step5. ApacheにPassenger組込み

■構成情報
・OS:        CentOS6.2(64bit)
・MySQL:     5.1.52(OSバンドル)
・Ruby:      1.8.7(Ruby Enterprise Editionを利用)
 ・rack:    1.1.2
 ・rake:    0.9.2
 ・i18n:    0.4.2
・gem:       1.6.2
・Apache:    2.2.15(OSバンドル)
・Passenger: 3.0.11
・Redmine:   1.3.1


Step5. ApacheにPassenger組込み
■Passengerのインストール
[root@redmine ~]# gem install passenger --no-rdoc --no-ri
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions.  This could take a while...
Fetching: daemon_controller-1.0.0.gem (100%)
Fetching: passenger-3.0.11.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-1.0.0
Successfully installed passenger-3.0.11
3 gems installed
[root@redmine ~]#


■PassengerのApache用モジュールのインストール
[root@redmine ~]# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v3.0.11.

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.


--------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Curl development headers with SSL support... found
 * OpenSSL development headers... found
 * Zlib development headers... found
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/local/bin/rake
 * rack... found
 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... found at /usr/sbin/apxs
 * Apache Portable Runtime (APR) development headers... found at /usr/bin/apr-1-config
 * Apache Portable Runtime Utility (APU) development headers... found at /usr/bin/apu-1-config

--------------------------------------------
Compiling and installing Apache 2 module...
(中略)

--------------------------------------------
The Apache 2 module was successfully installed.

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

   LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.11
   PassengerRuby /usr/local/bin/ruby

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:

   
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      
   

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

  /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.11/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.
[root@redmine ~]#


■Apacheの設定
⇒worker MPMに切り替える
[root@redmine ~]# vi /etc/sysconfig/httpd
[root@redmine ~]# grep httpd.worker /etc/sysconfig/httpd
#HTTPD=/usr/sbin/httpd.worker
HTTPD=/usr/sbin/httpd.worker ←追記

⇒passnger.conf作成
[root@redmine ~]# vi /etc/httpd/conf.d/passnger.conf
[root@redmine ~]# cat /etc/httpd/conf.d/passnger.conf
# output of "passenger-install-apache2-module"
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.11
PassengerRuby /usr/local/bin/ruby

# rails settings
RailsBaseURI /redmine

# Passengerが追加するHTTPヘッダを削除するための設定
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

# 必要に応じてPassengerのチューニングのための設定を追加。
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0
[root@redmine ~]#

⇒Apache自動起動設定
[root@redmine ~]# chkconfig httpd on; chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@redmine ~]#

⇒Redmineディレクトリの所有者変更
[root@redmine ~]# chown -R apache: /opt/redmine-1.3.1

⇒サブディレクトリでRedmineを実行(シンボリックリンク作成)
[root@redmine ~]# ln -s /opt/redmine-1.3.1/public /var/www/html/redmine

⇒/etc/hosts修正
[root@redmine ~]# vi /etc/hosts
[root@redmine ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.xxx.234   redmine.kuitan.net redmine
[root@redmine ~]#


⇒Apacheを起動
[root@redmine ~]# /etc/init.d/httpd configtest
Syntax OK
[root@redmine ~]# /etc/init.d/httpd graceful
httpd not running, trying to start
[root@redmine ~]# /etc/init.d/httpd status
httpd.worker (pid  16808) を実行中...
[root@redmine ~]#


⇒ブラウザからアクセス
http://192.168.xxx.234/redmine
ログイン:admin/admin

★終了ーーー


■作業完了後のディスク使用状況
[root@redmine ~]# df -m
Filesystem           1M-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/vg_redmine-lv_root
                          4607      3666       708  84% /
tmpfs                      751         1       751   1% /dev/shm
/dev/sda1                  485        33       428   7% /boot
[root@redmine ~]#


■初期状態のDBおよび添付ファイルをバックアップ
[root@redmine ~]# mkdir redmine_bk
[root@redmine ~]# mysqldump -u root db_redmine > /root/redmine_bk/db_redmine_initial.dbf
[root@redmine ~]# cd /opt/redmine-1.3.1/files/
[root@redmine files]# tar -zcf /root/redmine_bk/files_initial.tar.gz *
→初期状態ではfilesディレクトリにはdelete.meファイルしかないので実質的には不要。

[root@redmine ~]# ll /root/redmine_bk/
合計 60
-rw-r--r-- 1 root root 55227  2月  8 18:47 2012 db_redmine_initial.dbf
-rw-r--r-- 1 root root   151  2月  8 18:48 2012 files_initial.tar.gz
[root@redmine ~]#

2012年2月15日水曜日

CentOS6.2 Redmine1.3.1構築メモ(2)

CentOS6.2にRedmine1.3.1を構築する手順をまとめてみました。
 Step1. パッケージおよびインストーラの準備
 Step2. MySQLの準備
 Step3. Ruby Enterprise Edition インストール
 Step4. Redmine インストール
 Step5. ApacheにPassenger組込み

■構成情報
・OS:        CentOS6.2(64bit)
・MySQL:     5.1.52(OSバンドル)
・Ruby:      1.8.7(Ruby Enterprise Editionを利用)
 ・rack:    1.1.2
 ・rake:    0.9.2
 ・i18n:    0.4.2
・gem:       1.6.2
・Apache:    2.2.15(OSバンドル)
・Passenger: 3.0.11
・Redmine:   1.3.1


Step3. Ruby Enterprise Edition インストール
■OSバンドルのRuby有無確認
[root@redmine ~]# rpm -qa | grep ruby
[root@redmine ~]#
→既存Rubyは存在しないのでOK!


■プロキシ環境対応
[root@redmine ~]# export HTTP_PROXY=http://tanyao:xxxxxxx@proxy.kuitan.net:8080


■インストール
⇒インストール前確認
[root@redmine ~]# ll /usr/local/
合計 40
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 bin
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 etc
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 games
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 include
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 lib
drwxr-xr-x. 3 root root 4096  2月  7 02:22 2012 lib64
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 libexec
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 sbin
drwxr-xr-x. 6 root root 4096  2月  7 02:22 2012 share
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 src
[root@redmine ~]#

⇒解凍&インストール
[root@redmine src]# tar -zxf ruby-enterprise-1.8.7-2012.01.tar.gz
[root@redmine src]# cd ruby-enterprise-1.8.7-2012.01
[root@redmine ruby-enterprise-1.8.7-2012.01]# ./installer --dont-install-useful-gems --no-dev-docs
Welcome to the Ruby Enterprise Edition installer
This installer will help you install Ruby Enterprise Edition 1.8.7-2012.01.
Don't worry, none of your system files will be touched if you don't want them
to, so there is no risk that things will screw up.

You can expect this from the installation process:

  1. Ruby Enterprise Edition will be compiled and optimized for speed for this
     system.
  2. Ruby on Rails will be installed for Ruby Enterprise Edition.
  3. You will learn how to tell Phusion Passenger to use Ruby Enterprise
     Edition instead of regular Ruby.

Press Enter to continue, or Ctrl-C to abort.

Checking for required software...

 * Non-broken C compiler... found at /usr/bin/gcc
 * Non-broken C++ compiler... found at /usr/bin/g++
 * The 'make' tool... found at /usr/bin/make
 * The 'patch' tool... found at /usr/bin/patch
 * Zlib development headers... found
 * OpenSSL development headers... found
 * GNU Readline development headers... found
--------------------------------------------
Target directory

Where would you like to install Ruby Enterprise Edition to?
(All Ruby Enterprise Edition files will be put inside that directory.)

[/opt/ruby-enterprise-1.8.7-2012.01] : /usr/local
--------------------------------------------
Compiling and optimizing the memory allocator for Ruby Enterprise Edition
In the mean time, feel free to grab a cup of coffee.
(中略 約2分)

Ruby Enterprise Edition is successfully installed!
If want to use Phusion Passenger (http://www.modrails.com) in combination
with Ruby Enterprise Edition, then you must reinstall Phusion Passenger against
Ruby Enterprise Edition, as follows:

  /usr/local/bin/passenger-install-apache2-module

Make sure you don't forget to paste the Apache configuration directives that
the installer gives you.


If you ever want to uninstall Ruby Enterprise Edition, simply remove this
directory:

  /usr/local

If you have any questions, feel free to visit our website:

  http://www.rubyenterpriseedition.com

Enjoy Ruby Enterprise Edition, a product of Phusion (www.phusion.nl) :-)
[root@redmine ruby-enterprise-1.8.7-2012.01]#

⇒インストール後
[root@redmine ~]# ll /usr/local/
合計 40
drwxr-xr-x. 2 root root 4096  2月  8 11:38 2012 bin
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 etc
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 games
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 include
drwxr-xr-x. 3 root root 4096  2月  8 11:38 2012 lib
drwxr-xr-x. 3 root root 4096  2月  7 02:22 2012 lib64
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 libexec
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 sbin
drwxr-xr-x. 6 root root 4096  2月  7 02:22 2012 share
drwxr-xr-x. 2 root root 4096  9月 23 20:50 2011 src
[root@redmine ~]#

⇒バージョン確認
[root@redmine ~]# ruby -v
ruby 1.8.7 (2011-12-28 MBARI 8/0x6770 on patchlevel 357) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2012.01


■gemパッケージのインストール
⇒Rack 1.1.2のインストール
[root@redmine ~]# gem install rack -v=1.1.2 --no-rdoc --no-ri
Fetching: rack-1.1.2.gem (100%)
Successfully installed rack-1.1.2
1 gem installed

⇒rake 0.9.2のインストール
[root@redmine ~]# gem install rake -v=0.9.2 --no-rdoc --no-ri
Fetching: rake-0.9.2.gem (100%)
Successfully installed rake-0.9.2
1 gem installed

⇒i18n 0.4.2のインストール
[root@redmine ~]# gem install i18n -v=0.4.2 --no-rdoc --no-ri
Fetching: i18n-0.4.2.gem (100%)
Successfully installed i18n-0.4.2
1 gem installed

⇒RMagickのインストール
[root@redmine ~]# gem install rmagick --no-rdoc --no-ri
Fetching: rmagick-2.13.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rmagick-2.13.1
1 gem installed

⇒RDocのインストール
[root@redmine ~]# gem install rdoc --no-ri --no-rdoc
Fetching: json-1.6.5.gem (100%)
Building native extensions.  This could take a while...
Fetching: rdoc-3.12.gem (100%)
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Successfully installed json-1.6.5
Successfully installed rdoc-3.12
2 gems installed

⇒Ruby用MySQLドライバのインストール
[root@redmine ~]# gem install mysql --no-rdoc --no-ri
Fetching: mysql-2.8.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed

⇒確認
[root@redmine ~]# gem list

*** LOCAL GEMS ***

i18n (0.4.2)
json (1.6.5)
mysql (2.8.1)
rack (1.1.2)
rake (0.9.2)
rdoc (3.12)
rmagick (2.13.1)
[root@redmine ~]#


Step4. Redmine インストール
■インストール(解凍するだけ)
⇒/optに解凍
[root@redmine src]# tar -zxf redmine-1.3.1.tar.gz -C /opt/


■Redmine関連ファイル設定
⇒database.yml作成
[root@redmine src]# cd /opt/redmine-1.3.1/
[root@redmine redmine-1.3.1]# vi config/database.yml
[root@redmine redmine-1.3.1]# cat config/database.yml
production:
  adapter: mysql
  database: db_redmine
  host: localhost
  username: user_redmine
  password: ienaiyo
  encoding: utf8
[root@redmine redmine-1.3.1]#

⇒configuration.ymlの設定
[root@redmine redmine-1.3.1]# cp config/configuration.yml.example config/configuration.yml
[root@redmine redmine-1.3.1]# vi config/configuration.yml
[root@redmine redmine-1.3.1]# tail -11 config/configuration.yml
production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: 'kuitan.net'

# specific configuration options for development environment
# that overrides the default ones
development:
[root@redmine redmine-1.3.1]#

⇒Redmineの初期設定とデータベースのテーブル作成
[root@redmine redmine-1.3.1]# rake generate_session_store
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /opt/redmine-1.3.1/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /opt/redmine-1.3.1/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
(中略)
[root@redmine redmine-1.3.1]#

[root@redmine redmine-1.3.1]# rake db:migrate RAILS_ENV=production
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /opt/redmine-1.3.1/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /opt/redmine-1.3.1/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91.
(中略)
Missing these required gems:
  rubytree  >= 0

You're running:
  ruby 1.8.7.357 at /usr/local/bin/ruby
  rubygems 1.8.15 at /usr/local/lib/ruby/gems/1.8, /root/.gem/ruby/1.8

Run `rake gems:install` to install the missing gems.
[root@redmine redmine-1.3.1]#

[root@redmine redmine-1.3.1]# gem -v
1.8.15
→gemのバージョンが高すぎることが問題のようだ。

⇒gemのバージョンを1.7.1にダウングレード
[root@redmine ~]# gem update --system 1.7.1
Updating rubygems-update
Fetching: rubygems-update-1.7.1.gem (100%)
Successfully installed rubygems-update-1.7.1
Installing RubyGems 1.7.1
RubyGems 1.7.1 installed

=== 1.7.1 / 2011-03-32

* 1 bug fix:
  * Fixed missing file in Manifest.txt.  (Also a bug in hoe was fixed where
    `rake check_manifest` showing a diff would not exit with an error.)


-----------------------------------------------------------------

RubyGems installed the following executables:
        /usr/local/bin/gem

RubyGems system software updated
[root@redmine ~]# gem -v
1.7.1
[root@redmine ~]#

[root@redmine redmine-1.3.1]# rake generate_session_store
NOTE: SourceIndex.new(hash) is deprecated; From /opt/redmine-1.3.1/config/../vendor/rails/railties/lib/rails/vendor_gem_source_index.rb:100:in `new'.
[root@redmine redmine-1.3.1]#
1.7.1でも無理(T-T) 残念…。

⇒1.6.2で再々チャレンジ。
[root@redmine ~]# gem update --system 1.6.2
Updating rubygems-update
Fetching: rubygems-update-1.6.2.gem (100%)
Successfully installed rubygems-update-1.6.2
Installing RubyGems 1.6.2
RubyGems 1.6.2 installed

=== 1.6.2 / 2011-03-08

Bug Fixes:

* require of an activated gem could cause activation conflicts.  Fixes
  Bug #29056 by Dave Verwer.
* `gem outdated` now works with up-to-date prerelease gems.


-----------------------------------------------------------------

RubyGems installed the following executables:
        /usr/local/bin/gem

RubyGems system software updated
[root@redmine ~]# gem -v
1.6.2
[root@redmine ~]#

[root@redmine ~]# rake generate_session_store
[root@redmine ~]#
→成功したっ!!

[root@redmine redmine-1.3.1]# rake db:migrate RAILS_ENV=production
==  Setup: migrating =====================================================
-- create_table("attachments", {:force=>true})
   -> 0.0841s
-- create_table("auth_sources", {:force=>true})
(中略)

-- add_index(:changeset_parents, [:parent_id], {:name=>:changeset_parents_parent_ids, :unique=>false})
   -> 0.1499s
==  CreateChangesetParents: migrated (0.3711s) ===========================

[root@redmine redmine-1.3.1]#
→スキーマ作成完了。

2012年2月14日火曜日

CentOS6.2 Redmine1.3.1構築メモ(1)

CentOS6.2にRedmine1.3.1を構築する手順をまとめてみました。
 Step1. パッケージおよびインストーラの準備
 Step2. MySQLの準備
 Step3. Ruby Enterprise Edition インストール
 Step4. Redmine インストール
 Step5. ApacheにPassenger組込み

■構成情報
・OS:        CentOS6.2(64bit)
・MySQL:     5.1.52(OSバンドル)
・Ruby:      1.8.7(Ruby Enterprise Editionを利用)
 ・rack:    1.1.2
 ・rake:    0.9.2
 ・i18n:    0.4.2
・gem:       1.6.2
・Apache:    2.2.15(OSバンドル)
・Passenger: 3.0.11
・Redmine:   1.3.1


Step1. パッケージおよびインストーラの準備
■Firewall、SELinuxを無効化
[root@redmine ~]# chkconfig iptables off
[root@redmine ~]# chkconfig ip6tables off
[root@redmine ~]# vi /etc/sysconfig/selinux
SELINUX=enforcing
↓ # 変更
SELINUX=disabled

⇒再起動後に確認
[root@redmine ~]# getenforce
Disabled


■作業前ディスク使用状況確認
[root@redmine ~]# df -m
Filesystem           1M-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/vg_redmine-lv_root
                          4607      3253      1120  75% /
tmpfs                      751         1       751   1% /dev/shm
/dev/sda1                  485        33       428   7% /boot
/dev/sr0                  4219      4219         0 100% /media/CentOS_6.2_Final


■インストールメディアからパッケージインストール設定(基本的にはこちらから)
[root@redmine ~]# vi /etc/yum.repos.d/dvdmedia.repo
[root@redmine ~]# cat /etc/yum.repos.d/dvdmedia.repo
[dvdmedia]
name=CentOS-6.2-x86_64-DVD1
baseurl=file:///media/CentOS_6.2_Final/
enabled=0
gpgcheck=1
gpgkey=file:///media/CentOS_6.2_Final/RPM-GPG-KEY-CentOS-6
[root@redmine ~]#


■yumのproxy越え設定(インストールメディアにない場合は最新バージョンを採用)
[root@redmine ~]# vi /etc/yum.conf
[root@redmine ~]# tail -5 /etc/yum.conf
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

# Add Proxy
proxy=http://tanyao:xxxxxxxx@proxy.kuitan.net:8080/
[root@redmine ~]#
⇒最下行に上記2行を追記


■関連パッケージの確認
[root@redmine ~]# rpm -q openssl-devel readline-devel zlib-devel curl-devel
パッケージ openssl-devel はインストールされていません。
パッケージ readline-devel はインストールされていません。
パッケージ zlib-devel はインストールされていません。
パッケージ curl-devel はインストールされていません。
[root@redmine ~]# rpm -q mysql mysql-server mysql-devel
mysql-5.1.52-1.el6_0.1.x86_64
mysql-server-5.1.52-1.el6_0.1.x86_64
パッケージ mysql-devel はインストールされていません。
[root@redmine ~]# rpm -q httpd httpd-devel
httpd-2.2.15-15.el6.centos.x86_64
パッケージ httpd-devel はインストールされていません。
[root@redmine ~]# rpm -q ImageMagick ImageMagick-devel
パッケージ ImageMagick はインストールされていません。
パッケージ ImageMagick-devel はインストールされていません。
[root@redmine ~]#

⇒念のため開発ツール関係のパッケージも
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia groupinstall "Development Tools"
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
dvdmedia                                                     | 4.0 kB     00:00 ...
dvdmedia/primary_db                                          | 4.5 MB     00:00 ...
(中略)

No packages in any requested group available to install or update
[root@redmine ~]#


■関連パッケージのインストール
⇒openssl-devel
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install openssl-devel
(中略)
Installed:
  openssl-devel.x86_64 0:1.0.0-20.el6

Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.4-3.el6         krb5-devel.x86_64 0:1.9-22.el6
  libcom_err-devel.x86_64 0:1.41.12-11.el6       libselinux-devel.x86_64 0:2.0.94-5.2.el6
  libsepol-devel.x86_64 0:2.0.41-4.el6           zlib-devel.x86_64 0:1.2.3-27.el6

Complete!
[root@redmine ~]#
→zlib-develも同時にインストールされた。

⇒readline-devel
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install readline-devel
(中略)
Installed:
  readline-devel.x86_64 0:6.0-3.el6

Dependency Installed:
  ncurses-devel.x86_64 0:5.7-3.20090208.el6

Complete!
[root@redmine ~]#

⇒curl-devel
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install curl-devel
(中略)
Installed:
  libcurl-devel.x86_64 0:7.19.7-26.el6_1.2

Dependency Installed:
  libidn-devel.x86_64 0:1.18-2.el6

Complete!
[root@redmine ~]#

⇒mysql-devel
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install mysql-devel
(中略)
Installed:
  mysql-devel.x86_64 0:5.1.52-1.el6_0.1

Complete!
[root@redmine ~]#

⇒httpd-devel
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install httpd-devel
(中略)
Installed:
  httpd-devel.x86_64 0:2.2.15-15.el6.centos

Dependency Installed:
  apr-devel.x86_64 0:1.3.9-3.el6_1.2    apr-util-devel.x86_64 0:1.3.9-3.el6_0.1 cyrus-sasl-devel.x86_64 0:2.1.23-13.el6
  db4-cxx.x86_64 0:4.7.25-16.el6        db4-devel.x86_64 0:4.7.25-16.el6        expat-devel.x86_64 0:2.0.1-9.1.el6
  openldap-devel.x86_64 0:2.4.23-20.el6

Complete!
[root@redmine ~]#

⇒ImageMagick
[root@redmine ~]# yum --disablerepo=\* --enablerepo=dvdmedia install ImageMagick
(中略)
Installed:
  ImageMagick.x86_64 0:6.5.4.7-5.el6

Dependency Installed:
  libwmf-lite.x86_64 0:0.2.8.4-22.el6.centos

Complete!
[root@redmine ~]#

⇒ImageMagick-devel(依存パッケージがインストールメディアに全部は無い)
[root@redmine ~]# yum install ImageMagick-devel
(中略)

Installed:
  ImageMagick-devel.x86_64 0:6.5.4.7-5.el6

Dependency Installed:
  bzip2-devel.x86_64 0:1.0.5-7.el6_0                  freetype-devel.x86_64 0:2.3.11-6.el6_1.8
  ghostscript-devel.x86_64 0:8.70-11.el6_1.2          jasper-devel.x86_64 0:1.900.1-15.el6_1.1
  lcms-devel.x86_64 0:1.19-1.el6                      libICE-devel.x86_64 0:1.0.6-1.el6
  libSM-devel.x86_64 0:1.1.0-7.1.el6                  libX11-devel.x86_64 0:1.3-2.el6
  libXau-devel.x86_64 0:1.0.5-1.el6                   libXdmcp-devel.x86_64 0:1.0.3-1.el6
  libXext-devel.x86_64 0:1.1-3.el6                    libXt-devel.x86_64 0:1.0.7-1.el6
  libjpeg-devel.x86_64 0:6b-46.el6                    libtiff-devel.x86_64 0:3.9.4-1.el6_0.3
  libxcb-devel.x86_64 0:1.5-1.el6                     xorg-x11-proto-devel.noarch 0:7.6-13.el6

Dependency Updated:
  freetype.x86_64 0:2.3.11-6.el6_1.8                  jasper-libs.x86_64 0:1.900.1-15.el6_1.1

Complete!
[root@redmine ~]#


■インストーラダウンロード
⇒Ruby Enterprise Edition
サイト: http://www.rubyenterpriseedition.com/download.html
ファイル: ruby-enterprise-1.8.7-2012.01.tar.gz(約7.5MB)

⇒Redmine1.3
サイト: http://rubyforge.org/frs/?group_id=1850
ファイル: redmine-1.3.1.tar.gz(約5.7MB)

⇒インストーラ格納用ディレクトリを作成しFTP等でサーバにUP
[root@redmine ~]# mkdir /root/src
[root@redmine ~]# ll /root/src/
合計 13632
-rwxr--r-- 1 root root 6034718  2月  7 18:41 2012 redmine-1.3.1.tar.gz
-rwxr--r-- 1 root root 7918155  2月  7 18:41 2012 ruby-enterprise-1.8.7-2012.01.tar.gz
[root@redmine ~]#


Step2. MySQLの準備
■データベース初期化
[root@redmine ~]# /etc/init.d/mysqld start
MySQL データベースを初期化中:  WARNING: The host 'redmine' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
(中略)

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]
[root@redmine ~]#
[root@redmine ~]# mysqlshow
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
[root@redmine ~]#


■自動起動設定
[root@redmine ~]# chkconfig mysqld on
[root@redmine ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@redmine ~]#


■MySQLのデフォルトキャラクタセットをutf8に設定
[root@redmine ~]# cp -p /etc/my.cnf /etc/my.cnf.20110625
[root@redmine ~]# vi /etc/my.cnf
[root@redmine ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# for redmine        ←追記
character-set-server=utf8 ←追記

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# for redmine         ←追記
[mysql]            ←追記
default-character-set=utf8 ←追記
[root@redmine ~]#

⇒再起動して設定反映
[root@redmine ~]# /etc/init.d/mysqld restart
mysqld を停止中:                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]

⇒キャラクタセット設定確認
[root@redmine ~]# mysql -u root -e "show variables like 'character_set%';"
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
[root@redmine ~]#


■Redmine用データベース準備
⇒匿名ユーザー削除
[root@redmine ~]# mysql -u root

mysql> use mysql
Database changed
mysql> delete from user where user = '';
Query OK, 2 rows affected (0.00 sec)

mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

⇒Redmine用データベースとユーザーの作成
mysql> create database db_redmine default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on db_redmine.* to user_redmine identified by 'ienaiyo';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
[root@redmine ~]#

2012年2月13日月曜日

CentOS 6.2 LVMのディスクサイズ拡張

パーティション構成にLVMが使用されている場合の手順です。 LVMを使用せず、物理ディスクにパーティションが直接マッピングされている場合等は、 GPartedで拡張するのがおすすめですが、そのネタはまた次回。
・LinuxサーバOS: CentOS6.2 (64-bit)
・ホスト名: srv04

■vSphereClientからESXi上の仮想マシンのディスクサイズ拡張
仮想マシンsrv04をシャットダウン
ハードディスク1を16GB→30GBに設定 ■事前状況確認 [root@srv04 ~]# df -h Filesystem Size Used Avail Use% マウント位置 /dev/mapper/vg_srv04-lv_root 14G 3.5G 9.2G 28% / tmpfs 499M 88K 499M 1% /dev/shm /dev/sda1 485M 48M 412M 11% /boot [root@srv04 ~]# fdisk -l ディスク /dev/sda: 32.2 GB, 32212254720 バイト ヘッド 64, セクタ 32, シリンダ 30720 Units = シリンダ数 of 2048 * 512 = 1048576 バイト セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O size (minimum/optimal): 512 bytes / 512 bytes ディスク識別子: 0x000ce9dd デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2 501 512000 83 Linux パーティション 1 は、シリンダ境界で終わっていません。 /dev/sda2 502 16384 16264192 8e Linux LVM パーティション 2 は、シリンダ境界で終わっていません。 ディスク /dev/mapper/vg_srv04-lv_root: 14.5 GB, 14537457664 バイト ヘッド 255, セクタ 63, シリンダ 1767 Units = シリンダ数 of 16065 * 512 = 8225280 バイト セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O size (minimum/optimal): 512 bytes / 512 bytes ディスク識別子: 0x00000000 ディスク /dev/mapper/vg_srv04-lv_root は正常なパーティションテーブルを含んでいません ディスク /dev/mapper/vg_srv04-lv_swap: 2113 MB, 2113929216 バイト ヘッド 255, セクタ 63, シリンダ 257 Units = シリンダ数 of 16065 * 512 = 8225280 バイト セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O size (minimum/optimal): 512 bytes / 512 bytes ディスク識別子: 0x00000000 ディスク /dev/mapper/vg_srv04-lv_swap は正常なパーティションテーブルを含んでいません [root@srv04 ~]# ■一旦、拡張領域に新規パーティションを作成 [root@srv04 ~]# fdisk /dev/sda 警告: DOS互換モードは廃止予定です。このモード (コマンド 'c') を止めることを 強く推奨します。 and change display units to sectors (command 'u'). コマンド (m でヘルプ): m コマンドの動作 a ブート可能フラグをつける b bsd ディスクラベルを編集する c dos 互換フラグをつける d 領域を削除する l 既知の領域タイプをリスト表示する m このメニューを表示する n 新たに領域を作成する o 新たに空の DOS 領域テーブルを作成する p 領域テーブルを表示する q 変更を保存せずに終了する s 空の Sun ディスクラベルを作成する t 領域のシステム ID を変更する u 表示/項目ユニットを変更する v 領域テーブルを照合する w テーブルをディスクに書き込み、終了する x 特別な機能 (エキスパート専用) コマンド (m でヘルプ): p ディスク /dev/sda: 32.2 GB, 32212254720 バイト ヘッド 64, セクタ 32, シリンダ 30720 Units = シリンダ数 of 2048 * 512 = 1048576 バイト セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O size (minimum/optimal): 512 bytes / 512 bytes ディスク識別子: 0x000ce9dd デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2 501 512000 83 Linux パーティション 1 は、シリンダ境界で終わっていません。 /dev/sda2 502 16384 16264192 8e Linux LVM パーティション 2 は、シリンダ境界で終わっていません。 コマンド (m でヘルプ): n コマンドアクション e 拡張 p 基本パーティション (1-4) p パーティション番号 (1-4): 3 最初 シリンダ (1-30720, 初期値 1): 16385 Last シリンダ, +シリンダ数 or +size{K,M,G} (16385-30720, 初期値 30720): 30720 コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 警告: パーティションテーブルの再読込みがエラー 16 で失敗しました: デバイスもしくはリソースがビジー状態です。 カーネルはまだ古いテーブルを使っています。新しいテーブルは 次回リブート時か、partprobe(8)またはkpartx(8)を実行した後に 使えるようになるでしょう ディスクを同期しています。 [root@srv04 ~]# reboot →シリンダ境界で終わっていないというメッセージが出ているので、追加パーティション のシリンダの初期値を/dev/sda2の値(16384)の次の値とした。 ⇒再起動後にパーティションを確認すると/dev/sda3が作成されている。 [root@redmine ~]# fdisk -l ディスク /dev/sda: 32.2 GB, 32212254720 バイト ヘッド 64, セクタ 32, シリンダ 30720 Units = シリンダ数 of 2048 * 512 = 1048576 バイト セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O size (minimum/optimal): 512 bytes / 512 bytes ディスク識別子: 0x000ce9dd デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2 501 512000 83 Linux パーティション 1 は、シリンダ境界で終わっていません。 /dev/sda2 502 16384 16264192 8e Linux LVM パーティション 2 は、シリンダ境界で終わっていません。 /dev/sda3 16385 30720 14680064 83 Linux ディスク /dev/mapper/vg_srv04-lv_root: 14.5 GB, 14537457664 バイト (後略) ■/dev/sda3を元にPhysical Volumeを作り、Volume Group(vg_srv04)に追加 [root@srv04 ~]# pvcreate /dev/sda3 Writing physical volume data to disk "/dev/sda3" Physical volume "/dev/sda3" successfully created [root@srv04 ~]# vgextend vg_srv04 /dev/sda3 Volume group "vg_srv04" successfully extended [root@srv04 ~]# ⇒論理ボリュームに割り当てられるエクステントの個数(Free PEの値)を調べる [root@srv04 ~]# vgdisplay -v Finding all volume groups Finding volume group "vg_srv04" --- Volume group --- VG Name vg_srv04 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 29.50 GiB PE Size 4.00 MiB Total PE 7553 Alloc PE / Size 3970 / 15.51 GiB Free PE / Size 3583 / 14.00 GiB ←ここに注目! VG UUID oJIJHr-uD5d-ZXni-aAEm-nnZd-foA0-5XZvPD --- Logical volume --- LV Name /dev/vg_srv04/lv_root VG Name vg_srv04 LV UUID Siwck8-f0lb-zD8E-8Gdt-a5tH-7Ilq-a1wuqn LV Write Access read/write LV Status available # open 1 LV Size 13.54 GiB Current LE 3466 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/vg_srv04/lv_swap VG Name vg_srv04 LV UUID xZ92Cs-uPmf-rerw-oEBH-068n-rKAQ-f4wA5y LV Write Access read/write LV Status available # open 1 LV Size 1.97 GiB Current LE 504 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Physical volumes --- PV Name /dev/sda2 PV UUID v0cw4G-58Tk-Earn-p4xC-tMch-jkmZ-Pk5SDP PV Status allocatable Total PE / Free PE 3970 / 0 PV Name /dev/sda3 PV UUID xja5iK-Bzdh-FL01-dSda-wY8w-kWEQ-VNOZrS PV Status allocatable Total PE / Free PE 3583 / 3583 [root@srv04 ~]# ■Volume Group(vg_srv04)のLogical Volume(lv_root)を拡張 ⇒エクステント数を指定して論理ボリューム拡大 [root@srv04 ~]# lvextend -l +3583 /dev/vg_srv04/lv_root Extending logical volume lv_root to 27.54 GiB Logical volume lv_root successfully resized [root@srv04 ~]# ⇒resize2fsを実行(拡張サイズが大きいほど時間がかかる) [root@srv04 ~]# resize2fs /dev/vg_srv04/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_srv04/lv_root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2 Performing an on-line resize of /dev/vg_srv04/lv_root to 7218176 (4k) blocks. The filesystem on /dev/vg_srv04/lv_root is now 7218176 blocks long. [root@srv04 ~]#

■拡張完了
[root@srv04 ~]# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/vg_srv04-lv_root
                       28G  3.5G   23G  14% /
tmpfs                 499M   88K  499M   1% /dev/shm
/dev/sda1             485M   48M  412M  11% /boot
[root@srv04 ~]#