Quickly build YApi interface management platform under Linux

1. Preamble

In order for team members to cooperate better, we are going to build an interface management platform. I have been using it before YApi, and this time I am going to deploy an Yapiinstance by hand. YApiIt is a front-end project. Because I have been doing background development, I stepped on some small pits during deployment. I hereby record it.



2. Install Node

YapiIt is a Node project. The first big pitfall encountered here is the version problem. I tried Node v16 and v14 versions in the middle, and found that they could not be used. Finally, I found that it is possible to install Node v12 version.

nvmIt is strongly recommended to use to install Node here nvm. It is a version manager of Node, which can switch Node versions freely. The front end is not like the back end. Sometimes different Node versions are applicable to different projects. If the version is wrong, the mentality will collapse.


1. Install nvm

Just run the installation script directly on Linux, as follows:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Please refer to the specific address, nvm installation and update instructions .

Remarks: The installation may be a little slow, just wait patiently.


2. Use a compatible Node version

(1) List all versions of Node that can be installed

nvm ls-remote

(2) Install a Node version suitable for yapi, here select v12.22.12

nvm install v12.22.12

(3) View the currently installed Node version

nvm list

The following are the Node versions I currently have installed, there are v14.20.0 and v12.22.12 .

->    v12.22.12
       v14.20.0
default -> v12.22.12
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v14.20.0) (default)
stable -> 14.20 (-> v14.20.0) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12
lts/fermium -> v14.20.0
lts/gallium -> v16.16.0 (-> N/A)

(4) Switch to the specified Node version

nvm use default
或者
nvm use v12.22.12

(5) View the currently used Node version

node -v


2. Install MongoDB

1. Download MongoDB

YapiThe data storage is selected , so we have to deploy a Mongo instance Mongo DBbefore initializing Yapi . The Mongo DB version I installed here is 4.4.15, just run the following command directly:

wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-v4.4-latest.tgz

Then unzip it again:

tar xzf mongodb-linux-x86_64-rhel70-v4.4-latest.tgz

2. Configure MongoDB

(1) Create a new related directory under the MongoDB decompression directory

mkdir conf data logs

Remarks: conf is the configuration file directory, data is the data directory, and logs is the log directory.

(2) Add a configuration file mongod.conf under the conf directory

touch mongod.conf

The content of the configuration file is as follows:

systemLog:
   destination: file
   path: "/mongodb-4.4.15/logs/mongodb.log" # 日志目录
   logAppend: true
net:
   bindIp: 127.0.0.1 # 绑定的ip
   port: 27017 # 服务端口
   unixDomainSocket:
      enabled: false # 如果开启,下面的pathPrefix配置得加上,不然会写在/tmp目录下
      pathPrefix: "/mongodb-4.4.15/conf" 
storage:
   dbPath: "/mongodb-4.4.15/data" # 数据目录

Remarks: For more information about Mongo DB configuration items, please refer to, MongoDB 4.4 version configuration option description .

(3) Start MongoDB

Go to the bin directory where MongoDB is installed and run the following command.

./mongod -f /mongodb-4.4.15/conf/mongod.conf &

(4) Connection test

Run the following command directly in the bin directory.

./mongo

After the connection is successful, the display is as follows:

insert image description here



3. Install YApi

Directly use the visual installation recommended by the official website, the official website address is: Yapi official website. Just enter the following command:

# 安装yapi
npm install -g yapi-cli --registry https://registry.npm.taobao.org
# 启动服务
yapi server 

After startup, there will be a prompt, just open the browser access http://ip:9090port, and the following interface will appear:
insert image description here
After clicking to start deployment, an interface will pop up, which displays the log information of the application deployment, and the same log information will also appear on the shell terminal.

After the deployment is successful, it will prompt how to start the service, just execute the following command:

node /yapi/vendors/server/app.js

Remarks: My deployment path is /opt/appl/yapi, the soft link is yapi -> /opt/appl/yapi, the above startup method is foreground startup, and the service will terminate after pressing Ctrl + C. For how to start Node.jsthe application in the background, please read later.



4. Install PM2 to manage Node service

PM2It is Node.jsthe background process manager of the application, with a built-in load balancer, which can realize non-stop loading and help us better manage and maintain background applications.

In addition to managing Node.jsapplications, it can also manage any other executable scripts and binaries, as follows:

$ pm2 start bashscript.sh
$ pm2 start python-app.py --watch
$ pm2 start binary-file -- --port 1520

Note: For more commands and parameters, please refer to PM2 official website .

(1) Start the yapi service

pm2 start /yapi/vendors/server/app.js --name yapi --log /yapi/log/yapi.log
  • --name: Specify the application name.
  • --log: Specifies the log file.

Remarks: The applications managed by pm2 will start in the background.

(2) View service status

pm2 status

The displayed content is as follows:

insert image description here

(3) Termination of service

pm2 stop /yapi/vendors/server/app.js


5. Log in to the YApi background

Enter in the browser http://ip:9000to enter the login page. The default administrator username is the administrator mailbox we specified during deployment, namely: [email protected], and the default password is: ymfe.org.

Note: The initial password can be modified in the personal center.

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/lingbomanbu_lyl/article/details/125869152