nginx上で動作するPukiWikiにおいて、何故かPOST(更新/プレビュー)が失敗する場合…

client_body_buffer_size と、
client_max_body_size のパラメータがあやしい。
いったん 100M とかにしてみる?

コメントする

Percona XtraBackupを使ってMySQL InnoDB Hot Backup

ホットバックアップとは・・・DBを停止せずとも、起動状態のままでバックアップが完了する仕組み。

とりあえず、MySQLにはデフォルトでmysqldumpという仕組みがあるが、これだとmysqldを停止した状態でしかバックアップがとれない。

よって、サードパーティのPercona XtraBackupという製品を使ってみる。無料。
(MySQLが公式で出しているInnoDB HotBackupは有償)

1. perconaのレポジトリを追加

yumで入れる前提で。
64bit

rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm

32bitもありますが省略

2. インストール

yum install xtrabackup

(注意! XtraBackupの現在の最新版2.1では、MySQL5.1xに対応していない。
その場合、2.0を明示的に指定してインストールする。xtrabackup20)

3. セットアップ

自分の場合、リモートにあるEC2インスタンスにバックアップしたかった。
なので、XtraBackupとは直接関係ないが、ssh-keygenで送る側に秘密鍵を作り、送られる側のauthorized_keysに公開鍵を書いた。
これで、sshコマンドを使ったパイプ形式でリモートにバックアップファイルをリアルタイム送信することができる。
(XtraBackup 1.xのころはどうやらremote-hostというオプションがあったようだが、今は廃止されている)

4. 実行

/usr/bin/innobackupex --stream=tar ./ | ssh -p (sshのポート番号)  -i (秘密鍵のパス) (バックアップ先ユーザー名)@(バックアップ先ドメイン) "cat - > (リモートのバックアップ先ディレクトリ)backup.tar"

これはFull Backupなので、2回目移行は差分バックアップに切り替える。

参考リンク:
Percona Xtrabackup – Documentation — Percona XtraBackup Documentation
Percona XtraBackupの基本的な使い方 | 外道父の匠
XtraBackupを使ってMySQLをバックアップしよう | さぶみっと!JAPAN

今後の参考:
xtrabackupをちょっと便利に使う – かみぽわーる
Doc – How to use XtraBackup ちょっと旧い、1.x系

コメントする

RailsのDeviseで、メール認証完了時にデフォルトとは違うURLへ転送するための設定

いじるべきファイル

  • /config/routes.rb
  • /app/controllers/registrations_controller.rb
  • (新規作成) /app/controllers/confirmations_controller.rb

1. (registrations_controller.rb)と(confirmations_controller.rb)で元々のコントローラを継承し上書きする。

(registrations_controller.rb) 最後のほうに追加

def after_sign_up_path_for(resource)
users_success_path
end
def after_inactive_sign_up_path_for(resource)
users_checkmail_path
end

(confirmations_controller.rb)

class ConfirmationsController < Devise::ConfirmationsController
protected

def after_confirmation_path_for(resource_name, resource)
users_success_path
end
end

2. (routes.rb)に定義を追加する。

devise_for :users, :controllers =>{:registrations => “registrations”}

devise_for :users, :controllers =>{:registrations => “registrations”,:confirmations => “confirmations”}

さらにその下あたりに以下2行を追加

get “users/success”     (最終的な登録完了の画面)
get “users/checkmail”     (メール認証を依頼する画面)

3. 登録完了画面とメール認証依頼画面を/app/viewsに登録する

さっきroutes.rbに追加したパスの場所にerbを作る

  • /app/views/users/checkmail.html.erb
  • /app/views/users/success.html.erb

これでOK。

参考:

Deviseの遷移先をカスタマイズする [俺の備忘録]
devise でアクションの完了後に移動するパスをカスタマイズしたい | yukku++
Deviseを使ったRailsアプリで遷移先(ルート)を設定する – テクノロジーと広義のデザイン!

コメントする

公開鍵認証にする手順についておさらい

1. ローカル環境でssh-keygenを使い鍵ペアを作る

ssh-keygen -t rsa -f ファイル名

↑の場合、RSA鍵になる。標準的な形式なのでそれでいい。DSAとかもある。
作るとき鍵パスワードを聞かれるが、あってもなくてもいい。あったほうが、万が一鍵が流出した際には良いかもしれない。

