境外宝塔服务器切换pm2管理器的node版本失败的问题

有宝塔内部的PM2管理器,下nodejs软件的时候,默认使用的是http://npm.taobao.org淘宝的镜像。这对于国内服务器来说是天堂,安装很快。但是对我这种香港服务器来说,反而满成狗。
如果,它能在下载失败后,尝试使用国外的资源,那就好了,奈何它并不会。所以只能手动帮助他了。
我以现在最新版本nodejsv12.17.0为例。

1、 查看失败日志信息
cat /www/server/panel/logs/error.log

日志内容如下

Downloading and installing node v12.17.0...
Downloading http://npm.taobao.org/mirrors/node/v12.17.0/node-v12.17.0-linux-x64.tar.xz...
#####                                                                      7.4%
curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
Binary download from http://npm.taobao.org/mirrors/node/v12.17.0/node-v12.17.0-linux-x64.tar.xz failed, trying source.
grep: /www/server/nvm/.cache/bin/node-v12.17.0-linux-x64/node-v12.17.0-linux-x64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 1 CPU core(s)
Number of CPU core(s) less than or equal to 2, running in single-threaded mode
Local cache found: $NVM_DIR/.cache/src/node-v12.17.0/node-v12.17.0.tar.xz
Checksums match! Using existing downloaded archive $NVM_DIR/.cache/src/node-v12.17.0/node-v12.17.0.tar.xz
$>./configure --prefix=/www/server/nvm/versions/node/v12.17.0 <
which: no python2.7 in (/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin)
which: no python2 in (/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin)
Please use Python 2.7
nvm: install v12.17.0 failed!
N/A: version "12.17.0 -> N/A" is not yet installed.

You need to run "nvm install 12.17.0" to install it before using it.
! WARNING: Version '12.17.0' does not exist.
default -> 12.17.0 (-> N/A)
sh: line 10: npm: command not found
sh: line 11: npm: command not found
sh: line 12: npm: command not found
sh: line 13: npm: command not found
N/A: version "N/A -> N/A" is not yet installed.

You need to run "nvm install N/A" to install it before using it.

从日志能看出,他请求http://npm.taobao.org/mirrors/node/v12.17.0/node-v12.17.0-linux-x64.tar.xz下的过程中, 下载超时了。之后程序继续执行在安装的时候,发现这个目录/www/server/nvm/.cache/bin/node-v12.17.0-linux-x64/node-v12.17.0-linux-x64.tar.xz这个文件不存在,进而安装失败。

2、 手动下载并放置指定目录

我们手动访问http://npm.taobao.org/mirrors/node/v12.17.0/node-v12.17.0-linux-x64.tar.xz这个地址,把文件下载下来。然后创建他需要的目录。创建目录

mkdir /www/server/nvm/.cache/bin/node-v12.17.0-linux-x64/

之后,把你的文件传到这个目录下

3、尝试再次切换版本

会看到下面的日志说明

Downloading and installing node v12.17.0...
Local cache found: $NVM_DIR/.cache/bin/node-v12.17.0-linux-x64/node-v12.17.0-linux-x64.tar.xz
Checksums match! Using existing downloaded archive $NVM_DIR/.cache/bin/node-v12.17.0-linux-x64/node-v12.17.0-linux-x64.tar.xz
Now using node v12.17.0 (npm v6.14.4)
Now using node v12.17.0 (npm v6.14.4)
default -> 12.17.0 (-> v12.17.0 *)
/www/server/nvm/versions/node/v12.17.0/bin/pm2 -> /www/server/nvm/versions/node/v12.17.0/lib/node_modules/pm2/bin/pm2
/www/server/nvm/versions/node/v12.17.0/bin/pm2-dev -> /www/server/nvm/versions/node/v12.17.0/lib/node_modules/pm2/bin/pm2-dev
/www/server/nvm/versions/node/v12.17.0/bin/pm2-docker -> /www/server/nvm/versions/node/v12.17.0/lib/node_modules/pm2/bin/pm2-docker
/www/server/nvm/versions/node/v12.17.0/bin/pm2-runtime -> /www/server/nvm/versions/node/v12.17.0/lib/node_modules/pm2/bin/pm2-runtime
npm WARN [email protected] requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ [email protected]
added 270 packages from 214 contributors in 42.003s

它发现本地已经存在,就不去下载了。然后,就直接安装成功了。

你可能感兴趣的:(服务器)