[掉坑] 记一次被宝塔坑的操作..

泄露秘密 提交于 2019-12-03 20:25:14

需求方直接甩手给我一个需求, 考虑之下, 采用了 node 来作为后端 koa + mongodb 真香

首先是在宝塔上安装 mongodb

将监听 ip 设置为 0.0.0.0 (不考虑 authorization)

然后写一个测试登录的文件

const mongodb = require('mongoose')
const { env: config } = require('./config')
require('colors')

const db = mongodb.connect(config.db, {
  useUnifiedTopology: true,
  useNewUrlParser: true
}).then(r=> {
  console.log(`${ 'debug'.green }: MongoDB connected success❤️`.blue)
}).catch(r=> {
  throw new Error(`${ 'debug'.red }: MongoDB connected fail😂`.red)
})

这个 mongoose 玩法还真是不同, 共享一个实例

代码写好了, 就到了部署到线上去, 开开心心的登录 ssh 打开宝塔后台安装 pm2, 发现怎么都启动不了服务, 查看日志看到了

cat /tmp/panelExec.log
export NVM_DIR="/www/server/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Installing latest LTS version.
Downloading and installing node v12.13.0...
Downloading http://npm.taobao.org/mirrors/node/v12.13.0/node-v12.13.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.16' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by node)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v12.13.0` to unset it.
pm2.sh: line 428: npm: command not found
pm2.sh: line 429: npm: command not found
pm2.sh: line 430: npm: command not found
pm2.sh: line 431: npm: command not found
grep: /www/server/panel/config/config.json: No such file or directory

我们遇到什么困难都不要怕, 微笑着面对它, 消除的error的唯一办法就是 google...
查了很多文档, 一开始我的解决办法是手动安装 pm2

➜  ~ node -v
zsh: command not found: node

WTF, 没有安装 nodejs

➜  ~ sudo cat /etc/redhat-release
CentOS release 6.10 (Final)

手动安装还是报错, 猜测可能是 gcc 版本过低(这不是废话吗)

下载操作一下, 由于下载是在是太慢了, 就在下载过程中, 尝试了很多操作..

wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-4.9.2/gcc-4.9.2.tar.bz2

由于是线上环境, 不太敢乱动

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!