下载安装包
https://nodejs.org/en/download/
Linux Binaries (x64)
下载后FTP上传上centos服务器
1、解压
tar -xvf node-v12.18.1-linux-x64.tar.xz
2、配置环境变量
vim /etc/profile 环境变量新增如下配置:
export NODE_HOME=/root/node-v12.18.1-linux-x64
export PATH=PATH:PATH:PATH:NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
source /etc/profile 生效环境变量
node -v 检查是否安装成功
应用服务部署
下载应用代码,FTP上传到centos
进入到代码目录 cd /root/project
npm i 安装
npm run dev 发布当前应用
遇到的问题:
1、权限不足
[root@argrace-ci product-open-node]# npm i
[ …] - fetchMetadata: sill pacote range manifest for picomatch@^2.2.1 fetched in 1ms
[ …] - fetchMetadata: sill pacote range manifest for picomatch@^2.2.1 fetched in 1ms
npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
nodejieba@2.4.1 install /root/product-open-node/node_modules/nodejieba
node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for nodejieba@2.4.1 and node@12.18.1 (node-v72 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir ‘/root/product-open-node/node_modules/nodejieba/build’
gyp WARN EACCES current user does not have permission to access the dev dir “/root/.cache/node-gyp/12.18.1”
gyp WARN EACCES attempting to reinstall using temporary dev dir “/root/product-open-node/node_modules/nodejieba/.node-gyp”
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir ‘/root/product-open-node/node_modules/nodejieba/.node-gyp’
gyp ERR! System Linux 3.10.0-957.el7.x86_64
gyp ERR! command “/root/node-v12.18.1-linux-x64/bin/node” “/root/node-v12.18.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “configure” “–fallback-to-build” “–module=/root/product-open-node/node_modules/nodejieba/build/Release/nodejieba.node” “–module_name=nodejieba” “–module_path=/root/product-open-node/node_modules/nodejieba/build/Release” “–napi_version=6” “–node_abi_napi=napi” “–napi_build_version=0” “–node_napi_label=node-v72”
gyp ERR! cwd /root/product-open-node/node_modules/nodejieba
gyp ERR! node -v v12.18.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute ‘/root/node-v12.18.1-linux-x64/bin/node /root/node-v12.18.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/root/product-open-node/node_modules/nodejieba/build/Release/nodejieba.node --module_name=nodejieba --module_path=/root/product-open-node/node_modules/nodejieba/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72’ (1)
node-pre-gyp ERR! stack at ChildProcess. (/root/product-open-node/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:315:20)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Linux 3.10.0-957.el7.x86_64
node-pre-gyp ERR! command “/root/node-v12.18.1-linux-x64/bin/node” “/root/product-open-node/node_modules/.bin/node-pre-gyp” “install” “–fallback-to-build”
node-pre-gyp ERR! cwd /root/product-open-node/node_modules/nodejieba
node-pre-gyp ERR! node -v v12.18.1
node-pre-gyp ERR! node-pre-gyp -v v0.14.0
node-pre-gyp ERR! not ok
Failed to execute ‘/root/node-v12.18.1-linux-x64/bin/node /root/node-v12.18.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/root/product-open-node/node_modules/nodejieba/build/Release/nodejieba.node --module_name=nodejieba --module_path=/root/product-open-node/node_modules/nodejieba/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72’ (1)
phantomjs-prebuilt@2.1.16 install /root/product-open-node/node_modules/phantomjs-prebuilt
node install.js
PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /root/product-open-node/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1592793378421/phantomjs-2.1.1-linux-x86_64 -> /root/product-open-node/node_modules/phantomjs-prebuilt/lib/phantom
Phantom installation failed [Error: EACCES: permission denied, link ‘/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1592793378421/phantomjs-2.1.1-linux-x86_64’ -> ‘/root/product-open-node/node_modules/phantomjs-prebuilt/lib/phantom’] {
errno: -13,
code: ‘EACCES’,
syscall: ‘link’,
path: ‘/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1592793378421/phantomjs-2.1.1-linux-x86_64’,
dest: ‘/root/product-open-node/node_modules/phantomjs-prebuilt/lib/phantom’
} Error: EACCES: permission denied, link ‘/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1592793378421/phantomjs-2.1.1-linux-x86_64’ -> ‘/root/product-open-node/node_modules/phantomjs-prebuilt/lib/phantom’
egg-ci@1.15.0 postinstall /root/product-open-node/node_modules/egg-ci
node install.js
internal/fs/utils.js:230
throw err;
^
Error: EACCES: permission denied, open ‘/root/product-open-node/.travis.yml’
at Object.openSync (fs.js:458:3)
at Object.writeFileSync (fs.js:1355:35)
at Object. (/root/product-open-node/node_modules/egg-ci/install.js:141:6)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
errno: -13,
syscall: ‘open’,
code: ‘EACCES’,
path: ‘/root/product-open-node/.travis.yml’
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/nunjucks/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN co-mocha@1.2.2 requires a peer of mocha@>=1.18 <6 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: nodejieba@2.4.1 (node_modules/nodejieba):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: nodejieba@2.4.1 install: node-pre-gyp install --fallback-to-build
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: phantomjs-prebuilt@2.1.16 (node_modules/phantomjs-prebuilt):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: phantomjs-prebuilt@2.1.16 install: node install.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! egg-ci@1.15.0 postinstall: node install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the egg-ci@1.15.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-06-22T02_36_21_395Z-debug.log
解决办法:
–加sudo
sudo npm i
2、
[root@argrace-ci product-open-node]# sudo npm i
sudo: npm: command not found
[root@argrace-ci product-open-node]#
解决办法:
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
然后再安装npm
3、还 是权限问题

解决办法:
安装build工具包
npm install --global --production

然后再安装npm

成功~
启动服务
npm start
本文详细介绍了在CentOS服务器上部署Node.js应用的步骤,包括下载安装包、配置环境变量、应用代码上传及使用npm进行安装和发布。同时,针对部署过程中遇到的权限问题提供了具体的解决方案。
&spm=1001.2101.3001.5002&articleId=106862250&d=1&t=3&u=e5002a350fd549e3a19ecf4d850b8773)
1069

被折叠的 条评论
为什么被折叠?



