LoginSignup
5
5

More than 5 years have passed since last update.

Node.js って Solaris ではどうなのか調べてみた (1/1/2016, 4:42:07 PM)

Last updated at Posted at 2016-01-01

node.js と io.js がげふんげふんしているあたりに調べて埋もれさせていたネタ。

いつのまにか Node.js と io.js が統合され、Nodejs v4.0 としてリリースされていたり、最新はv5.x とか、もう一度あらため直してみようかなと。

  • nodejs.org では、Solaris 32/64 bit x86 binary が配布されているが、illumos ベースの環境で build されている
  • でも、Solaris 10 x86 や Solaris 11 x86 では動かしている人を見かける
  • す、SPARC はどうなの?
    V8 JavaScript Engine は、"V8 does not support the SPARC CPU architecture." ということで SPARC をサポートしていない。
    server-side non-blocking framework が欲しいということでれば、Virt.X は動くみたいだけど、ごめん、このあたりは良くわかっていない

過去を少し振り返ってみる

で、試しに、node.js が配布している node.js v0.12.9 SunOS binary を Solaris 11.1 x86 とか 11.2 x86 とか 11.3 x86 で動かしてみると、AN EXAMPLE: WEBSERVER みたいなコードも、このバイナリは下記のエラーを吐いて動きません。

$ cat server.js

var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

$  node-v0.12.9-sunos-x64/bin/node server.js                           
    events.js:85
          throw er; // Unhandled 'error' event
                ^
    Error: listen EPROTOTYPE
        at exports._errnoException (util.js:746:11)
        at Server._listen2 (net.js:1129:19)
        at listen (net.js:1172:10)
        at Server.listen (net.js:1257:5)
        at Object.<anonymous> (/export/home/kazus/server.js:7:4)
        at Module._compile (module.js:460:26)
        at Object.Module._extensions..js (module.js:478:10)
        at Module.load (module.js:355:32)
        at Function.Module._load (module.js:310:12)
        at Function.Module.runMain (module.js:501:10)

これは、example.js failed under solaris #7004 に書かれていたが、illumos がサポートした SOCK_CLOEXEC and SOCK_NONBLOCK有効になってしまっているから、そんなオプションはない Oracle Solaris では動かないと。

やっぱり illumos ベースの binary なんだなと。

また、v0.12.x は mdb 関連の実装で error になってしまう。
これも illumos 依存で、結局のところ、Binaries for sunos do not work on Solaris 11.2 - Error: listen EPROTOTYPE #9282 にヒントがあって、最新の source を git clone して --without-mdb (0.12.2 以降で追加されたっぽい)すれば良いらしい。

もう、source から build すれば解決だね?
と思ってたけど、はまりポイントもそれなりにあったので一気にまとめてみた。
そして、binary package はない。

というわけで、Oracle Solaris 11.3 で Node.js を build する方法、いっきにいくよっ (x86 限定なので注意です)

前提条件

  • 必要な IPS パッケージのインストール

    # pkg install developer/versioning/git developer/gnu-binutils developer/build/gnu-make developer/gcc-48
    
    
  • mkheaders の実行を忘れずに!
    忘れると v4/v5 系がまともに build できない。
    下記を実行。詳しくは、GCC 4.5.2, 4.7.3, and 4.8.2 Packages Do Not Provide include-fixed Header Files で。

    # /usr/gcc/4.8/lib/gcc/i386-pc-solaris2.11/4.8.2/install-tools/mkheaders
    

node-v0.12.9 を Solais 11.3 で source から build する場合

$ wget https://nodejs.org/dist/v0.12.9/node-v0.12.9.tar.gz
$ cd node-v0.12.9
$ PATH=/usr/gnu/bin:$PATH; export PATH

common.gypi を修正

*** common.gypi.orig    Fri Jan  1 16:26:36 2016
--- common.gypi Fri Jan  1 16:32:44 2016
***************
*** 198,203 ****
--- 198,204 ----
              'ldflags': [ '-m64' ],
            }],
            [ 'OS=="solaris"', {
+             'defines': ['_GLIBCXX_USE_C99_MATH'],
              'cflags': [ '-pthreads' ],
              'ldflags': [ '-pthreads' ],
              'cflags!': [ '-pthread' ],

続き

$ CC=gcc ./configure --dest-cpu=x64 --dest-os=solaris --prefix=/opt/node  --with-dtrace --without-mdb
$ CC=gcc gmake
$ sudo CC=gcc gmake install

node-v4.2.4 を Solais 11.3 で source から build する場合

$ wget https://nodejs.org/dist/v4.2.4/node-v4.2.4.tar.gz
$ cd node
$ PATH=/usr/gnu/bin:$PATH; export PATH
$ CC=gcc configure --dest-os=solaris --prefix=/opt/node --with-dtrace  --dest-cpu=x64
$ CC=gcc gmake
$ sudo CC=gcc gmake install

node-v5.3.0 を Solais 11.3 で source から build する場合

node-v4.2.4 と同じ

$ wget https://nodejs.org/dist/v4.2.4/node-v5.3.0.tar.gz
$ cd node
$ PATH=/usr/gnu/bin:$PATH; export PATH
$ CC=gcc configure --dest-os=solaris --prefix=/opt/node --with-dtrace  --dest-cpu=x64
$ CC=gcc gmake
$ sudo CC=gcc gmake install

git clone して build する場合

$ git clone https://github.com/nodejs/node.git
$ cd node
$ PATH=/usr/gnu/bin:$PATH; export PATH
$ CC=gcc configure --dest-os=solaris --prefix=/opt/node --with-dtrace  --dest-cpu=x64
$ gmake
$ CC=gcc gmake install

build は面倒なのでなんとかしたい場合

手取り早く動かしてみたいなら、Peter さんの binary をオススメします。

binary package ないって言ったけど、こいつは特別だ。

  • for Solaris 10
    http://www.petertribble.co.uk/Solaris/node.html
      Peter さんの Solaris 10 の binary はこちら。(Current version, Node 0.12.9) 実は、Solaris 11 以降でも動く。Solaris Binary Compatibility 万歳\(^o^)/
      Solaris 11.2 にインストールして、ghost 動かしてみたけど動いてる。

動くの?

動かしてみてください。

5
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5