Nest.js部署记录

Nest项目部署一般有两种做法,一种是在本地打包后上传到服务器,一种是docker容器化部署。这次采用的是第一种。但是,Nest在本地打包时,不会将依赖给打包进去,所以需要把package.json也带上,然后在服务器上安装依赖:

css 复制代码
npm install --omit-dev

接着,使用pm2后台运行node.js. 通过pm2 ecosystem生成配置文件:

js 复制代码
module.exports = {
  apps: [
    {
      name: '', //应用名称
      script: './main.js',  //入口文件
      instances: 'max',  // 根据需求设置实例数量
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      env: {
        NODE_ENV: 'production',
      },
    },
  ]
 }

启动:pm2 start ecosystem.config.js, 最后通过nginx转发到node监听的端口。

实际部署过程遇到的问题:

1) CentOS7内缺少支持node 18以上版本的C标准库:

解决办法:需要升级到glibc-2.28

shell 复制代码
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar xf glibc-2.28.tar.gz
cd glibc-2.28/ && mkdir build && cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

在安装升级过程中,又遇到了

2) 第二个问题:

解决办法::升级gcc与make

shell 复制代码
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz 
tar xf glibc-2.28.tar.gz 
cd glibc-2.28/ && mkdir build && cd build 
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

# 升级GCC(默认为4 升级为8)</span> 
yum install -y centos-release-scl 
yum install -y devtoolset-8-gcc* 
mv /usr/bin/gcc /usr/bin/gcc-4.8.5 
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc 
mv /usr/bin/g++ /usr/bin/g++-4.8.5 
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++ 
# 升级 make(默认为3 升级为4) 
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz 
tar -xzvf make-4.3.tar.gz && cd make-4.3/ 
./configure --prefix=/usr/local/make make && make install cd /usr/bin/ && mv make make.bak 
ln -sv /usr/local/make/bin/make /usr/bin/make

在yum安装devtoolset-8-gcc时,遇到

第三个问题:

解决办法:更换为阿里的源

bash 复制代码
cd /etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

执行上面步骤后,yum makecache还是报错:

还是使用了centos的源,原来还需要更新SCL的源。

vim 复制代码
vim /etc/yum.repos.d/CentOS-SCLo-scl.repo

修改如下:

shell 复制代码
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

修改/etc/yum.repos.d/CentOS-SCLo-scl-rh.repo:

ini 复制代码
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

刷新缓存:

css 复制代码
yum repolist
yum clean all
yum makecache

解决完第三个问题,回到前面继续安装devtoolset-8-gcc,解决第二个问题。最后回到解决第一个问题,安装升级glibc-2.28.

bash 复制代码
cd /root/glibc-2.28/build 
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

接着遇到第四个问题:

4)bison版本太旧:

解决办法:

复制代码
yum install -y bison

最后安装更新所有软件:

go 复制代码
make && make instal

参考资料:

www.cnblogs.com/yuwen01/p/1...

www.cnblogs.com/Jedi-Pz/p/1...

相关推荐
Yeats_Liao1 天前
Go Web 编程快速入门 10 - 数据库集成与ORM:连接池、查询优化与事务管理
前端·数据库·后端·golang
你的人类朋友1 天前
适配器模式:适配就完事了bro!
前端·后端·设计模式
间彧1 天前
SpringBoot集成RocketMQ事务消息
后端
间彧1 天前
RocketMQ消息幂等控制:借助数据库唯一约束实现
后端
间彧1 天前
RocketMQ消息幂等控制:借助Redis实现
后端
霸道流氓气质1 天前
SpringBoot+MybatisPlus+自定义注解+切面实现水平数据隔离功能(附代码下载)
java·spring boot·后端
间彧1 天前
RocketMQ消息幂等控制:借助ConcurrentHashMap的putIfAbsent方法实现
后端
why技术1 天前
1K+Star的开源项目能给一个在校大学生带来什么?
前端·人工智能·后端
克莱恩~莫雷蒂1 天前
Spring Boot 中 controller层注解
java·spring boot·后端