EC2で新しくrailsのAMIを作成する

  1. gem のインストール

まず gem のソースをダウンロードする。

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz


次に、パッケージを展開し、インストールを行う。

$ tar zxvf rubygem-0.9.4.tgz
$ cd rubygem-0.9.4
$ ruby setup.rb

  1. rails のインストール

次に gem を使って rails をインストール。

# gem install rails --include-dependencies

  1. MySQLのインストール

# yum install mysql-devel

  1. MySQL設定

詳しくはこちら

[root@centos ~]# vi /etc/my.cnf ← MySQL設定ファイル編集
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8 ← 追加(MySQLサーバーの文字コードUTF-8にする)


以下を追加(MySQLクライアントの文字コードUTF-8にする)

[mysql]
default-character-set = utf8

  1. MySQL起動

[root@centos ~]# /etc/rc.d/init.d/mysqld start ← MySQL起動

[root@centos ~]# chkconfig mysqld on ← MySQL自動起動設定

[root@centos ~]# chkconfig --list mysqld ← MySQL自動起動設定確認

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← ランレベル2〜5のonを確認

  1. MySQLデータベース初期設定
    1. rootユーザへのパスワード設定

MySQLの管理ユーザであるrootユーザ(システムのrootユーザとは別)にはデフォルトではパスワードが設定されていないため、パスワードを設定する


詳しくはこちら。
http://centossrv.com/mysql.shtml


[root@centos ~]# mysql -u root ← MySQLサーバーへrootユーザでログイン

mysql> set password for root@localhost=password('rootパスワード'); ← ホスト名がlocalhostのrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@'centos.centossrv.com'=password('rootパスワード'); ← ホスト名が自ホストのrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)


mysql> set password for root@127.0.0.1=password('rootパスワード'); ← ホスト名が127.0.0.1のrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)

  1. apacheのインストール

# rpm -qa httpd #すでにApacheがインストールされていないかどうかを確認
httpd-2.2.3-11.el5_1.centos.3 #このようにhttpd-*.*.*-**.****と表示されれば、Apacheはインストールされています


# yum -y install httpd #インストールされていなかった場合、このコマンドでインストールを行います

unsubscriptable objectなどと、エラーが出る場合は、
yum clean metadataをするといい様子。

  1. apacheの起動

/etc/rc.d/init.d/httpd start