preface

Due to the recent change of a new company, no interface document system was used in the front and back end docking, but only TXT or Word files were thrown directly. In order to improve the development efficiency, I tried to use YApi for interface document management.

YApi is designed to provide more elegant interface management services for developers, products, and testers. It can help developers easily create, publish, and maintain apis. Supports permissions control, visual interface management, mock interfaces, automated tests, data import, and plug-in mechanisms. At the same time, it supports Intranet deployment. The project is maintained by the Front-end technology Center of Qunar, and developed with the FRAMEWORK of Koa + Mongoose. It is friendly to the front-end in both deployment and configuration, so let’s start the whole process next.

Environment to prepare

Since YApi is developed based on Node and the data is stored in the mongodb database, node and MondoDB need to be installed on the server before installation.

Mongo installation

  • I can download the mongodb package directly

  • Download it and decompress it on the server

Tar - XVF mongo - Linux - x86_64 - ubuntu2004-4.4.5Copy the code
  • Decompress it and rename it
Mv mongo - Linux - x86_64 - ubuntu2004-4.4.5 / mongoCopy the code
  • Move the mongodb folder to /usr/local
mv mongodb /usr/local
Copy the code
  • Adding environment variables
sudo vim /etc/profile
Copy the code
  • Add the following and save it
export PATH=/usr/local/mongodb/bin:$PATH
Copy the code
  • Put the change into effect
source /etc/profile
Copy the code
  • Create a folder for storing data and log files and modify its permissions to add read and write permissions
/var/log/mongodb sudo mkdir -p /var/lib/mongodb sudo chown 'whoami' /var/lib/mongo Sudo chown 'whoami' /var/log/mongodbCopy the code
  • Add the configuration file to /usr/local/mongodb/bin
#Directory for storing data files
dbpath = /var/lib/mongo
#Directory for storing log files
logpath = /var/log/mongodb/mongodb.log
#port
port = 27017
#Whether to authenticate or not will be changed latertrue
auth = false
#Specify an IP address for remote connection or the connection will fail. 0.0.0.0 does not restrict IP access and enables the corresponding portBind_ip = 0.0.0.0Copy the code

Nodejs installation

Here I use a compressed package to install. In fact, it is more convenient to use ubuntu’s own command to install, as follows:

Apt-get install NPM install pm2 install pm2 install pm2 install pM2 install pM2 install pM2 install pM2 install pM2 install PM2 Run pm2 -v to check whether the installation is successful. Sudo NPM install -g pm2Copy the code

Because compressed packages are used, soft links need to be configured when NPM, PM2, and N are installed. Therefore, compressed packages are not recommended.

  • To download the nodeJS installation package, click here to download it

  • Download it and unzip it on the server:

The tar XVF - node - v14.16.1 - Linux - x64. Tar. XzCopy the code
  • Unzip and rename the folder:
Node - mv v14.16.1 - Linux - x64 nodejsCopy the code
  • Move the nodejs folder to /usr/local
mv nodejs /usr/local
Copy the code
  • Adding soft Links
ln -s /usr/local/nodejs/bin/node /usr/local/bin
ln -s /usr/local/nodejs/bin/npm /usr/local/bin
Copy the code
  • Check whether the installation is successful
node -v
npm -v
Copy the code

  • Install pM2 and n for management
npm install -g pm2
npm install -g n
Copy the code
  • Adding soft Links
ln -s /usr/local/nodejs/bin/pm2 /usr/local/bin
ln -s /usr/local/nodejs/bin/n /usr/local/bin
Copy the code
  • Check whether the installation is successful
n -V
pm2 -v
Copy the code
  • Successful installation

Do not install a too late version of Node when installing yAPI, because the later installation of yAPI will cause an error, so install around 10.x.

Start the mongo

Run the usr/local/mongodb/bin command to start the mongodb service.

./mongod -f mongodb.conf --fork
Copy the code
  • Configuring password Login

Run the mongo command to go to the shell and run the following command to create an administrator user

Roles: [{role: "userAdminAnyDatabase", db: "admin"}]})#The user name and password are admin and created for the admin databaseDb.auth ('admin','adminpassword') #Copy the code

In this case, the creation is successful

  • In the configuration file open access authentication, open/usr/local/mongo/bin/mongo. Conf file will auth set to true

  • Shut down the mongodb service and enable it again to connect to mongodb using the password
./mongod -f mongodb.conf --shutdown
./mongod -f mongodb.conf --fork
Copy the code

Install yapi

YApi officially provides two deployment modes: visual deployment and command line deployment. The visual deployment mode starts a Node service on the server and automatically deploys the service after the browser fills in relevant configurations as required. The command line deployment mode modifies the configuration file and deploys the service. For details, see here

npm install -g yapi-cli --registry https://registry.npm.taobao.org
Copy the code
  • Add soft links (this needs to be done again because of the way node was installed)
ln -s /usr/local/nodejs/bin/yapi /usr/local/bin
Copy the code
  • Run yapi server to start the installation service. The default port is 9090

  • Enable port 9090 on the firewall and enter http://ip:9090 in the browser to start the installation

  • During the installation process, the user name and password of mongodb database are required. We established the user name and password of admin database before, because we need to establish another password of YAPI database

Roles: [{user:"admin", PWD :" adminyAPI ", roles: [{user:"admin", db: "adminyAPI "}]})#The user name is admin and the password is AdminyAPI. The user name is created for the yAPI databaseDb.auth ('admin',' adminyAPI ') #Copy the code
  • After the establishment can be installed, database address fill in the server IP, other according to their own situation can be filled in. Here I use Navicat to log in to the database. Authentication means which database you want to connect to.

  • After the installation is complete, visit http://ip:3000 to register and log in to use

Note: Remember the security group start ports 9090, 3000, and 27017 for the server

conclusion

The overall installation process is relatively simple, the official scaffolding is also very convenient to use, the trouble is the installation and configuration of mongodb, but if you use skilled words there is no problem.

reference

  • Official use document: hellosean1025. Making. IO/yapi/docume…
  • The official deployment document: hellosean1025. Making. IO/yapi/conversation…
  • Environment set up document: zhuanlan.zhihu.com/p/95880755