cat /etc/issue | head -n 1
Category: ‘CentOS’
LinuxコマンドでOSのバージョンを調べる
CentOS6.2 へ Ruby1.9.3 のインストール
It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby.
まずはRubyインストール後にエラーになるので、 LibYAML のインストールを行う。
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz tar xvzf yaml-0.1.4.tar.gz cd yaml-0.1.4 ./configure --prefix=/usr/local/ruby193/lib make make install
Rubyのインストール。
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz tar xvzf ruby-1.9.3-p194.tar.gz cd ruby-1.9.3 ./configure --prefix=/usr/local/ruby193 --enable-shared --with-opt-dir=/usr/local/ruby193/lib make make install
SVNレポジトリのサーバ移行
VPSサーバの移行のため、SVNレポジトリの移行の必要が出てきた。その覚え書き。
svnadmin dump レポジトリ名 > ファイル名.dmp * リビジョン 0 をダンプしました。 * リビジョン 1 をダンプしました。 ・・・省略・・・ * リビジョン 573 をダンプしました。 * リビジョン 574 をダンプしました。 * リビジョン 575 をダンプしました。
ちなみに出力先に、ファイル書き込み権限が無いと怒られます。
WinSCPでサーバからローカルへ、そして別サーバへとリポジトリ移動しようと思いましたが、ファイルサイズが大きいので、scpコマンドで、直接サーバ間で移動しました。
scp /home/foo/repo.dmp foo@other_server:/home/foo/repo.dmp foo@other_server's password:
これなら一発。
新しいサーバに新しいレポジトリを作成。
svnadmin create new_repo
そしてロード。
svnadmin load new_repo/ < /home/foo/repo.dmp
レポジトリ移行後のユーザをapacheユーザに変更すればOK。
chown -R apache:apache *
ワンライナー
PGになって10年以上も経つが、恥ずかしながら最近「ワンライナー」という言葉を知った。
もっともスクリプト言語を始めたのも、この1年くらいだし、オブジェクト言語専門だったので、妙に新鮮だった。
ということで、覚え書き。
history | tr -s ' ' 'n' | sort | uniq -c | sort -rn | head -n 10
これは、頻繁に使用したコマンド履歴のベストテンを出力するワンライナー。
302 ls 231 cd 190 -la 79 sudo 78 vi 60 ruby 50 .. 44 | 29 hist.txt 26 mv
ls cd 最強。当たり前。
コマンドラインでのsvn checkout
svn checkout file:///var/www/svn/repos/project .
crontab 覚え書き
久しぶりに cron の設定。忘れていたので覚え書き。
-l で一覧。 -e で編集。
$crontab -l 0 0 * * * /opt/scripts/svn_backup.sh 0 0 * * * /opt/scripts/mysql_backup.sh
左から、分 0~59 / 時 0~23 / 日 1~31 / 月 1~12 / 曜日 0~7
JDK1.6のインストールとAlternatives
毎回インストール方法が簡単になるけど、反面ブラックボックス化して理解不能になるので覚え書き。
ここから、jdk-6u30-linux-x64.bin をダウンロードして解凍。
ちなみに、jdk-6u30-linux-x64-rpm.bin は勝手にインストールしてくれるので、自分的にはNG。
余談だが、X86 と X64 は、64bit版がX64で、32bit版がX86。
数値の大小がまぎらわしい。 Windows7 と Windows98 みたいなもの・・・。
[user@server src]$ sudo ./jdk-6u30-linux-x64.bin Unpacking... Checksumming... Extracting... UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu). creating: jdk1.6.0_30/ creating: jdk1.6.0_30/db/ creating: jdk1.6.0_30/db/bin/ inflating: jdk1.6.0_30/db/bin/ij …省略 Creating jdk1.6.0_30/jre/lib/ext/localedata.jar Creating jdk1.6.0_30/jre/lib/plugin.jar Creating jdk1.6.0_30/jre/lib/javaws.jar Creating jdk1.6.0_30/jre/lib/deploy.jar Java(TM) SE Development Kit 6 successfully installed. Product Registration is FREE and includes many benefits: * Notification of new versions, patches, and updates * Special offers on Oracle products, services and training * Access to early releases and documentation Product and system data will be collected. If your configuration supports a browser, the JDK Product Registration form will be presented. If you do not register, none of this information will be saved. You may also register your JDK later by opening the register.html file (located in the JDK installation directory) in a browser. For more information on what data Registration collects and how it is managed and used, see: http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html Press Enter to continue..... Done.
解凍されたディレクトリを、お好みの場所へ移動。
[user@server src]$ sudo mv jdk1.6.0_30 /usr/local/jdk1.6 [user@server src]$ ls /usr/local/jdk1.6/
javaのバージョンを調べると古いまま・・・。
どうやらalternatives というもので管理されているよう。
OS初期状態では、/usr/lib/jvm/jre-1.4.2-gcj/bin/java が実態としてリンクされている模様。
[root@servere ~]# alternatives --config java 1 プログラムがあり 'java' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:
alternatives –install で、今回インストールしたディレクトリを指定する。
ちなみに、最後の30は優先順位らしいが、いくつでもよい。指定しないと怒られる。
[root@server ~]# alternatives --install /usr/bin/java java /usr/local/jdk1.6/bin/java 30 [root@server ~]# alternatives --config java 2 プログラムがあり 'java' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java 2 /usr/local/jdk1.6/bin/java Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
どうやら上手くいったようだ。
ちなみに、ユーザは /usr/bin/java を環境変数のパスで参照しに行っている。
/usr/bin/java → /etc/alternatives/java → /usr/local/jdk1.6/bin/java
慣れれば便利だが、知らないと手動で ln -s してしまいそう。
下記のコマンドは、alternativesを使用しているようなので気を付けよう。
antlr ksh mta-newaliases print-cancel print-lpqman java ksh-man mta-newaliasesman print-cancelman print-lprm jaxp_parser_impl ksh-usrbin mta-pam print-lp print-lprman jre_1.4.2 mta mta-rmail print-lpc print-lprmman jre_1.4.2_exports mta-aliasesman mta-sendmail print-lpcman print-lpstat jre_gcj mta-mailq mta-sendmailman print-lpman print-lpstatman jre_gcj_exports mta-mailqman print print-lpq xinputrc
Gemfile WindowsXP(開発機) ⇔ CentOS5.5 デプロイ
サーバ(CentOS5.5)側と、開発機(WindowsXP SP3)でどうしてもgem等バージョンの整合性を合わせるのが大変だった。ruby初級者なので、理解も曖昧・・・。
こちらを立てるとあちらが立たずという感じ。苦痛。
ハマッたのは、execjs と therubyracerの指定。
なぜかpythonのライブラリを求められたりしたので…。
とりあえず最終形としての Gemfile
source 'http://rubygems.org' gem 'rails', '3.1.3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'mysql2', '0.3.10' gem 'rake', '0.8.7' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'execjs' gem 'therubyracer', :platforms => :ruby gem 'sass-rails', '~> 3.1.5' gem 'coffee-rails', '~> 3.1.1' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # Use unicorn as the web server # gem 'unicorn' #group :development do # Deploy with Capistrano # gem 'capistrano', requier => nil # gem 'capistrano-ext', requier => nil # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' #end group :test do # Pretty printed test output gem 'turn', '0.8.2', :require => false end
試行錯誤の結果なので、正しい設定かは責任は一切持ちません。とりあえず動作したというだけの設定。これから色々理解していこうと思います。
参考にするなら、独自環境に合わせてください。責任は持ちません。
Capistrano deployエラー
WindowsXPクライアント開発機から、CentOS5.5サーバへcapstrano で下記エラー。
Ruby 1.9.3 will raise SystemCallError in this case
デプロイ設定で丸1日程ハマっている…。
$ cap deploy * executing `deploy' * executing `deploy:update' ** transaction: start * executing `deploy:update_code' executing locally: "svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache -rHEAD" c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:97: warning: failed to set environment variable. Ruby 1.9.3 will raise SystemCallError in this case. *** [deploy:update_code] rolling back * executing "rm -rf /app/xxxx/releases/20111217022544; true" servers: ["svn.server.host"] Password: [svn.server.host] executing command command finished in 422ms c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:106:in ``': No such file or directory - svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache -rHEAD (Errno::ENOENT) from c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:106:in `block in run_locally'
Capstranoのデプロイ時、サーバ上でsvnコマンドを発行していると思い込んでいたのだが、WindowsXPクライアント開発機でコマンドラインでの問題のようだと疑ってみる。
クライアント開発機でSVNコマンドライン実行できないとダメなのか?
TortuiseSVN はインストール済みだし、 CapstranoをインストールしていればクライアントからのSVN取得は問題ないと勝手に思い込んでいた。
とにかく、SVN CLI で検索してみて1番上に引っ掛かった下記ツールをダウンロード&インストールしてみた。
$ cap deploy * executing `deploy' * executing `deploy:update' ** transaction: start * executing `deploy:update_code' executing locally: "svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache -rHEAD" command finished in 2406ms
とりあえずのエラー回避。
Capistrano のエラー
デプロイの為、Capistrano を使ってみる。
環境は、WindowsXP のクライアント開発環境から、CentOS5.5 のリモートサーバ上へ。
まずは、クライアント開発環境にて、capistrano を gemでインストール。
$ gem install capistrano $ gem install capistrano-ext
クライアント開発機のアプリのフォルダへ移動して、capifyコマンド。
$ capify . [add] writing './Capfile' [add] writing './config/deploy.rb' [done] capified!
まずは、sshで怒られる。ログインユーザがwindowsのユーザ名(xxxx)になっていた。
$ cap deploy:setup * executing `deploy:setup' Password: connection failed for: www.whoocus.com (Net::SSH::AuthenticationFailed: xxxx)
capify で生成された deploy.rb に追記。
set :user, "app"
今度は、sudoコマンドは、tty でなければならないと怒られる。
$ cap deploy:setup * executing `deploy:setup' Password: [****] sudo: sorry, you must have a tty to run sudo
サーバ側で、visudo にてsudo のデフォルト設定を変更しなくてはならない。
# コメントアウト #Defaults requiretty
またも怒られる。
$ cap deploy:setup * executing `deploy:setup' Password: no tty present and no askpass program specified
再度、サーバ側で、visudo にてsudo のデフォルト設定を追記。
# 追記 Defaults visiblepw
リモートサーバ上に、デプロイ用のディレクトリができている。
やっとうまく行った。