2. リモート環境

2-1. ログインしたいユーザーのホームディレクトリに.sshディレクトリがあるか確認する

なければ作る。パーミッションはそのままでいい。

2-2. 中にauthorized_keysという名前のファイルを作り、中にローカルで作った鍵ペアのうち拡張子が.pubとなっているほうの中身をコピペする。

authorized_keysはデフォルト値であり、/etc/ssh/sshd_configを書き換えている場合はこの限りではない。

2-3. /etc/ssh/sshd_configを編集し、パスワードログイン機能を無効化する。

PasswordAuthentication no

これにより、完全に鍵認証でしかログインできないようにする。

これでOK。

コメントする

Amazon EC2でCentOS 6.3をセットアップする(1)

起動時のAMIにはCentOS公式の6.3 Release Mediaを使った。
EC2でインスタンスを起動するところは割愛します。

まずログインすると以下のようなことを聞かれる。

The authenticity of host 'xx.xxx.xxx.xxx (xx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is xxx
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xx.xxx.xxx.xxx' (RSA) to the list of known hosts.

known_hostsに接続情報の記録がないことが原因で、これは初回接続だから。
yesを押せば2回目からは問題なし。

基本設定

ルートEBSボリュームの拡張を反映

例え起動時にStorage Device ConfigulationからルートEBSボリュームの容量を拡張していても、OSのほうには反映されていない。AMIのデフォルト容量が適用されている。

なので、以下のコマンドでルートボリュームのラベルを確認。

