search
HomeOperation and MaintenanceCentOSProblem records related to centos deployment of yapi

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

    or Curl

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

       source   ~/.bashrc
  • Verify installation

       command -v nvm
  • View remote node version

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

       nvm install 10.2.1

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 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
  • Install mongodb

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

               vi /etc/mongod.conf
  • Start mongodb

           systemctl start mongod.service  // 启动mongodb

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" } ]
  }
)

## 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配置的端口},初次运行会有个编译的过程,请耐心等候

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
  • Switch to the vendors directory of yapi and execute pm2 start

         pm2 start server/app.js  --watch

Problem records related to centos deployment of yapi

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

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)
  • 成功开启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
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
CentOS's Replacement: Exploring the New OptionsCentOS's Replacement: Exploring the New OptionsApr 28, 2025 am 12:17 AM

CentOS alternatives include RockyLinux, AlmaLinux, and OracleLinux. 1. RockyLinux and AlmaLinux provide stable distributions compatible with RHEL, suitable for users who need long-term support. 2. CentOSStream is suitable for users who focus on new features and development cycles. 3. OracleLinux is suitable for users who need enterprise-level support.

Replacing CentOS: Identifying Suitable ReplacementsReplacing CentOS: Identifying Suitable ReplacementsApr 27, 2025 am 12:04 AM

CentOS needs alternatives because CentOSStream no longer provides long-term support. Alternative options include: 1. RockyLinux, which provides 10 years of life cycle support, suitable for users who need stability. 2.AlmaLinux also provides 10 years of support and has strong community support. 3. OracleLinux, provides RHEL-compatible version, and flexible life cycle management.

The End of CentOS: Evaluating the ImpactThe End of CentOS: Evaluating the ImpactApr 26, 2025 am 12:03 AM

The end of CentOS has had a significant impact on users, with users having the option of RHEL, AlmaLinux, Debian or Ubuntu as alternatives. 1. The migration cost is high, requiring time and money. 2. Community division affects open source projects. 3.RHEL provides commercial support, but it is costly. 4.AlmaLinux is similar to CentOS and has low migration costs. 5. Debian and Ubuntu need more time to adapt.

CentOS: An Explanation of the Decision-Making ProcessCentOS: An Explanation of the Decision-Making ProcessApr 25, 2025 am 12:03 AM

CentOS is suitable as an enterprise-class server operating system because it is stable, secure and free. 1) It is based on RHEL and provides high compatibility with RHEL. 2) Use yum for package management to ensure that the software is easy to install and update. 3) The community regularly releases security patches, with a support cycle of up to 10 years.

The Discontinuation of CentOS: Understanding the FactorsThe Discontinuation of CentOS: Understanding the FactorsApr 24, 2025 am 12:01 AM

The reason why CentOS stopped maintaining is RedHat's strategic change. User response strategies include: 1. Migrating to other distributions, such as UbuntuServer, Debian or RockyLinux; 2. Continue to use CentOS7 until June 2024; 3. Turning to CentOSStream; 4. Build solutions, such as custom distributions based on RHEL or using container technology.

CentOS: What Led to the Decision to End SupportCentOS: What Led to the Decision to End SupportApr 23, 2025 am 12:10 AM

RedHatendedsupportforCentOStoshifttowardsacommerciallyfocusedmodelwithCentOSStream.1)CentOStransitionedtoCentOSStreamforRHELdevelopment.2)ThisencourageduserstomovetoRHEL.3)AlternativeslikeAlmaLinux,RockyLinux,andOracleLinuxemergedasreplacements.

Using CentOS: A Guide for System AdministratorsUsing CentOS: A Guide for System AdministratorsApr 22, 2025 am 12:04 AM

CentOS is an open source operating system based on RedHatEnterpriseLinux, suitable for server environments. 1. Select the appropriate media and options during installation and configure network, firewall and user permissions. 2. Use useradd, usermod and systemctl commands to manage users and services, and update software packages regularly. 3. Basic operations include using yum installation software and systemctl management services, and advanced features such as SELinux to enhance security. 4. Check the system log to solve common errors. Optimizing performance requires monitoring resources and cleaning of unnecessary files.

CentOS: Security, Stability, and PerformanceCentOS: Security, Stability, and PerformanceApr 21, 2025 am 12:11 AM

CentOS is the first choice for server and enterprise environments for its superior security, stability and performance. 1) Security provides forced access control through SELinux to improve system security. 2) Stability is supported by the LTS version for up to 10 years to ensure the stability of the system. 3) Performance significantly improves system response speed and resource utilization by optimizing kernel and system configuration.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor