OraRails

Oracle(9i,10g)+RubyOnRails(Ver1.2.1+Apache+mongrel)の設定メモ

DBはUTF8なのにSHIFTJISになる

2007-03-07 10:44:47 | Xserver+apache
Oracle10gは、UTF8になってるのに、Rails+ODBCで帰ってきた結果はSHIFT-JISになってる。なんで?

確認1)本当にOracleはUTF8か?

SQL# select * from NLS_DATABASE_PARAMETERS where PARAMETER = 'NLS_NCHAR_CHARACTERSET';

PARAMETER VALUE
-------------------------- --------------------
NLS_NCHAR_CHARACTERSET UTF8

間違いなさそう

確認2)ODBCで、Shift-Jisになってるのではないか?

あった!!

したいことの整理

2007-02-22 09:33:00 | Xserver+apache
ちょっと整理する

・できてること
  sourceの場所が、/docroot/rails1 で
  http://a.com -> a.com:8000
          a.com:8001
          a.com:8002 のバランシング。

・したいこと
  sourceの場所が、/docroot/rails1
          /docroot/rails2
          /docroot/rails3
          /docroot/rails4 で

http://a.com/rails1 -> a.com/rails1:8000
           a.com/rails1:8001
           a.com/rails1:8002 のバランシング。

http://a.com/rails2 -> a.com/rails2:8005
           a.com/rails2:8006
           a.com/rails2:8007 のバランシング。

http://a.com/rails3 -> a.com/rails3:8010
           a.com/rails3:8011
           a.com/rails3:8012 のバランシング。

http://a.com/rails4 -> a.com/rails4:8015
           a.com/rails4:8016
           a.com/rails4:8017 のバランシング。

参考サイト1)someedaの日記 - [Ruby on Rails]ApacheのProxyPassでRailsを動かす

ZendFrameWork を入れる

2007-02-01 18:49:25 | Xserver+apache
ZendFrameWork をダウンロード

#/usr/src/ZendFramework-0.7.0 root# cd library/
#/usr/src/ZendFramework-0.7.0/library root# ls -la
total 32
drwx------ 4 1005 513 136 Jan 19 02:15 .
drwx------ 11 1005 513 374 Jan 19 02:16 ..
drwx------ 47 1005 513 1598 Jan 19 02:15 Zend
-rwx------ 1 1005 513 13016 Jan 18 06:37 Zend.php
#/usr/src/ZendFramework-0.7.0/library root#

Zend,Zend.phpをphpのinclude_pathにコピーする

Apache2.2.4 + mongrel_cluster

2007-01-31 11:03:21 | Xserver+apache
参考サイト1)Install/Mongrel cluster With Apache2.2
参考サイト2)apxsでapacheにモジュールを追加する
参考サイト3)bind- おいぬまの覚書
参考サイト4)mongrel apache
参考サイト5)shachi-wiki
参考サイト6)Scaling Rails with Apache 2.2, mod_proxy_balancer and Mongrel

1)apacheの設定
ロードバランス設定のために、mongrelのサイトで紹介されていたconfigureオプションを指定します。
#./configure --enable-so --enable-deflate --enable-proxy --enable-proxy-balancer --enable-rewrite --enable-cache --enable-mem-cache --enable-ssl --enable-headers --with-included-apr

2)ProxyPass
参考)- 株式会社エスロジカル - 技術ドキュメント Apache:ProxyPass ディレクティブ

3)Proxy balancer
参考)YappoLogs: Apache 2.2.0 のロードバランス機能(mod_proxy_balancer)を使いこなす



bind9の設定

2007-01-31 10:40:54 | Xserver+apache
Virtualhostを組むために bind9の設定を触りました。

※bind9のサーバーはdebianです。

1) vi /etc/bind/local/aaaaa.zone 正引きの設定

2)赤字部分を追加

@ IN 86400 SOA aaaaa. bbbbb. (
2007011001 ; serial
28800 ; refresh
7200 ; retry
604800 ; expire
86400 ; ttl
)
@ IN A sss.sss.sss.sss
@ IN NS ccccc.

dns IN MX 10 ddddd.
@ IN MX 10 ddddd..

dns IN A mmm.mmm.mmm.mmm
www IN A qqq.qqq.qqq.qqq
hostname1 IN A 192.168.240.ddd
hostname2 IN A 192.168.240.ccc
hostname3 IN A 192.168.101.aaa
hostname4 IN A 192.168.101.bbb

