Archive for: 𔃸月 2015’

Redmine2.1.2からRedmine3.1.0へのDB移行時のエラー

2015年8月24日 Posted by PURGE

Mysqlのダンプファイルをインポートしようとしたが、Redmineがサーバエラーを起こしていたので覚え書き。

データダンプファイルを新規のDBに移行し、新たにマイグレーション。

$ mysql redmine_db < Dmpfile.sql
$ rake db:migrate RAILS_ENV=production

エラーログを見るとマイグレーションで失敗していたようなので、下記のテーブル群が件数0件であることを確認してDROP。

drop table custom_fields_roles;
drop table queries_roles;
drop table email_addresses;
drop table roles_managed_roles;

その後も下記エラーとなったが、Redmineのサーバを再起動したら直った。

Mysql2::Error: Unknown column 'users.mail'

Redmineのファイルバックアップスクリプト

2015年8月14日 Posted by PURGE

特にエラーハンドリングしていないが、覚え書きで。

#!/bin/sh
#
# Redmine DB backup script

FILE_DIR=/app/redmine/files/
DMP_DIR=/var/tmp/
MNT_DIR=/mnt/svn/
BAK_DIR="//10.10.10.10/windows/Backup/server/dir"
PERIOD=5
DB_USER=user
DB_PASS=pass

USER_NAME=winuser
PASSWD=winpass
EXIT_STATUS=0

FILE_NAME=`date +%y%m%d`
RM_FILE_NAME=`date --date "$PERIOD days ago" +%y%m%d`

DMP_FILE=$DMP_DIR/Redmine_DB_$FILE_NAME.sql.gz
ARC_FILE=$DMP_DIR/Redmine_FILE_$FILE_NAME.tar.gz

RM_DMP_FILE=$MNT_DIR/Redmine_DB_$RM_FILE_NAME.sql.gz
RM_ARC_FILE=$MNT_DIR/Redmine_FILE_$RM_FILE_NAME.tar.gz

# ファイルサーバへマウント
mount -t cifs -o username=$USER_NAME,password=$PASSWD $BAK_DIR $MNT_DIR

# データのダンプ
mysqldump --opt --single-transaction --default-character-set=binary -u $DB_USER --password=$DB_PASS --all-databases | gzip > $DMP_FILE

# 添付ファイルのアーカイブ
tar cfvz $ARC_FILE $FILE_DIR

# ファイルの移動
mv $DMP_FILE $MNT_DIR
mv $ARC_FILE $MNT_DIR

# ファイルの削除
rm $RM_DMP_FILE
rm $RM_ARC_FILE
echo "Redmine Backup OK"

umount -l $MNT_DIR

exit $EXIT_STATUS

gem install mysql2 インストールエラー

2015年8月14日 Posted by PURGE

対象環境

  • CentOS 6.7
  • Ruby2.1
  • Rails4.1
  • MySQL Community Server 5.6.26

概要

Redmineをインストールするにあたって、MySQLをインストールし、Railsで使用するライブラリmysql2のインストールでエラーとなる。

$ gem install mysql2 -v '0.3.19'
Fetching: mysql2-0.3.19.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    /usr/local/ruby2.2/bin/ruby -r ./siteconf20150814-32250-1l3iwxf.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. Try 'apt-get install libmysqlclient-dev' or
'yum install mysql-devel', check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/ruby2.2/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config

extconf failed, exit code 1

Windows環境でハマった時の対応方法は、この記事であるが、今回の環境はまた異なるし、対応方法が異なるようだ。

そこで下記`mysql-devel`をインストール。

$ yum install mysql-devel
読み込んだプラグイン:fastestmirror, security
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: centos.usonyx.net
パッケージ mysql-devel は mysql-community-devel によって不要になりました。代わりに mysql-community-devel-5.6.26-2.el6.x86_64 のインストールを試みています。
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package mysql-community-devel.x86_64 0:5.6.26-2.el6 will be インストール
--> 依存性解決を終了しました。

依存性を解決しました

====================================================================================================
 パッケージ                    アーキテクチャ バージョン            リポジトリー               容量
====================================================================================================
インストールしています:
 mysql-community-devel         x86_64         5.6.26-2.el6          mysql56-community         3.2 M

トランザクションの要約
====================================================================================================
インストール         1 パッケージ

