Nuxt project release server steps (using pm2 management)

Note: If the server has already installed node, you can go to step 3 directly. If it is not installed, start from step 1. Step 2 is available or not. It is recommended to use the convenient management node version.

  1. Install node (this place is best to install the same version as your local node)

Encounter: The latest version I downloaded by default is v18.14.2 , and an error was reported when I finally installed the dependencies (the node version is too high, and the current project's dependency version is too low).

1.1, enter the server directory

cd /usr/local/src/

1.2. Enter the command (this place is the copied link, the version can be replaced with the version you need)

Reference: https://nodejs.org/zh-cn/download/releases/

wget https://nodejs.org/dist/v12.19.0/node-v12.19.0.tar.gz

1.3. Unzip the download package in the current directory (/usr/local/src/)

tar -zxvf node-v12.19.0.tar.gz 

1.4. After the decompression is completed, move the decompression package to the directory /usr/local/node/. If there is no node directory, create one. Because it is generally believed that the software installed under local

mv node-v12.19.0  /usr/local/node/
cd  /usr/local/node/

1.5, run command

./configure 

1.6. Run the command (this place takes a long time to wait, so be patient, I waited for about 2 hours)

make

1.7, run command

sudo make install

1.8. Enter the command to check (if there is a version prompt, the installation is successful, if not, the configuration file is still needed)

node -v

1.9. Enter the command (you don’t need to do this if the installation is successful)

vim /etc/profile

Enter above export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

export NODE_HOME=/usr/local/node/node-v9.8.0
export PATH=$NODE_HOME/bin:$PATH

Save and exit, enter the command

source /etc/profile

Last check version number

node -v
  1. , Install node manager n

npm install -g n

View n module version

n --version或 n -V

Download the specified version of node ( the command uses the corresponding node version )

n 12.19.0

Install the latest version (node ​​version)

n latest

switch node version

n

Select installed version

  node/12.19.0
o node/18.14.2

Use up/down arrow keys to select version, return key to install, d to delete, q to quit

Use node -v to view the current version. If you want to view the version or the current version, you need to set PATH

2.1, set PATH, view the current node directory

which node

2.2, edit the configuration file

vi ~/.bash_profile

2.3. Insert the following 2 lines of code at the end of the file and save

export N_PREFIX=/usr/local
export PATH=$N_PREFIX/bin:$PATH
:wq
:wq force write to file and exit

2.4. Execute source to make the modification take effect immediately

source ~/.bash_profile

Then use node -v to view the version

3. Install pm2 to start the nuxt project (do not use too low node version, installing pm2 will report an error)

# 安装pm2
npm install -g pm2
# 把项目打包后将这几个文件上传至服务器
nuxt.config.js  
package.json  
package-lock.json  
static 
.nuxt
##后续更新只需要上传这几个文件就可以了
nuxt.config.js  
package.json  
.nuxt
# 构建安装(进入服务器在当前项目目录下安装依赖)
npm install
# 启动项目(访问地址,你服务器地址加你项目配置的端口号)
pm2 start npm --name "你的项目名字" -- run start
# 查看项目
pm2 list
## 要是没有启动成功就手动启动
npm run dev
# Configure npm source
npm config set registry https://registry.npmmirror.com

3.1, pm2 use commands

# 启动进程/应用
pm2 start app.js  # 单个启动
pm2 start app.js -i max  # 根据有效CPU数目启动最大进程数目
pm2 start app.js -i 3      # 启动3个进程,自动负载均衡
pm2 start app.js --watch  # 启动并监听项目文件变化
pm2 start app.json # 启动进程, 在 app.json里设置选项
----------------------------
#批量启动
{
    "apps": [{
        "name": "appA",
        "script": "./appA.js",
        "watch": false
    }, {
        "name": "appB",
        "script": "./appB.js",
        "watch": false
    }]
}
# 再执行:
$ pm2 start server.json
-----------------------------
# 重命名进程/应用
pm2 start app.js --name 项目名称

# 结束进程/应用
pm2 stop 项目名称

# 结束所有进程/应用
pm2 stop all

# 删除进程/应用 pm2
pm2 delete 项目名称

# 删除所有进程/应用
pm2 delete all

# 列出所有进程/应用
pm2 list

# 查看某个进程/应用具体情况
pm2 describe 项目名称

# 查看进程/应用的资源消耗情况
pm2 monit

# 查看pm2的日志
pm2 logs 序号/名称

# 若要查看某个进程/应用的日志,使用
pm2 logs 项目名称

# 重新启动进程/应用
pm2 restart 项目名称

# 重新启动所有进程/应用
pm2 restart all

Guess you like

Origin blog.csdn.net/qq_36821274/article/details/129186688