type1 IN A 192.168.ttt.rrr
type2 IN A 192.168.ttt.rrr
type3 IN A 192.168.ttt.rrr
type4 IN A 192.168.ttt.rrr
type5 IN A 192.168.ttt.rrr
type6 IN A 192.168.ttt.rrr



3) vi /etc/bind/local/bbbb.zone 逆引きの設定

4)赤字部分の追加
@ IN 86400 SOA aaaaa. bbbbb. (
2007013001 ; serial
2880 ; refresh
7200 ; retry
604800 ; expire
86400 ; ttk
)
@ IN NS dns.mmm.mmm.mmm.

ff0 IN PTR aaa.aaa.aaa.aa.

fff IN PTR type1.example.jp.
fff IN PTR type2.example.jp.
fff IN PTR type3.example.jp.
fff IN PTR type4.example.jp.
fff IN PTR type5.example.jp.
fff IN PTR type6.example.jp.

ffa IN PTR current1.example.jp.
ffb IN PTR current2.example.jp.
ffc IN PTR current3.example.jp.
ffd IN PTR current4.example.jp.
ffe IN PTR current5.example.jp.
ffg IN PTR current6.example.jp.
ffh IN PTR current7.example.jp

192.168.ttt.rrrのサーバーに6本の別ドメインサーバーの設定をしました。
( type1,type2,type3,type4,type5,type6 .example.jp )

Mongrel

2007-01-27 15:23:57 | Xserver+apache
mongrel 1.0.1,mongrel_clusterを入れる

参考サイト1)Mongrel
参考サイト2)Mongrelを使って見る

1.gem install mongrel

→ mongrel 1.0.1
2.railsアプリのフォルダへ移動して
 # 起動
mongrel_rails start -d development -p 3000 -B
 # 停止
mongrel_rails stop
3.gem install mongrel_cluster

→mongrel_cluster-0.2.1
4.コンフィギュレーション
  railsアプリのフォルダへ移動して

 #ポート8000~8002番でクラスタを組む
mongrel_rails cluster::configure -e production -p 8000 -N 3
 # 起動
  mongrel_rails cluster::start

 # 停止
  mongrel_rails cluster::stop



Ruby Rails ODBC 設定

2007-01-26 16:27:56 | Xserver+apache
RailsにODBCでOracle接続する。ドキュメントが少ない。。。。
参考サイト1)Ruby DBIモジュールを使う
参考サイト2)HowtoConnectToMicrosoftSQLServerFromRailsOnLinux→これを見ながらやりました
参考サイト3)OpenLink ODBC Adapter for ActiveRecord/RubyonRails

必要なもの
1.Actual ODBC driver (不要か?)
2.ruby-odbc ruby-odbc-0.9994
3.ruby-dbi dbi-0.1.1.tar → ruby-dbi
4.odbc-railsodbc-rails-1.3

手順 参考サイト2より
1.Ruby ODBC:

Before building ruby-odbc, make sure that you have odbc-devel installed as this is a requirement to build ruby-odbc. I used yum to install odbc-devel.

Also, note that if you are running Ubuntu “Breezey Badger,” you probably don’t have make installed, and won’t be able to run the code below. Install make by running Synaptic and searching for “make.” [David R]

# tar zvxf ruby-odbc-0.9994.tar.gz
# cd /usr/src/ruby-odbc-0.9994/
# ruby extconf.rb
# make
# make install

2.Ruby DBI ODBC driver:

# cd /usr/src/ruby-dbi
# ruby setup.rb config --with=dbi,dbd_odbc
# ruby setup.rb setup
# ruby setup.rb install

Test everything:
Heres a quick way to see if ruby can talk to SQL Server provided by Mark Imbriaco:

macsv1:/usr/src root# irb
irb(main):001:0> require "dbi"
=> true
irb(main):002:0> dbh = DBI . connect('dbi:ODBC:oota','macs','system')
=> #<DBI::DatabaseHandle:0x517e44 @trace_output=#>
irb(main):003:0> quit

→この時点でうまくいっていなければ、DBIで失敗してます
If everything went well, go make it work in Rails:

3.Setup Rails
odbc-railsのREADME →★設定IP他★を読む。
3パターンの入れ方がある。manualインストールをやりました。

find /usr/ -name 'odbc_adapter*' で、
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record の周辺にファイルができていることを確認

