Table of Contents
Preface
Installing node
Install mongdb
Summary
① Failed to obtain mongdb authentication
② PM2 failed to start yapi and kept restarting
③The configured mailbox fails
不足之处欢迎拍砖指正!
yapi开启https访问
Home Operation and Maintenance CentOS Problem records related to centos deployment of yapi

Problem records related to centos deployment of yapi

Jul 10, 2021 pm 04:12 PM
centos

Preface

In the past few days, I finally completed a three-month demo version project of the company. During this period, I had countless arguments with the company's backend about the API.' There is no problem with my interface, but the way you requested is wrong! ', 'The parameters you requested must be wrong'... Problems like these have persisted throughout the past three months, just because we don't have good interface management habits, a bunch of trouble-free tools have not been used, and the interface definition is very random. Basically conveyed verbally. Therefore, I think the YApi interface management platform must be used first. Furthermore, Zhang Xinxu is also calling for interface management, and the front-end should also use the tools. Liberate productivity and improve efficiency!

Installing node

Because the installation of Yapi must rely on node, Google the various methods of installing node in the centos environment, and there are thousands of them. But I still stepped on a trap. I don’t know why my method of installing the source code based on wget failed. Of course, it was not a complete failure. It was when I waited too long during make, so I directly ctrl c. It’s better to use nvm to install it, although I don’t know if it is reasonable. Please speak with the code:

  • Wget download and install nvm

       wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
    Copy after login

    or Curl

       curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
    Copy after login
  • Join the system environment after the download is complete

       source   ~/.bashrc
    Copy after login
  • Verify installation

       command -v nvm
    Copy after login
  • View remote node version

       nvm ls-remote
    Copy after login
  • Install the required version required nodejs ( 7.6)

       nvm install 10.2.1
    Copy after login

Install mongdb

