railsスケルトン作成

環境
【Webサーバー】
 eth0 インターネット
 eth1 スイッチ
【スイッチ】
 eth0 スイッチ
【DB用サーバー】


設定
【Webサーバー】
Railsインストール
ドキュメントを省いてインストール
gem install rails # --no-ri --no-rdoc

#railsあぷり作成
$ rails new soneTrack

#rails内部サーバー起動
rails server

Could not find gem 'sqlite3 (>= 0) ruby' in the gems available on this machine.
??エラー
rails new のデフォルトDBサーバーはsqllite。
 sqlliteインストールしていないから当然エラー

#db postgre指定でrails new
$ rails new test_apl -d postgresql

#bundler installでGemfileファイルから該当のgemをインストール

% bundle install --path=vendor/bundle --binstubs=vendor/bin
(注)pg インストール時にエラーが出る場合
 bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config
 ⇒pg_configのパスを設定してあげる。
 その後にbundle install

◾[--path]
指定したディレクトリへGemをインストールします。指定しない場合はrbenvのグローバルな領域へインストールされます。
上記の場合、カレントディレクトリに「vendor/bundle」というディレクトリが掘られ、インストールされます。


◾[--binstubs]
指定したディレクトリへコマンドとなるスクリプトを配置します。指定しない場合はカレントに 「bin」というディレクトリが出来てそれいかにスクリプトが置かれます(※1 注意が必要)
上記の場合、「vendor/bin」というディレクトリにスクリプトが配置されます。 「bundle_bin」というディレクトリ名を指定するのも多いようですが、自分はvendor/binとしてインストールしました。


【DB用サーバー】
#postgres設定
すでにpostgresSQLはインストール済み

#userの追加
createuser -a xxxxx

  • a, --adduser

新しいユーザが他のユーザを作成することを許可します。(注意: 実際これにより新しいユーザはスーパーユーザ となります。このオプションの名前はあまり適したものとはいえません。)

% createdb -E UTF8 -O xxxx test_production -T template0
所有者xxxxx db名test_production を文字コードUTF8 で template0を下に作成

#ユーザーのパスワード設定
% psql -c "alter user postgres with password 'xxxxxx'"
% psql -c "alter user xxxx with password 'xxxxxxx'"

※192.168.0.0/24 から 接続許可設定
vim /var/lib/pgsql/9.3/data/pg_hba.conf
以下の一行を追加
host all all 192.168.0.0 255.255.255.0 md5

#DB接続方法変更(md5
http://www.postgresql.jp/document/9.2/html/auth-pg-hba-conf.html

※Listen_Adressの変更
vim /var/lib/pgsql/9.3/data/postgressql.conf

listen_adress = "*"

※postgresの再起動(設定の読み込み)
service postgresql-9.3 restart

※postgresSqlで使用するポートの解放
vim /etc/sysconfig/iptables
以下一行を追加

  • A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport xxxxx -j ACCEPT