総ダウンロード容量: 3.2 M
インストール済み容量: 20 M
これでいいですか? [y/N]y
パッケージをダウンロードしています:
mysql-community-devel-5.6.26-2.el6.x86_64.rpm                                | 3.2 MB     00:01
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
  インストールしています  : mysql-community-devel-5.6.26-2.el6.x86_64                           1/1
  Verifying               : mysql-community-devel-5.6.26-2.el6.x86_64                           1/1

インストール:
  mysql-community-devel.x86_64 0:5.6.26-2.el6

完了しました!

再度、試したら上手く行った。

$ gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.19
Parsing documentation for mysql2-0.3.19
Installing ri documentation for mysql2-0.3.19
Done installing documentation for mysql2 after 1 seconds
1 gem installed

gemでのインストールエラー

2015年8月12日 Posted by PURGE

bundlerのインストール

社内プロキシの関係でインストールできない場合がある

$ gem install bundler --no-rdoc --no-ri -p http://user:password@proxy:8080
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ 
          - no such name (https://rubygems.org/specs.4.8.gz)

社内プロキシの関係でインストールできない場合は、ローカルにダウンロードしてインストールする。

$ gem install --local /usr/local/src/bundler-1.10.6.gem
Successfully installed bundler-1.10.6
Parsing documentation for bundler-1.10.6
Installing ri documentation for bundler-1.10.6
Done installing documentation for bundler after 7 seconds
1 gem installed

但し、インストール対象に依存関係がある場合は面倒くさい。

Ruby2.2.2のソースコードからのインストール

2015年8月12日 Posted by PURGE

いまどき、Rubyのインストール等は、rbenv等を使用するのが普通だが、必要があって直接ソースコンパイルしてRubyのインストールしてみた。

Rubyのダウンロード

$ curl -O https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
$ mv ruby-2.2.2.tar.gz /usr/local/src/

Rubyの解凍&インストール

$ tar xvf ruby-2.2.2.tar.gz
$ cd ruby-2.2.2
$ ./configure --prefix=/usr/local/ruby2.2/ --disable-install-doc
$ make
$ make install

Rubyインストール場所の確認

$ ls /usr/local/ruby2.2

Rubyをパスに追加

$ vi /etc/skel/.bash_profile
$ vi ~/.bash_profile
RUBY_HOME=/usr/local/ruby2.2
PATH=$PATH:$RUBY_HOME/bin

Rubyの確認

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

CentOS6.7へのMySQL5.6のインストール方法

2015年8月10日 Posted by PURGE

久しぶりにMySQLのインストール。
この手の設定は、2年に一度くらいしかしないので覚え書き。

OS : CentOS6.7

そういえば、前回は、CentOS 5.8にMySQL5.5 をインストールしていた。
しかも yum ではなくrpmで・・・。懐かしい。

そのままで、yum install してもインストールされる対象は、MySQL5.1の為、MySQL5.6にしたい。

yum install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

パッケージ情報の確認

yum infoで、インストールするパッケージの情報を表示する

yum info mysql-community-server
読み込んだプラグイン:fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: centos.usonyx.net
 * extras: ftp.iij.ad.jp
 * updates: centos.usonyx.net
利用可能なパッケージ
名前                : mysql-community-server
アーキテクチャ      : x86_64
バージョン          : 5.6.26
リリース            : 2.el6
容量                : 53 M
リポジトリー        : mysql56-community
要約                : A very fast and reliable SQL database server
...

インストール

上記で調べた利用可能なパッケージ名を指定してインストールする。

$ yum install mysql-community-server
読み込んだプラグイン:fastestmirror, security
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: centos.usonyx.net
 * extras: ftp.iij.ad.jp
 * updates: centos.usonyx.net
依存性の解決をしています

...

依存性を解決しました

====================================================================================================
 パッケージ                        アーキテクチャ
                                                バージョン            リポジトリー             容量
====================================================================================================
インストールしています:
 mysql-community-libs              x86_64       5.6.26-2.el6          mysql56-community       1.9 M
     置き換えています  mysql-libs.x86_64 5.1.73-5.el6_6
 mysql-community-libs-compat       x86_64       5.6.26-2.el6          mysql56-community       1.6 M
     置き換えています  mysql-libs.x86_64 5.1.73-5.el6_6
 mysql-community-server            x86_64       5.6.26-2.el6          mysql56-community        53 M
依存性関連でのインストールをします。:
 mysql-community-client            x86_64       5.6.26-2.el6          mysql56-community        18 M
 mysql-community-common            x86_64       5.6.26-2.el6          mysql56-community       307 k
 perl-DBI                          x86_64       1.609-4.el6           base                    705 k

トランザクションの要約
====================================================================================================
インストール         6 パッケージ

総ダウンロード容量: 75 M
これでいいですか? [y/N]
パッケージをダウンロードしています:
(1/6): mysql-community-client-5.6.26-2.el6.x86_64.rpm                        |  18 MB     00:05
(2/6): mysql-community-common-5.6.26-2.el6.x86_64.rpm                        | 307 kB     00:00
(3/6): mysql-community-libs-5.6.26-2.el6.x86_64.rpm                          | 1.9 MB     00:00
(4/6): mysql-community-libs-compat-5.6.26-2.el6.x86_64.rpm                   | 1.6 MB     00:00
(5/6): mysql-community-server-5.6.26-2.el6.x86_64.rpm                        |  53 MB     00:12
(6/6): perl-DBI-1.609-4.el6.x86_64.rpm                                       | 705 kB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                3.9 MB/s |  75 MB     00:19

...

これでいいですか? [y/N]y
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
  インストールしています  : mysql-community-common-5.6.26-2.el6.x86_64                          1/7
  インストールしています  : mysql-community-libs-5.6.26-2.el6.x86_64                            2/7
  インストールしています  : mysql-community-client-5.6.26-2.el6.x86_64                          3/7
  インストールしています  : perl-DBI-1.609-4.el6.x86_64                                         4/7
  インストールしています  : mysql-community-server-5.6.26-2.el6.x86_64                          5/7
  インストールしています  : mysql-community-libs-compat-5.6.26-2.el6.x86_64                     6/7
  削除中                  : mysql-libs-5.1.73-5.el6_6.x86_64                                    7/7
  Verifying               : mysql-community-common-5.6.26-2.el6.x86_64                          1/7
  Verifying               : perl-DBI-1.609-4.el6.x86_64                                         2/7
  Verifying               : mysql-community-libs-5.6.26-2.el6.x86_64                            3/7
  Verifying               : mysql-community-server-5.6.26-2.el6.x86_64                          4/7
  Verifying               : mysql-community-client-5.6.26-2.el6.x86_64                          5/7
  Verifying               : mysql-community-libs-compat-5.6.26-2.el6.x86_64                     6/7
  Verifying               : mysql-libs-5.1.73-5.el6_6.x86_64                                    7/7

インストール:
  mysql-community-libs.x86_64 0:5.6.26-2.el6     mysql-community-libs-compat.x86_64 0:5.6.26-2.el6
  mysql-community-server.x86_64 0:5.6.26-2.el6

依存性関連をインストールしました:
  mysql-community-client.x86_64 0:5.6.26-2.el6     mysql-community-common.x86_64 0:5.6.26-2.el6
  perl-DBI.x86_64 0:1.609-4.el6

置換:
  mysql-libs.x86_64 0:5.1.73-5.el6_6

完了しました!

インストールしたMySQLのバージョンの確認

$ mysqld --version
 mysqld  Ver 5.6.26 for Linux on x86_64 (MySQL Community Server (GPL))

自動起動の設定

インストール後は、自動起動がoffになっているので、自動起動するように設定する。

$ chkconfig mysqld --list
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
$ chkconfig mysqld on
$ chkconfig mysqld --list
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

MySQLの起動

$ service mysqld start
MySQL データベースを初期化中:  2015-08-10 14:06:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-08-10 14:06:31 0 [Note] /usr/sbin/mysqld (mysqld 5.6.26) starting as process 24192 ...
2015-08-10 14:06:31 24192 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-08-10 14:06:31 24192 [Note] InnoDB: The InnoDB memory heap is disabled

a new database to be created!

...
                                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]

rootパスワードの変更

$ /usr/bin/mysqladmin -u root password 'new-password'

デフォルト文字コードの変更

デフォルトでは、文字コードが下記のようになっている。

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

そこで、/etc/my.cnf の設定に追記する。

[mysqld]
character-set-server=utf8

[mysql]
default-character-set=utf8

MySQLサーバの再起動。

$ service mysqld restart

デフォルト文字コードの設定の確認をする。

mysql> 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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

latin1 であった部分が utf8 に変更された。

CentOSのバージョンの調べ方

2015年8月10日 Posted by PURGE

$ cat /etc/redhat-release
$ cat /proc/version