I’ve deployed easy-Mock myself, and I’ve devoted my entire blog to it, but I haven’t committed easy-Mock effectively in over two years, and most importantly, Easy-mock has no support for [email protected] and above, so I looked for other Api management/mock platform YApi and decided to switch to YApi in the future. I deployed YApi on my own server and will use it from now on.

CentOS version: 7.6

Nginx version: 1.16.1

Yapi version: 1.19.1

MongoDB version: 4.2.6

1. The mongo configuration

1.1 Configuring YUM and installing MongoDB

MongoDB is not the same as many other software installed directly with yum, it can not be installed directly with the MongoDB version, this way is very low, you need to configure the yum:

# create yum configuration fileVim/etc/yum. Repos. D/mongo - org - 4.2. RepoEnter the following content in the file and exit from the :wq file[mongo - org - 4.2] name = mongo Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/ mongo - org / 4.2 / x86_64 / gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc gpgcheck = 1 enabled = 1You can use yum to install
yum install -y mongodb-org
Copy the code

1.2 MongoBD Common commands

systemctl start mongod.service        # open mongo
systemctl enable mongod               # Self-start after startup
systemctl list-unit-files|grep mongod # Check whether MongoDB starts from startup

service mongod restart          # to restart
service mongod stop             # stop
service mongod start            # run

rpm -ql mongodb-org-server      # Check MongoDB related files
Copy the code

1.3 mongo configuration

We then modified the configuration file to make MongoDB accessible externally

# Modify MongoDB configuration file
vim /etc/mongod.conf

# find here, modify :wq
net:
  port: 27017
  bindIp: 0.0.0.0    # is 127.0.0.1, only allow local connection, change 0.0.0.0 allow external connections, if you won't have to change only need local connection
  
security:            # Enable authentication for security
  authorization: "enabled"   # disable or enabled

  
Save and restart the service
service mongod restart
Copy the code

After changing the configuration, go to < your server address >:27017 on the web page. If you do not change bindIp, only local connections can be made.

If you visit Mongod with the following situation:

Mkdir /data/db = /data/db = /data/db

1.4 uninstall mongo

The uninstallation method is retained here, and MongoDB may be installed in other ways in the future:

systemctl disable mongod # Stop the startup
service mongod stop      # Stop service
sudo yum erase $(rpm -qa | grep mongodb-org)   Delete the installation package

sudo rm -r /var/log/mongodb     Delete log files
sudo rm -r /var/lib/mongo       Delete data files
Copy the code

2. Yapi installation and deployment

2.1 Local Deployment

First install the official yapi-CLI tool, and install pM2 can be used to start the service when the daemon and management process:

npm install -g yapi-cli pm2 --registry https://registry.npm.taobao.org
yapi server
Copy the code

Then I configure it visually, which I do as follows:

Click “Start deployment” to start the Yapi deployment process. After two or three minutes of waiting, I see the last few lines prompt the administrator account name and password, which is useful to write down later

then

cd< Deployment path >/usr/share/ my-yapi
node vendors/server/app.js  # run

Yapi will restart automatically if the memory limit of 200MB is exceeded
pm2 start /usr/share/my-yapi/vendors/server/app.js -n yapi --max-memory-restart 500M
pm2 stop yapi        # pm2 stop
pm2 list             # pm2 Check the running status
Copy the code

At this point, you can see the script status of pM2:

Now go to your browser and go to < your server IP >:9001 (note that the port is the one you just set) to access the Yapi service directory, which looks similar to the official website

This completes the local deployment ~ 👏

Register a new account, log in, and you can use it normally.

2.2 Installing the Cross-Request Plug-in

After installing Yapi, you also need to install a cross-request plug-in in your browser to make cross-domain page requests.

First we go to the https://github.com/YMFE/cross-request warehouse, download and unzip the zip bag.

Then choose More Tools from the three-dot menu in the upper right corner of Chrome -> Extensions -> Load extensions to decompress -> select the contents of the compressed package, making sure to open developer mode in the upper right corner first.

Then view the interface -> run to send the command ~

⚠️ Note: after installation, the decompressed plug-in folder cannot be deleted!!

For later use, you can refer to the official document: YApi- Tutorials

Just to mention, I found a bit of a problem importing the Swagger2.0 interface documentation into Yapi 😅, Swagger2.0: Swagger2.0: Swagger2.0: Swagger2.0: Swagger2.0: Swagger2.0: Swagger2.0


Most of the online posts are different in depth, and even some inconsistent, the following article is a summary of the learning process, if you find mistakes, welcome to leave a message to point out ~

Reference documents:

  1. Install MongoDB Community Edition on Red Hat or CentOS — MongoDB Manual
  2. Install MongoDB for Linux Centos 7. Detailed!

PS: MY blog address Github – SHERlocked93/blog, also welcome everyone to pay attention to my public number [front afternoon tea], refuting together ~

In addition, you can join the wechat group of “front end afternoon tea Communication Group”. Long press to identify the qr code below to add my friend, note to add group, I pull you into the group ~