このエントリーをはてなブックマークに追加
はてなブックマーク - Amazon EC2 Node.js, npm, Socket.IOをインストール
Share on Facebook
Post to Google Buzz
Bookmark this on Yahoo Bookmark
Bookmark this on Livedoor Clip
Share on FriendFeed
Amazon EC2 Node.js, npm, Socket.IOをインストールあらかたは回帰、きまぐれは彷徨

Amazon EC2にNode.js, npm, Socket.IOをインストール。

Node.js単体に関してはこちらの記事とほぼ同様の流れ。
Amazon Web Serviceでnode.jsを起動させてみた

wget http://nodejs.org/dist/node-v0.4.11.tar.gz
tar xvzf node-v0.4.11.tar.gz
cd node-v0.4.11
ec2-user> ./configure
Checking for program g++ or c++          : not found
Checking for program icpc                : not found
Checking for program c++                 : not found
/home/ec2-user/node-v0.4.11/wscript:232: error: could not configure a cxx compiler!
~/node-v0.4.11

ここで、コンパイラがないとおこられる

sudo yum install gcc-c++
sudo yum install openssl-devel

もし無い場合はopenssl-develも、私の場合はもうつかってたのでなし。

これでいけるか、と思ったが、突然重くなって落ちた。Googleさんに尋ねてみたところ、この2つの記事に出くわす。
node.jsをAmazon EC2のmicroインスタンスに入れる時の注意
Amazon EC2 MicroインスタンスのAmazon LinuxにNodeをインストールした
どうやら、CPU負荷が高くなりすぎて、make中にkillされてしまったらしい。

ただ、make cleanして、もういちど./configure, make, make installしたところすぐ終了。

ec2-user> ./configure
Checking for program g++ or c++          : /usr/bin/g++
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok
Checking for program gcc or cc           : /usr/bin/gcc
Checking for gcc                         : ok
Checking for library dl                  : yes
Checking for openssl                     : yes
Checking for library util                : yes
Checking for library rt                  : yes
--- libeio ---
Checking for library pthread             : yes
Checking for function pthread_create     : yes
Checking for function pthread_atfork     : yes
Checking for futimes(2)                  : yes
Checking for readahead(2)                : yes
Checking for fdatasync(2)                : yes
Checking for pread(2) and pwrite(2)      : yes
Checking for sendfile(2)                 : yes
Checking for sync_file_range(2)          : yes
--- libev ---
Checking for header sys/inotify.h        : yes
Checking for function inotify_init       : yes
Checking for header sys/epoll.h          : yes
Checking for function epoll_ctl          : yes
Checking for header port.h               : not found
Checking for header poll.h               : yes
Checking for function poll               : yes
Checking for header ['sys/types.h', 'sys/event.h'] : not found
Checking for header sys/queue.h                    : yes
Checking for function kqueue                       : not found
Checking for header sys/select.h                   : yes
Checking for function select                       : yes
Checking for header sys/eventfd.h                  : yes
Checking for function eventfd                      : yes
Checking for SYS_clock_gettime                     : yes
Checking for library rt                            : yes
Checking for function clock_gettime                : yes
Checking for function nanosleep                    : yes
Checking for function ceil                         : yes
Checking for fdatasync(2) with c++                 : yes
'configure' finished successfully (3.415s)
~/node-v0.4.11
ec2-user> node -v
v0.4.11

ちゃんと、/usr/local/bin/nodeに入ってる。

次にnpm のインストール
EC2ではないけれど、この記事が非常に参考になった。
Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application
一時的に/usr/localの所有権を$USERに移してるのは、インストールコマンドを実行するため。
sudo shだとよくないってどっかに書いてあった気がするけど忘れた。汗

sudo chown -R $USER /usr/local
curl http://npmjs.org/install.sh | sh
sudo chown -R root /usr/local
npm -v
1.0.27

npmインストールされた!
次に、socket.io

sudo npm install socket.io
sudo: npm: command not found
~

???
というわけで、困ったときのStackoverflowさんに聞いてみる。

sudo changes PATH – why?
On EC2: sudo node command not found, but node without sudo is ok

どうやら、sudo したときのPATHの設定がセキュリティの関係上リセットされるらしい。
しかも、/usr/local/binをPATHに読み込んでくれない。なので、visudoでpathに/usr/local/binを追加する。

sudo visudo

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
ec2-user> sudo npm install socket.io
socket.io@0.8.2 ./node_modules/socket.io
├── policyfile@0.0.4
├── redis@0.6.6
└── socket.io-client@0.8.2
~

/usr/local/binにPATHが通って、sudoからnpm, nodeできるように!