2011年10月31日月曜日

Amazon EC2を始める(Apache編)

経緯
Amazon EC2を始める(導入編)
Amazon EC2を始める(SSL編)
Amazon EC2を始める(SCP編)
の続きです。

概要
Amazon EC2に作成したインスタンスにApacheを立ち上げた際のメモです。


手順
1. Apacheがないことを確認。

初期状態のサービスは下記、httpdは入っていない。
$ chkconfig --list
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
cgconfig        0:off   1:off   2:off   3:off   4:off   5:off   6:off
cgred           0:off   1:off   2:off   3:off   4:off   5:off   6:off
cloud-init      0:off   1:off   2:on    3:on    4:on    5:on    6:off
cloud-init-user-scripts 0:off   1:off   2:on    3:on    4:on    5:on    6:off
conman          0:off   1:off   2:off   3:off   4:off   5:off   6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
irqbalance      0:off   1:off   2:off   3:on    4:on    5:on    6:off
lvm2-monitor    0:off   1:on    2:on    3:on    4:on    5:on    6:off
mdmonitor       0:off   1:off   2:on    3:on    4:on    5:on    6:off
messagebus      0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
netfs           0:off   1:off   2:off   3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
ntpdate         0:off   1:off   2:on    3:on    4:on    5:on    6:off
psacct          0:off   1:off   2:off   3:off   4:off   5:off   6:off
quota_nld       0:off   1:off   2:off   3:off   4:off   5:off   6:off
rdisc           0:off   1:off   2:off   3:off   4:off   5:off   6:off
restorecond     0:off   1:off   2:off   3:off   4:off   5:off   6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off
yum-updatesd    0:off   1:off   2:on    3:on    4:on    5:on    6:off

2. rootでインストール
$ sudo su root
# yum install httpd

3. rootで起動
#  /etc/rc.d/init.d/httpd start
Starting httpd:                                            [  OK  ]

4. ブラウザから確認
http://ec2-xxx-xx-xxx-xxx.ap-northeast-1.compute.amazonaws.com/

※ 自分のサーバーのドメインは「AWS Management Console」から確認できます。(Public DSN)

5. サーバー起動時に立ち上がるよう設定
# chkconfig httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

6. index.htmlを作成
# cat /etc/httpd/conf/httpd.conf | grep DocumentRoot
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/var/www/html"

# vi /var/www/html/index.html
でもいいのですが。

グループを作成してソースを分けます。
# groupadd -g 502 webuser
# tail -1 /etc/group
webuser:x:502:root,ec2-user
# usermod -G webuser root
# usermod -G webuser ec2-user
# chgrp -R webuser /usr/local/src
$ vi /var/www/html/index.html
<!DOCTYPE html>
<html>
  <head>
     <title>Hello world!</title>
  </head>
  <body>
    <h1>Hello World!!</h1>
  </body>
</html>
$ sudo su root
# ln -s /usr/local/src/index.html /var/www/html/index.html

7. 再度ブラウザから確認
http://ec2-xxx-xx-xxx-xxx.ap-northeast-1.compute.amazonaws.com/


問題ないですね。
とりあえずApacheは入れてみたものの、次はrubyやphpには目もくれず一直線にnode.js + MongoDBを導入しようと思います(*^-^)




0 件のコメント:

コメントを投稿