YApi-Efficient, easy-to-use, powerful visual interface management platform - (1) Local deployment using Docker

This content takes the virtual machine [system: Centos7] as an example, and the steps of the cloud server are the same. Use Docker to build YApi, just pull the MongoDB image and YApi image.

Install Docker

Install

  1. The yum package is updated to the latest:

    yum update
    
  2. Install the required software packages, yum-util provides yum-config-manager function, and the other two are devicemapper driver dependencies:

    yum install -y yum-utils device-mapper-persistent-data lvm2
    
  3. Set the yum source to Alibaba Cloud:

    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
  4. Install Docker Community Edition:

    yum -y install docker-ce
    
  5. Check the Docker version number:

    docker -v
    

Set up USTC mirror

  1. Edit /etc/docker/daemon.jsonfile:

    mkdir -p /etc/docker
    vim /etc/docker/daemon.json
    

    Note: Install vim via yum: yum -y install vim*.

  2. daemon.jsonEnter the following in the file :

    {
          
          
    "registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
    }
    

start docker

  1. start docker

    systemctl start docker
    
  2. stop docker

    systemctl stop docker
    
  3. View docker status

    systemctl status docker
    
  4. Set up to automatically start docker at boot

    systemctl enable docker
    

Docker install MongoDB

Create a mongo container data mount directory:

mkdir /usr/local/mongo

Pull the MongoDB 4.2.21 version Docker image:

docker pull mongo:4.2.21

Create a web plugin for yapi:

docker network create yapi

Start the MongoDB container, specify the network plug-in, map port, mount directory, initial database yapi, root account password:

#启动MongoDB容器
docker run -d \
  --name mongodb \
  --restart always \
  --net=yapi \
  -p 2717:27017 \
  -v /usr/local/mongo:/data/db \
  -e MONGO_INITDB_DATABASE=yapi \
  -e MONGO_INITDB_ROOT_USERNAME=root \
  -e MONGO_INITDB_ROOT_PASSWORD=root \
  mongo:4.2.21

Enter the MongoDB container:

docker exec -it mongodb /bin/bash

Switch the admin database:

use admin;

Authenticate with the root account password:

db.auth("root	", "root");

Switch yapi database:

use yapi;

Create a user: yapi, and grant operational permissions:

db.createUser({
    
    
  user: 'yapi',
  pwd: 'yapi123456',
  roles: [
 {
    
     role: "dbAdmin", db: "yapi" },
 {
    
     role: "readWrite", db: "yapi" }
  ]
});

Execute the exit command twice to exit to the terminal:

exit

Docker install YApi

Create a local configuration file config.jsonfor container mounting:

vim /usr/local/yapi/config.json

Add the following:

{
    
    
   "port": "3000",
   "adminAccount": "****@qq.com", // 管理员账号名,用于登录
   "timeout":120000,
   "db": {
    
    
     "servername": "mongo",
     "DATABASE": "yapi",
     "port": 27017,
     "user": "yapi",
     "pass": "yapi123456",
     "authSource": ""
   },
   "mail": {
    
     // 邮箱功能
     "enable": true,
     "host": "smtp.qq.com",
     "port": 465,
     "from": "****@qq.com",
     "auth": {
    
    
       "user": "****@qq.com",
       "pass": "****password"
     }
   }
 }

Note: db.user and db.pass are the username and password of mongodb. If mongo authentication is not enabled, please delete these two options.

Docker search query yapi image:

docker search yapi

image-20230707124701866

The pull command pulls the image:

docker pull yapipro/yapi

image-20230707124737640

Initialize the yapi database table:

docker run -d --rm \
  --name yapi-init \
  --link mongodb:mongo \
  --net=yapi \
  -v /usr/local/yapi/config.json:/yapi/config.json \
   yapipro/yapi \
  server/install.js

Start the yapi container, specify the container name, port number, and mount the configuration file /usr/local/yapi/config.json:

docker run -d \
   --name yapi \
   --link mongodb:mongo \
   --restart always \
   --net=yapi \
   -p 3000:3000 \
   -v /usr/local/yapi/config.json:/yapi/config.json \
   yapipro/yapi \
   server/app.js

Login to YApi

Access URL [ http://192.168.1.14:3000/ ]:

image-20230707135904997

Login with account password:

image-20230707140011028

Note: Initialize the value of adminAccount in the config.json configuration above to initialize the administrator account. The initial password is yapi.pro, which can be modified in the personal center after logging in.

Guess you like

Origin blog.csdn.net/qq_20185737/article/details/131595835