Yapi relies on mongodb (2.6, theoretically you can configure remote mlab, install centos mongdb here, the premise is to ensure that centos is 64 bit.
There are thousands of similar installation methods. Here, use yum to install

  • Modify the yum package management configuration

               vi /etc/yum.repos.d/mongodb-org-3.4.repo   // 会自动新建mongodb-org-3.4.repo文件
    Copy after login
  • Copy The following configuration information:

               [mongodb-org-3.4]
               name=MongoDB Repository
               baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
               gpgcheck=0
               enabled=1
    Copy after login
  • Install mongodb

               yum install -y mongodb-org   // 一路yes安装mongodb
    Copy after login
  • Modify mongdb configuration (public network accessible: 127.0.0.1 => 0.0.0.0 )

               vi /etc/mongod.conf
    Copy after login
  • Start mongodb

           systemctl start mongod.service  // 启动mongodb
    Copy after login

If it is an Alibaba Cloud server, add port 12071 to the security group to access it through the public address. Of course it is not safe at this time

Problem records related to centos deployment of yapi

Anyone can tamper with your data by connecting to your mongdb data. Try adding verification at this time. There are thousands of methods here, please google by yourself, for example:

mongo --port 27017

use admin

db.createUser(
  {
    user: "adminUser",
    pwd: "adminPass",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
Copy after login

## Deploy yapi
According to the official documentation, there are two deployment methods. In view of the fact that I used the first one on my computer a few days ago The first method failed to install, so I used the second more complicated method

mkdir yapi
cd yapi
git clone https://github.com/YMFE/yapi.git vendors //或者下载 zip 包解压到 vendors 目录
cp vendors/config_example.json ./config.json //复制完成后请修改相关配置
cd vendors
npm install --production --registry https://registry.npm.taobao.org
npm run install-server //安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
node server/app.js //启动服务器后,请访问 127.0.0.1:{config.json配置的端口},初次运行会有个编译的过程,请耐心等候
Copy after login

At this time, it was only temporarily deployed successfully, and the yapi process must be permanently guarded. pm2 is used here

  • Install pm2

         npm i pm2 -g
    Copy after login
  • Switch to the vendors directory of yapi and execute pm2 start

         pm2 start server/app.js  --watch
    Copy after login

Problem records related to centos deployment of yapi

正常的话,应该能正常访问到,默认接口是3000
Copy after login

Problem records related to centos deployment of yapi

Summary

At this point, you have cloned the source code of yapi to your own intranet. Of course, you will still encounter a lot of pitfalls during the process. I The main pitfalls encountered are mongdb authentication pitfalls: such as unsuccessful authentication settings, incorrect config file configuration, and even pm2 failure to start Yapi. In short, try more and take more hands-on work. If you really can't solve it yourself, then ask the experts for advice.

① Failed to obtain mongdb authentication

Problem records related to centos deployment of yapi

Solution: Check whether the mongdb configuration is correct, whether the authentication setting is successful, and whether the yapi config file is configured correctly

② PM2 failed to start yapi and kept restarting

Problem records related to centos deployment of yapi

Solution: Use pm2 log to check that the service previously started through npm has not ended, resulting in port occupation. Just use the service before ctrl c
The first two problems don’t seem to be pitfalls, they are just roadblocks

③The configured mailbox fails

Problem records related to centos deployment of yapi

Solution: It must be that the mailbox configuration is incorrect. , come back! Then I continued to mine
I wasn’t sure if there was something wrong with the NetEase mailbox or something. Just change it to QQ. After modifying the config.json file, I thought everything would be fine if I re-npm run install-server. In fact-->

Problem records related to centos deployment of yapi

It should be that the administrator's information already exists in yapi in mongdb. If there is no data under admin, just delete it directly. If there is any, just modify the data. I was very lazy, so I just used mongdb compass to delete the entire Yapi. I deleted the database and ran away!

不足之处欢迎拍砖指正!

Problem records related to centos deployment of yapi

yapi开启https访问

虽然对小白来说https然并卵,我还是想捣鼓一下试着通过https来访问我的yapi,首先证书我是有了,获取证书的方法也有千千万万种,我这里用的阿里云的免费证书,总之有证书的话应该能拿到证书文件如.pem、.key、.pfx之类文件。技术菜的我天真的以为还能开启3000端口的https访问,结果啪啪啪打脸打的很清脆,于是乎把https的端口设定成了8443。大概步骤如下:

  • 获取证书文件(默认有证书并且能拿到.key和.pem文件或者.pfx文件)

    Problem records related to centos deployment of yapi

  • 上传证书(我直接放在app.js同级,根据个人喜好)

    Problem records related to centos deployment of yapi

  • 修改app.js 是基于koa的 不过我没有再引用koa-ssl,直接用的node的https方法的第一种

    // 引入相关的服务和文件
    const fs = require('fs');
    const https = require('https');
    const options = {
        key: fs.readFileSync(__dirname + '/server.key'),
        cert: fs.readFileSync(__dirname + '/server.pem')
      };
    const port = 8443;
    //...
    //开启https端口
    https.createServer(options, app.callback()).listen(port)
    Copy after login
  • 成功开启https

    Problem records related to centos deployment of yapi

  • 同样还是踩了不少坑

    • 文件径不对 not such file
      解决:用__dirname
    • mac verify failure
      解决: 用node https提供的第一种方法引入证书文件

推荐:《centos教程

The above is the detailed content of Problem records related to centos deployment of yapi. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to input Chinese in centos How to input Chinese in centos Apr 07, 2024 pm 08:21 PM

Methods for using Chinese input in CentOS include: using the fcitx input method: install and enable fcitx, set shortcut keys, press the shortcut keys to switch input methods, and input pinyin to generate candidate words. Use iBus input method: Install and enable iBus, set shortcut keys, press the shortcut keys to switch input methods, and input pinyin to generate candidate words.

How to read USB disk files in centos7 How to read USB disk files in centos7 Apr 07, 2024 pm 08:18 PM

To read U disk files in CentOS 7, you need to first connect the U disk and confirm its device name. Then, use the following steps to read the file: Mount the USB flash drive: mount /dev/sdb1 /media/sdb1 (replace "/dev/sdb1" with the actual device name) Browse the USB flash drive file: ls /media/sdb1; cd /media /sdb1/directory; cat file name

How to enter root permissions in centos7 How to enter root permissions in centos7 Apr 02, 2024 pm 08:57 PM

There are two ways to enter the root authority of CentOS 7: use the sudo command: enter sudo su - in the terminal and enter the current user password. Log in directly as the root user: Select "Other" on the login screen, enter "root" and the root password. Note: Operate carefully with root privileges, perform tasks with sudo privileges, and change the root password regularly.

SCP usage tips-recursively exclude files SCP usage tips-recursively exclude files Apr 22, 2024 am 09:04 AM

One can use the scp command to securely copy files between network hosts. It uses ssh for data transfer and authentication. Typical syntax is: scpfile1user@host:/path/to/dest/scp -r/path/to/source/user@host:/path/to/dest/scp exclude files I don't think you can when using scp command Filter or exclude files. However, there is a good workaround to exclude the file and copy it securely using ssh. This page explains how to filter or exclude files when copying directories recursively using scp. How to use rsync command to exclude files The syntax is: rsyncav-essh-

What to do if you forget your password to log in to centos What to do if you forget your password to log in to centos Apr 07, 2024 pm 07:33 PM

Solutions for forgotten CentOS passwords include: Single-user mode: Enter single-user mode and reset the password using passwd root. Rescue Mode: Boot from CentOS Live CD/USB, mount root partition and reset password. Remote access: Use SSH to connect remotely and reset the password with sudo passwd root.

What should I do if I forget my centos username and password? What should I do if I forget my centos username and password? Apr 02, 2024 pm 08:54 PM

After forgetting your CentOS username and password, there are two ways to restore access: Reset the root password: Restart the server, edit the kernel command line in the GRUB menu, add "rw init=/sysroot/bin/sh" and press Ctrl+x ;Mount the root file system and reset the password in single-user mode. Use rescue mode: Start the server from the CentOS installation ISO image, select rescue mode; mount the root file system, copy the chroot environment from the ISO image, reset the password, exit the chroot environment and restart the server.

How to enable root permissions in centos7 How to enable root permissions in centos7 Apr 07, 2024 pm 08:03 PM

CentOS 7 disables root permissions by default. You can enable it by following the following steps: Temporarily enable it: Enter "su root" on the terminal and enter the root password. Permanently enabled: Edit "/etc/ssh/sshd_config", change "PermitRootLogin no" to "yes", and restart the SSH service.

What should I do if I forget my centos7 password? What should I do if I forget my centos7 password? Apr 02, 2024 pm 08:51 PM

Three solutions for forgotten passwords in CentOS 7: Single-user mode: Restart the system, edit the kernel options, change ro to rw init=/sysroot/bin/sh, and use the passwd command to reset the root password. Rescue mode: Boot from the installation media, select rescue mode, mount the root file system, chroot to the root file system, and use the passwd command to reset the root password. Grub2 command line: Restart the system, press c to enter the command line, load the kernel, mount the root file system, chroot to the root file system, and use the passwd command to reset the root password.

See all articles