我在华为云服务器配置npm开发环境的时候, SSH远程连接一直掉线,无奈提了工单,被告知是NPM install导致的OOM问题。无语了,破NPM还有这个问题呢!
在项目的跟路径下创建一个名为:.npmrc
的文件
在文件内部写入:
NODE_OPTIONS=--max-old-space-size=4096
4096
的单位是M
, 如果还不够的话请自动调大一点。这个数字有个讲究,最好是1024的倍数哦。
然后可以通过命令: npm config ls
查看配置是否生效
base) ➜ gatsby-cds-blog git:(master) ✗ npm config ls
; "user" config from /Users/chendongsheng/.npmrc
chromedriver-cdnurl = "https://npm.taobao.org/mirrors/chromedriver"
couchbase-binary-host-mirror = "https://npm.taobao.org/mirrors/couchbase/v{version}"
debug-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector"
disturl = "https://npm.taobao.org/dist"
electron-mirror = "https://npm.taobao.org/mirrors/electron/"
flow-bin-binary-host-mirror = "https://npm.taobao.org/mirrors/flow/v"
fse-binary-host-mirror = "https://npm.taobao.org/mirrors/fsevents"
fuse-bindings-binary-host-mirror = "https://npm.taobao.org/mirrors/fuse-bindings/v{version}"
git4win-mirror = "https://npm.taobao.org/mirrors/git-for-windows"
gl-binary-host-mirror = "https://npm.taobao.org/mirrors/gl/v{version}"
grpc-node-binary-host-mirror = "https://npm.taobao.org/mirrors"
hackrf-binary-host-mirror = "https://npm.taobao.org/mirrors/hackrf/v{version}"
home = "https://npm.taobao.org"
leveldown-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown/v{version}"
leveldown-hyper-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown-hyper/v{version}"
mknod-binary-host-mirror = "https://npm.taobao.org/mirrors/mknod/v{version}"
node-sqlite3-binary-host-mirror = "https://npm.taobao.org/mirrors"
node-tk5-binary-host-mirror = "https://npm.taobao.org/mirrors/node-tk5/v{version}"
nodegit-binary-host-mirror = "https://npm.taobao.org/mirrors/nodegit/v{version}/"
operadriver-cdnurl = "https://npm.taobao.org/mirrors/operadriver"
phantomjs-cdnurl = "https://npm.taobao.org/mirrors/phantomjs"
profiler-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector/"
proxy = "http://127.0.0.1:7890"
puppeteer-download-host = "https://npm.taobao.org/mirrors"
python-mirror = "https://npm.taobao.org/mirrors/python"
rabin-binary-host-mirror = "https://npm.taobao.org/mirrors/rabin/v{version}"
registry = "https://registry.npmmirror.com/"
sass-binary-site = "https://npm.taobao.org/mirrors/node-sass"
sodium-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/sodium-prebuilt/v{version}"
sqlite3-binary-site = "https://npm.taobao.org/mirrors/sqlite3"
utf-8-validate-binary-host-mirror = "https://npm.taobao.org/mirrors/utf-8-validate/v{version}"
utp-native-binary-host-mirror = "https://npm.taobao.org/mirrors/utp-native/v{version}"
zmq-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/zmq-prebuilt/v{version}"
; "project" config from /Users/chendongsheng/github/react_learner/gatsby-cds-blog/.npmrc
NODE_OPTIONS = "--max-old-space-size=4096"
; node bin location = /usr/local/bin/node
; node version = v20.9.0
; npm local prefix = /Users/chendongsheng/github/react_learner/gatsby-cds-blog
; npm version = 10.1.0
; cwd = /Users/chendongsheng/github/react_learner/gatsby-cds-blog
; HOME = /Users/chendongsheng
; Run `npm config ls -l` to show all defaults.
在继续安装,如果还有该问题的话,请继续调大该值,直到解决问题。
Linux 服务器自动重启是常见的故障现象,可能由多种原因导致。在排查该问题时,可以按照以下步骤进行:
首先,可以通过 last
或 uptime
命令查看重启时间。例如:
[root@localhost ~]# last
reboot Wed 2023-11-15 12:00:00 CST
这表示系统在 2023-11-15 12:00:00 CST 重启。
系统日志通常会记录重启的原因。可以使用 grep
命令查找关键字,例如 panic
、error
、exception
和 shutdown
。例如:
[root@localhost ~]# cat /var/log/messages | grep -E -i "panic|error|exception|shutdown"
这将显示系统日志中包含上述关键字的行。
定时任务可能会导致系统自动重启。可以使用 crontab -l
命令查看定时任务列表。
硬件故障也可能导致系统自动重启。可以检查 CPU、内存、磁盘、电源等硬件是否存在异常。
如果通过以上步骤仍无法确定重启原因,可以使用 kdump
和 crash
工具生成内核崩溃转储文件。然后,可以使用分析工具查看转储文件,以获取更多信息。
常见的导致Linux自动重启的原因
以下是一些常见的导致Linux自动重启的原因:
软件错误:例如,某个程序存在错误,导致系统崩溃。
硬件故障:例如,内存损坏或电源故障。
配置错误:例如,系统配置文件存在错误。
恶意软件:例如,病毒或木马程序导致系统自动重启。
GitHub上有人提过相关的 github-npm-ISSUE
statck overflow 也有相关记载: npm install stackoverflow