database.yml:

development:
adapter: odbc
dsn: oota
username: macs
password: system

Add other sections in the same manner.


PHP ODBC設定

2007-01-26 10:11:12 | Xserver+apache
結局 InstantClientがPPCのため、OCI接続はあきらめ、ODBC設定に切り替えました。ActualTecnologies
The Actual ODBC Driver for Oracle を購入 ライセンスキー →★設定IP他★
参考サイト1)Oracleドライバの設定
参考サイト2)PHPセットアップ

1.ODBCドライバの設定 →★設定IP他★
2.PHP5.2.0コンパイル
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-trans-sid --with-xml --enable-exif --enable-mbstring --enable-mbregex --enable-dbx --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-mysql=/usr --with-mysql-sock=/var/mysql/mysql.sock

make
make install
完了

3.確認
サンプルソース でサンプルを作成して実行

Xcodeでコンパイル

2007-01-24 16:01:26 | Xserver+apache
MacOS 10.4.8 では Xcode2.4 を使うことができます。
Unixのソースをユニバーサルライブラリーにコンパイルするのに使えます。
やったことをメモしておきます。
参考サイト1)Xcode2.3ユーザーガイド:ファイル毎のコンパイルフラグ 
参考サイト2)Developing Cross-Platform Unix Applications with Mac OS X
参考サイト3)MacWiki

Rubyの場合の例)
If you'd like to reproduce this figure, you can use the following recipe.

1.Download the Ruby distribution from the Ruby download page.
2.If needed, unpack the distribution. If you download it with Safari, it should have been downloaded and unpacked onto your Desktop.
3.Open a Terminal window and cd to the Ruby distribution directory. Then run the configure script.
4.Open Xcode and create a new project of
the GNU Make type.>Save it to your Ruby distribution directory.
→ プロジェクトの中にGNU Make(This project builds using an external build system)というのものがある5.Add the Ruby sources to the project using Project > Add to Project menu.
6.Build using the Build > Build menu or Command-B.


自己流の手順でいくと
1.xxxx.tarの解凍
2.解凍先フォルダへ移動して ./configure オプションもプラスする
3.Xcodeで新規プロジェクトを作成(DynamicLibraryの中の External Build System)。解凍先フォルダに保存
例)php5.2.0フォルダに直接プロジェクトを作成する
4.プロジェクトを選んで、情報ボタンを押す。
ビルド→アーキテクチャ→i386,ppc にする。
一般→ターゲットSDKをしようしたクロス開発→MacOSX10.4u.sdk
5.ビルド する。

Ruby - OCI - Rails インストール(要約)

2007-01-06 18:50:52 | Xserver+apache
Rubyインストール関連をまとめました。

1.このIntelMacには、Universalbinary でRubyをインストールする。
macsv1:/usr/local/bin root# file ruby
ruby: Mach-O universal binary with 2 architectures
ruby (for architecture ppc): Mach-O executable ppc
ruby (for architecture i386): Mach-O executable i386

Makefile にCFLAGS="-arch ppc -archi386"を追加する

2.rubyGem、Railsは Universalbinary の状態でインストールする
3.oracleinstantClientが、ppcバイナリ対応なので、ruby/ociは、rbconfig.rb
を修正してppcに見せかけてコンパイルする

vi /usr/lib/ruby/1.8/i686-darwin8.8.4/rbconfig.rb

CONFIG["CFLAGS"] = "-arch ppc -g -O2 -pipe -fno-common"
CONFIG["DLDFLAGS"] = "-arch ppc"

macsv1:/usr/src/ruby-oci8-0.1.16 root# ruby setup.rb config -- --with-instant-client=/usr/local/oracle/instantclient10_1

OK

4.dittoコマンドで、ppc バイナリのrubyを作る
参考サイト1)Tissot Blogs →超重要
参考サイト2)Universal Binary Programming Guidelines, Second Edition: アプリケーションの強制翻訳実行 →超重要
macsv1:/usr/local/bin root# ditto -arch ppc /usr/bin/ruby ruby_pcc

macsv1:/usr/local/bin root# ruby_pcc -r oci8 -e "OCI8.new('macs', 'system', '//192.168.240.110:1521/orcl').exec('select count(*) from im01rc') do |r| puts r.join(','); end"
177729.0

これでOCIも動くようになった。Railsで動かすにはどうすれば良いか??