[root@ ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde             7.9G  621M  6.9G   9% /
tmpfs                 296M     0  296M   0% /dev/shm

xvde となっている。これを、resize2fs。

[root@ ~]# resize2fs /dev/xvde
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvde is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/xvde to 7864320 (4k) blocks.
The filesystem on /dev/xvde is now 7864320 blocks long.

変更が反映されたことを確認。

[root@ ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde              30G  625M   28G   3% /
tmpfs                 296M     0  296M   0% /dev/shm

無事に30GBと認識された。

SELinuxを無効にする

挙動が非常に難解なセキュリティ機構であるため、無効にするのが半ば常態化している(と思う)。
しかし、だからといって無効にしていい理由にはならないので、慎重に。EC2で言えばSecurity Group設定の確認とか。。。

[root@ ~]# sed -e 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

再起動

SELinuxの設定変更は再起動しないと反映されないため、いったん再起動。

日本時間にする

[root@ ~]# cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
cp: overwrite `/etc/localtime'? y

SSHをパスワード不要にする

公開鍵認証を使うので、パスワードは不要。

[root@ ~]# sed -e 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config

ここでおもむろにyum update

[root@ ~]# yum -y update

yum groupinstallでBaseとDevelopment Toolsをインストール

これはかなり色々なツールがインストールされる。
中には使わないものもたくさん混じっているので、やるかどうかは好みによると思う。
ただ、何もしないとwgetやperlやmake等、入っていて当然に思いがちな物も一つずつインストールすることになってしまうので、いっそパッケージごと入れてしまう。

[root@ ~]# yum -y groupinstall "Base"
[root@ ~]# yum -y groupinstall "Development Tools"

yum-cronをインストール

一定周期でyum updateを自動でやってくれる。
デフォルト設定だと、インストールまで全自動だが、それだとアプリが動かなくなったりするかもしれない怖い、という場合はパッケージダウンロードだけに留めることもできる。

[root@ ~]# yum -y install yum-cron
[root@ ~]# service yum-cron start
[root@ ~]# chkconfig yum-cron on

とりあえずここまでやったら、EC2でCreate AMIして状態をSnapshot化しておく。
ここからは、Chef経由で環境セットアップを行う。
続きはまた次エントリーで書きます。

コメントする

brew updateしようとしたらgit commitしろと怒られた

Owner$ brew update
error: Your local changes to the following files would be overwritten by merge:
    Library/Formula/imagemagick.rb
Please, commit your changes or stash them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

前のエントリーでImageMagickのFormulaをいじった件をgit commit -aしないとダメっぽい。

Formulaが保存されているディレクトリへ移動。

cd /usr/local/Library/Formula

続いて、gitにコミット。

git commit -a -m 'ImageMagick Formula Update'

この後brew updateしたらうまくいった。

でもなんかその前にマージ関係のメッセージが出たんだけど勢い余ってZZしちゃいました(vim)

コメントする

Rails3.2.11でRmagickを使おうとしてエラー->解決->本末転倒

プロジェクト活動中だけどメモ。

Rails側のファイルアップロードシステムにはCarrierWaveが使われていて、自分はそこにjQuery File Uploadを使ってファイルを送信したい思った。

そのサンプルプログラムとしてn0ne/Rails-Carrierwave-jQuery-File-Upload · GitHubというものを発見し、動作を参考にするためとりあえずbundle installしようとしたらエラーが出た。

An error occurred while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.

画像操作ライブラリImageMagickのruby用インターフェースであるRmagickのgem installが失敗しているようだ。そもそもImageMagickが入ってないので当然だな、と思いhomebrewからインストールを試みようとする。しかし、不穏な記事を発見。

homebrewでuniversal binaryなImageMagickをビルド – massatの日記

この記事によれば、HomebrewでインストールされるImageMagickはx64専用であるため、MAMP上のPHP等、x86で動作する環境でエラーを吐くらしい。

今の開発言語はRailsで、サーバーもMAMPではなくpowだが、自分はPHPもいじることがあるのでどうせならユニバーサルバイナリのImageMagickを入れようと思った。

前述のブログを参考に、

cp /usr/local/Library/Formula/imagemagick.rb /usr/local/Library/Formula/imagemagick.rb.org

でImageMagickのFormulaをコピーしたあと、

brew edit imagemagick

で編集。def install直下に

ENV.universal_binary 

を追加して、

brew install imagemagick

以下ログ。

Owner$ brew install imagemagick
==> Installing imagemagick dependency: freetype
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/freetype-2.4.10.mountainlion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/freetype-2.4.10.mountainlion.bottle.tar.gz
==> Pouring freetype-2.4.10.mountainlion.bottle.tar.gz
/usr/local/Cellar/freetype/2.4.10: 56 files, 2.5M
==> Installing imagemagick
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/imagemagick-6.8.0-10.mountainlion.bott
######################################################################## 100.0%
==> Pouring imagemagick-6.8.0-10.mountainlion.bottle.tar.gz
/usr/local/Cellar/imagemagick/6.8.0-10: 1422 files, 45M

OK。

ただ、RMagickのインストールはまだうまくいかず。

Owner$ gem install rmagick -v '2.13.1'
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

        /Users/Owner/.rbenv/versions/1.9.3-p374/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... yes
checking for InitializeMagick() in -lMagickCore... no
checking for InitializeMagick() in -lMagick... no
checking for InitializeMagick() in -lMagick++... no
Can't install RMagick 2.13.1. Can't find the ImageMagick library or one of the dependent libraries. Check the mkmf.log file for more detailed information.

*** 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=/Users/Owner/.rbenv/versions/1.9.3-p374/bin/ruby
    --with-MagickCorelib
    --without-MagickCorelib
    --with-Magicklib
    --without-Magicklib
    --with-Magick++lib
    --without-Magick++lib


Gem files will remain installed in /Users/Owner/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1 for inspection.
Results logged to /Users/Owner/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1/ext/RMagick/gem_make.out

ImageMagickのLibraryが見つからないようだ。
気を取り直して、

Owner$ cd /usr/local/lib

に移動し、

Owner$ ls
ImageMagick         libMagickWand-Q16.dylib     libjasper.1.0.0.dylib       liblcms.1.dylib         libtiff.5.dylib
libMagick++-Q16.7.dylib     libMagickWand-Q16.la        libjasper.1.dylib       liblcms.a           libtiff.a
libMagick++-Q16.dylib       libfreetype.6.dylib     libjasper.a         liblcms.dylib           libtiff.dylib
libMagick++-Q16.la      libfreetype.a           libjasper.dylib         libpng.a            libtiffxx.5.dylib
libMagickCore-Q16.7.dylib   libfreetype.dylib       libjpeg.8.dylib         libpng.dylib            libtiffxx.a
libMagickCore-Q16.dylib     libicns.1.dylib         libjpeg.a           libpng15.15.dylib       libtiffxx.dylib
libMagickCore-Q16.la        libicns.a           libjpeg.dylib           libpng15.a          pkgconfig
libMagickWand-Q16.7.dylib   libicns.dylib           liblcms.1.0.19.dylib        libpng15.dylib

状況を確認。libMagick++にバージョン番号が付いてしまっていて、これがRmagick側でエラーを吐く原因となっている。

Owner$ ln -s libMagick++-Q16.7.dylib libMagick++.dylib
Owner$ ln -s libMagickCore-Q16.7.dylib libMagickCore.dylib
Owner$ ln -s libMagickWand-Q16.7.dylib libMagickWand.dylib

なので、シンボリックリンクを張る。

再度挑戦。

Owner$ gem install rmagick -v '2.13.1'
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

        /Users/Owner/.rbenv/versions/1.9.3-p374/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... yes
checking for InitializeMagick() in -lMagickCore... yes
checking for snprintf() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AcquireImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AffinityImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AffinityImages() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AutoGammaImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AutoLevelImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for BlueShiftImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for ConstituteComponentTerminus() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DeskewImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for EncipherImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for EqualizeImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for FloodfillPaintImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for FunctionImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetAuthenticIndexQueue() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetImageAlphaChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetVirtualPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelImageColors() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelColorsImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelizeImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LiquidRescaleImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for MagickLibAddendum() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for OpaquePaintImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for QueueAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for RemapImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for RemoveImageArtifact() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SelectiveBlurImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetImageAlphaChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetImageArtifact() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetMagickMemoryMethods() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SparseColorImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SyncAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for TransparentPaintImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for TransparentPaintImageChroma() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for QueryMagickColorname() new signature... yes
checking for Image.type in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.kerning in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.interline_spacing in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.interword_spacing in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DitherMethod in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for MagickFunction in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for ImageLayerMethod in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for long double in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AlphaChannelType.CopyAlphaChannel... yes
checking for AlphaChannelType.BackgroundAlphaChannel... yes
checking for CompositeOperator.BlurCompositeOp... yes
checking for CompositeOperator.DistortCompositeOp... yes
checking for CompositeOperator.LinearBurnCompositeOp... yes
checking for CompositeOperator.LinearDodgeCompositeOp... yes
checking for CompositeOperator.MathematicsCompositeOp... yes
checking for CompositeOperator.PegtopLightCompositeOp... yes
checking for CompositeOperator.PinLightCompositeOp... yes
checking for CompositeOperator.VividLightCompositeOp... yes
checking for CompressionType.DXT1Compression... yes
checking for CompressionType.DXT3Compression... yes
checking for CompressionType.DXT5Compression... yes
checking for CompressionType.ZipSCompression... yes
checking for CompressionType.PizCompression... yes
checking for CompressionType.Pxr24Compression... yes
checking for CompressionType.B44Compression... yes
checking for CompressionType.B44ACompression... yes
checking for DistortImageMethod.BarrelDistortion... yes
checking for DistortImageMethod.BarrelInverseDistortion... yes
checking for DistortImageMethod.BilinearForwardDistortion... yes
checking for DistortImageMethod.BilinearReverseDistortion... yes
checking for DistortImageMethod.DePolarDistortion... yes
checking for DistortImageMethod.PolarDistortion... yes
checking for DistortImageMethod.PolynomialDistortion... yes
checking for DistortImageMethod.ShepardsDistortion... yes
checking for DitherMethod.NoDitherMethod... yes
checking for FilterTypes.KaiserFilter... yes
checking for FilterTypes.WelshFilter... yes
checking for FilterTypes.ParzenFilter... yes
checking for FilterTypes.LagrangeFilter... yes
checking for FilterTypes.BohmanFilter... yes
checking for FilterTypes.BartlettFilter... yes
checking for FilterTypes.SentinelFilter... yes
checking for MagickEvaluateOperator.PowEvaluateOperator... yes
checking for MagickEvaluateOperator.LogEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdBlackEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdWhiteEvaluateOperator... yes
checking for MagickEvaluateOperator.GaussianNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.ImpulseNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.LaplacianNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.MultiplicativeNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.PoissonNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.UniformNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.CosineEvaluateOperator... yes
checking for MagickEvaluateOperator.SineEvaluateOperator... yes
checking for MagickEvaluateOperator.AddModulusEvaluateOperator... yes
checking for MagickFunction.ArcsinFunction... yes
checking for MagickFunction.ArctanFunction... yes
checking for MagickFunction.PolynomialFunction... yes
checking for MagickFunction.SinusoidFunction... yes
checking for ImageLayerMethod.FlattenLayer... yes
checking for ImageLayerMethod.MergeLayer... yes
checking for ImageLayerMethod.MosaicLayer... yes
checking for ImageLayerMethod.TrimBoundsLayer... yes
checking for VirtualPixelMethod.HorizontalTileVirtualPixelMethod... yes
checking for VirtualPixelMethod.VerticalTileVirtualPixelMethod... yes
checking for VirtualPixelMethod.HorizontalTileEdgeVirtualPixelMethod... yes
checking for VirtualPixelMethod.VerticalTileEdgeVirtualPixelMethod... yes
checking for VirtualPixelMethod.CheckerTileVirtualPixelMethod... yes
checking for ruby/io.h... yes
checking for rb_frame_this_func() in ruby.h,ruby/io.h... yes
creating extconf.h
creating Makefile


======================================================================
Fri 15Feb13 16:37:12
This installation of RMagick 2.13.1 is configured for
Ruby 1.9.3 (x86_64-darwin12.2.1) and ImageMagick 6.8.0 Q16 
======================================================================



make
compiling rmagick.c
compiling rmdraw.c
compiling rmenum.c
compiling rmfill.c
compiling rmilist.c
rmilist.c: In function ‘ImageList_map’:
rmilist.c:448: warning: ‘MapImages’ is deprecated (declared at /usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick/magick/deprecate.h:200)
compiling rmimage.c
rmimage.c: In function ‘Image_map’:
rmimage.c:8155: warning: ‘MapImage’ is deprecated (declared at /usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick/magick/deprecate.h:198)
rmimage.c: In function ‘Image_recolor’:
rmimage.c:10701: warning: ‘RecolorImage’ is deprecated (declared at /usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick/magick/deprecate.h:140)
compiling rminfo.c
compiling rmmain.c
compiling rmmontage.c
compiling rmpixel.c
compiling rmstruct.c
compiling rmutil.c
rmutil.c: In function ‘rm_fatal_error_handler’:
rmutil.c:1612: warning: format not a string literal and no format arguments
rmutil.c: In function ‘handle_exception’:
rmutil.c:1652: warning: format not a string literal and no format arguments
linking shared-object RMagick2.bundle
ld: file not found: /usr/local/lib/libltdl.7.dylib for architecture x86_64
collect2: ld returned 1 exit status
make: *** [RMagick2.bundle] Error 1


Gem files will remain installed in /Users/Owner/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1 for inspection.
Results logged to /Users/Owner/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1/ext/RMagick/gem_make.out

まだエラー吐いてるぞ!どうなってんだ!

ld: file not found: /usr/local/lib/libltdl.7.dylib for architecture x86_64

ということなので、どうやらまたユニバーサルバイナリ関連のエラーらしい。
調べてみると、以下がヒット。

osx – ImageMagick and OS X Lion trouble – Stack Overflow

On 10.8 I solved this issue with:

brew install libtool –universal brew link libtool

If you don’t know what brew is, visit https://github.com/mxcl/homebrew
and its wiki.

これを試して見る。

Owner$ brew install libtool --universal
==> Downloading http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/libtool/2.4.2 --program-prefix=g --enable-ltdl-install
==> make install
==> Caveats
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> Summary
/usr/local/Cellar/libtool/2.4.2: 66 files, 2.2M, built in 15 seconds

特にエラーなし。

再度Rmagickインストールに挑戦。

Owner$ gem install rmagick -v '2.13.1'
Building native extensions.  This could take a while...
Successfully installed rmagick-2.13.1
1 gem installed
Installing ri documentation for rmagick-2.13.1...
Installing RDoc documentation for rmagick-2.13.1...

うまくいった!続いてbundle install。

Owner$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.3.6) 
Using activesupport (3.2.3) 
Using builder (3.0.0) 
Using activemodel (3.2.3) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.3) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.3) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.3) 
Using activeresource (3.2.3) 
Using carrierwave (0.6.2) 
Using coffee-script-source (1.3.3) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.3) 
Using rdoc (3.12) 
Using thor (0.14.6) 
Using railties (3.2.3) 
Using coffee-rails (3.2.2) 
Using commonjs (0.2.6) 
Using jquery-rails (2.0.2) 
Using less (2.2.1) 
Using less-rails (2.2.3) 
Using libv8 (3.3.10.4) 
Using bundler (1.2.3) 
Using rails (3.2.3) 
Using rmagick (2.13.1) 
Installing russian (0.6.0) 
Installing sass (3.1.19) 
Installing sass-rails (3.2.5) 
Installing sqlite3 (1.3.6) with native extensions 
Installing therubyracer (0.10.1) with native extensions 
Installing twitter-bootstrap-rails (2.0.8) 
Installing uglifier (1.2.4) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

YEAH!

やったーRMagickインストールできたぞーと喜んでいるのも束の間、Rails班のすだくんから衝撃の発言。「RMagickメンテされてないしいろいろやばそうだからminiMagick使うことにしたよ」

自分の人生いつもこんな感じだ・・・(鬱に入る)

コメントする

mysqldumpによるMySQL DBエクスポート&リストア&+α

mysqldumpは、MySQLデータベースを.sql形式でエクスポートするためのコマンドである。 低機能なツールではあるが、pipeでsshやgzipと繋げたり、それをcronで回すことで、意外と高度な需要に対応できる。

(以下の条件を前提としています)

  • mysqld起動中
  • mysqlのuserにはpasswordが設定済
  • 十分な空き容量

エクスポート

ローカルにエクスポート

基本(.sql)

必要に応じて、[dumpfilename]にはディレクトリパスも含める。

mysqldump --user=[username] --password=[userpass] [dbname] &gt; [dumpfilename].sql
+gzip圧縮(.sql.gz)

ファイルサイズが小さくなる。

mysqldump --user=[username] --password=[userpass] [dbname] | gzip &gt; [dumpfilename].sql.gz

リモートに直接エクスポート

[注意] sshコマンドをそのまま使っているので、鍵認証の場合はあらかじめローカル(転送する側)の公開鍵をリモート(転送される)側に登録しておく必要がある。

参考 sshで公開鍵認証(パスフレーズ無し)のメモ – toyosystem

基本(.sql)

圧縮なし。

mysqldump --user=[username] --password=[userpass] [dbname] | ssh -p [portnumber] [sshusername]@[remotehost] 'cat &gt; [dumpfilename].sql'
+gzip圧縮(.sql.gz)

圧縮しながら転送。おすすめ。

mysqldump --user=[username] --password=[userpass] [dbname] | gzip | ssh -p [portnumber] [sshusername]@[remotehost] 'cat &gt; [dumpfilename].sql'

インポート

リモート側に転送された .sql もしくは .sql.gz をMySQL DBに取り込む作業。

基本の場合
mysql --user=[username] --password=[userpass] [dbname] &lt; [dumpfilename].sql

gzip圧縮されている場合

zcat [dumpfilename].sql.gz | mysql --user=[username] --password=[userpass] [dbname]

応用編

エクスポート時に特定文字列を置換する + gzip

mysqldump --user=[username] --password=[userpass] [dbname] | sed 's/[search]/[replace]/g' | gzip &gt; [dumpfilename].sql.gz

参考

コメントする

Gmail上のメールを直接Google Appsメールへ移行する方法 (Google Apps Migration for Microsoft Exchangeを利用して)

Gmailで長らく運用してきたアドレスをGoogle Apps上で運用する独自ドメインのメールに移したいという要求が先日発生し、方法を調べた。

Google Apps Migration for Microsoft Exchangeというツールを使うと可能なようだ。 本来はExchange Serverからメールを移行するためのものだが、IMAPサーバーをSourceとすることでGmail -> Google Apps間の移行にも対応できる。

以下手順。基本的にはGoogle Apps アカウント間でメールを移行する – Google Apps ヘルプという公式ヘルプの補足。

1: [ドメインの設定] > [ユーザー設定] から [Provisioning API を有効にする] チェックボックスをオンにし、[変更を保存] 。

スクリーンショット 2012 12 12 3 28

2: [高度なツール] > [OAuth ドメイン キーを管理する]から以下のチェックボックスをオンにしたのち、「OAuth コンシューマ シークレット」をどこかにコピペしてメモしておく。

スクリーンショット 2012 12 12 3 30 2

3: ソフトをダウンロードしてインストール(Windowsオンリー)

以下URLからダウンロード

Google Apps Migration for Microsoft® Exchange

4: ソフトを起動後、以下のように設定、”次へ”

スクリーンショット 2012 12 12 3 35 2

5: 以下のように設定 “次へ”

スクリーンショット 2012 12 12 3 41 2

CSVの形式

これが公式ドキュメントだとよくわからないけども、 username@gmail.com#password, username@googleappsdomain.com という形式で書く。 メモ帳か何かで書いた上で、拡張子を.csvにして保存して読み込ませればおk。

6: その他の移行設定が必要であれば記入 “次へ”

キャプチャ5

7: 移行実行

あとは接続テストをしたうえでStartを押せば移行がどんどん進んでいくのだが、自分は以下のようなエラーに遭遇した。 キャプチャ

原因は、学校の回線で行おうとしていたためにファイアウォールの影響でIMAP接続がうまくいかなかったことのようだ。 家の回線で試したらそのまますんなり通った。

また、移行にはかなりの時間がかかるので注意。 自分は3000通程度だったが、それでも5時間はかかったと思う。

コメントする

Heroku セットアップ手順 (2012/11)

Herokuは、Ruby/PHP/Java/Python/node.js/Scala/Cloujure等の言語に対応するPaaSです。従来型の専用サーバーと比べかんたんにWebアプリケーションを設置して動かすことができます。また、dynoというサーバーの単位を増やしていくことによりスケールアウトが可能です。

また、Heroku Postgres というPostgres SQLベースのDaaS(Database as a Service)も提供しており、Webアプリケーションから汎用的なデータベースを利用することができます。これも自動スケーリングに対応しており、バックアップなどもあらかじめ用意された機構を持っています。

有料プランだと、Herokuを含めたPaaSはさくらのVPSなど格安なVPS/専用サーバーと比べて一般的に高いですが、その分さまざまなサーバー運営業務をおまかせにすることができます。もちろん、その分自由度は減りますが。

  1. 登録 herokuに登録する。

  2. Heroku Toolbeltをインストールする。 gem install heroku これで、ターミナルでherokuコマンドを利用できるようになる。

  3.  HerokuにSSH公開鍵を登録&アプリケーションを設置(デプロイ) //OS X環境の場合 ssh-keygen

  4. 保存するファイルパス及びファイル名を聞かれる(デフォルトは/Users/user/.ssh/フォルダ以下にid_rsaとid_rsa.pubが生成される)。

  5. パスフレーズを聞かれるので、4文字以上で設定する。
  6.  再度確認されるので、同じパスフレーズを入力して確定。
  7. .sshフォルダ以下に秘密鍵fooと公開鍵foo.pubが生成される(1で設定した名前) (以上参考 Play with さくらVPS vii セキュリティ設定その2 SSH鍵認証 | Kitchen Garden Blog)

生成されたら、

  1. chmod 0600 ~/.ssh/<さっきの秘密鍵の名前> * パーミッションの変更作業。 * .pubのほう(公開鍵)ではないので注意。 * これをやらないと、デフォルトの秘密鍵のパーミッションがオープンすぎるので、このあとの段階で「WARNING: UNPROTECTED PRIVATE KEY FILE!」と出て先に進めない。 (参考 MacでSSH公開鍵・秘密鍵ファイルをコピーして使ったら警告がでた – アインシュタインの電話番号☎)
  2. heroku login まずHerokuに登録したメールアドレスとパスワードを入力。 ~/.ssh/にある公開鍵のリストが出てくるので、さっき作った物を数字で選ぶ。 (参考 HerokuでSSH公開鍵(public key)を登録する方法(と削除して再登録する方法) | ID-Blogger)
  3. heroku create でHeroku上にアプリを作成。dynoが自動的に割り当てられる(無料分)
  4. お目当てのアプリの.gitがあるフォルダまで cdで移動
  5. git commitしたのち、git push heroku masterでHeroku上に展開。

  6. その他参考リンク それぞれ微妙に古かったり、やり方が違っていたりするので注意。

コメントする

Older Posts »