最近搞内部系统开发,频繁跟nodejs打交道,遇到了不少莫名其妙的坑,暂时记录下,回头有时间深究到底。
系统环境:
[root@localhost ~]# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 5.8 (Tikanga) Release: 5.8 Codename: Tikanga [root@localhost ~]# python -V Python 2.7.3 [root@localhost ~]# node -v v0.10.26 [root@localhost ~]# npm -v 1.4.3
1,nodejs环境问题
手动编译的nodejs,流程很简单,先把Python升级了,然后下载nodejs包make install。
# wget http://nodejs.org/dist/latest/node-v0.10.26.tar.gz # tar zxvf node-v0.10.26.tar.gz # cd node-v* # ./configure && make && make install
过程很顺畅没有什么问题,安装完正常使用,至少node -v可以输出版本号,似乎已经成功安装了,但是在开发调试过程中发现,使用node的child_process.exec去执行一个node模块结果callback输出Error: Command failed: /usr/bin/env: node: No such file or directory,很奇怪有没有!!!代码都能执行,并且也回调了,可是回调报错竟然是node不存在。
快速解决方案:
# ln -s /usr/local/bin/node /usr/bin/node
2,npm link的问题
我写了一个node模块,想加入node全局调用,于是cd到模块目录npm link了下,命令正常执行,我以为一切正常,如同我在Windows下调试的那样,但是结果是:
[root@localhost ~]# uechecker-server : No such file or directory [root@localhost ~]# which uechecker-server /usr/local/bin/uechecker-server [root@localhost ~]# ll /usr/local/bin/uechecker-server lrwxrwxrwx 2 root root 49 04-03 15:13 /usr/local/bin/uechecker-server -> ../lib/node_modules/uechecker-server/uechecker.js
这尼玛又是什么逆天的问题,我想一定是我node没有编译好或者是系统哪里出问题了,又是各种文件不存在,暂时没有找到问题所在。
[root@localhost bin]# strace uechecker-server execve("/usr/local/bin/uechecker-server", ["uechecker-server"], [/* 33 vars */]) = 0 brk(0) = 0x896d000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b67b17a8000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b67b17a9000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=339761, ...}) = 0 mmap(NULL, 339761, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b67b17aa000 close(3) = 0 open("/lib64/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\332!\2060\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1726472, ...}) = 0 mmap(0x3086200000, 3506520, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3086200000 mprotect(0x308634f000, 2097152, PROT_NONE) = 0 mmap(0x308654f000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14f000) = 0x308654f000 mmap(0x3086554000, 16728, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3086554000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b67b17fd000 arch_prctl(ARCH_SET_FS, 0x2b67b17fd6e0) = 0 mprotect(0x308654f000, 16384, PROT_READ) = 0 mprotect(0x308601c000, 4096, PROT_READ) = 0 munmap(0x2b67b17aa000, 339761) = 0 brk(0) = 0x896d000 brk(0x898e000) = 0x898e000 open("/usr/lib/locale/locale-archive", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=56467728, ...}) = 0 mmap(NULL, 56467728, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b67b17fe000 close(3) = 0 execve("/usr/local/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/opt/17173/jdk/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/opt/17173/jdk/jre/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/opt/17173/jdk/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/lib64/qt-3.3/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/kerberos/sbin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/kerberos/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/local/sbin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/local/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/sbin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/sbin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/usr/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) execve("/root/bin/node\r", ["node\r", "/usr/local/bin/uechecker-server"], [/* 33 vars */]) = -1 ENOENT (No such file or directory) write(2, "/usr/bin/env: ", 14/usr/bin/env: ) = 14 ) = 5e open("/usr/share/locale/locale.alias", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2528, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b67b4dd9000 read(3, "# Locale name alias data base.\n#"..., 4096) = 2528 read(3, "", 4096) = 0 close(3) = 0 munmap(0x2b67b4dd9000, 4096) = 0 open("/usr/share/locale/zh_CN.UTF8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/zh_CN.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/zh_CN/LC_MESSAGES/libc.mo", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=69942, ...}) = 0 mmap(NULL, 69942, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2b67b4dd9000 close(3) = 0 open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=25464, ...}) = 0 mmap(NULL, 25464, PROT_READ, MAP_SHARED, 3, 0) = 0x2b67b4deb000 close(3) = 0 open("/usr/lib64/gconv/EUC-CN.so", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\7\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=14280, ...}) = 0 mmap(NULL, 2109472, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b67b4df2000 mprotect(0x2b67b4df5000, 2093056, PROT_NONE) = 0 mmap(0x2b67b4ff4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x2b67b4ff4000 close(3) = 0 open("/usr/lib64/gconv/tls/x86_64/libGB.so", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/gconv/tls/x86_64", 0x7fff49e2b920) = -1 ENOENT (No such file or directory) open("/usr/lib64/gconv/tls/libGB.so", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/gconv/tls", 0x7fff49e2b920) = -1 ENOENT (No such file or directory) open("/usr/lib64/gconv/x86_64/libGB.so", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/gconv/x86_64", 0x7fff49e2b920) = -1 ENOENT (No such file or directory) open("/usr/lib64/gconv/libGB.so", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\6\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=67440, ...}) = 0 mmap(NULL, 2162712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b67b4ff6000 mprotect(0x2b67b5006000, 2093056, PROT_NONE) = 0 mmap(0x2b67b5205000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf000) = 0x2b67b5205000 close(3) = 0 write(2, ": \346\262\241\346\234\211\351\202\243\344\270\252\346\226\207\344\273\266\346\210\226\347\233\256\345\275\225", 29: 没有那个文件或目录) = 29 write(2, "\n", 1 ) = 1 close(1) = 0 exit_group(127) = ?