How to Deploy Yapi API Management Platform on CentOS: Step‑by‑Step Guide
This article provides a comprehensive, step‑by‑step tutorial for installing and configuring the Yapi API management platform on a CentOS 7.6 server, covering system prerequisites, Node.js and MongoDB setup, environment configuration, deployment commands, and common error troubleshooting.
1. Yapi Overview
Yapi is a high‑efficiency, easy‑to‑use API management platform designed for developers, product managers and testers to provide elegant interface management services.
Key features include visual interface management, data mocking, automated interface testing, data import (Swagger, HAR, Postman, JSON, CLI), permission management, support for local deployment, plugins, and secondary development.
2. System Environment
OS version: CentOS 7.6
MongoDB version: 3.2.22
Node.js version: 9.8.0
Git version: 1.8.3
3. System Environment Configuration
1) Configure Alibaba Cloud yum repository:
cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
EOF2) Disable and stop firewalld:
systemctl disable firewalld && systemctl stop firewalld3) Temporarily and permanently disable SELinux:
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config4) Flush iptables rules:
iptables -X && iptables -F && iptables -Z4. Deploy Node.js Environment
1) Download and extract Node.js 9.8.0:
cd /opt
wget https://nodejs.org/dist/v9.8.0/node-v9.8.0-linux-x64.tar.xz
xz -d node-v9.8.0-linux-x64.tar.xz
tar -xf node-v9.8.0-linux-x64.tar2) Create symbolic links:
cd node-v9.8.0-linux-x64
ln -s /opt/node-v9.8.0-linux-x64/bin/node /usr/local/bin/node
ln -s /opt/node-v9.8.0-linux-x64/bin/npm /usr/local/bin/npm3) Verify versions and switch npm registry:
node -v
npm -v
npm config set registry https://registry.npm.taobao.org5. Deploy Git
yum install git -y6. Install and Deploy MongoDB
1) Add MongoDB repository:
cat >> /etc/yum.repos.d/mongodb-org.repo <<EOF
[mongodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1
EOF2) Install MongoDB: yum install -y mongodb-org 3) Modify configuration to listen on all interfaces: sed -i s/127.0.0.1/0.0.0.0/g /etc/mongod.conf 4) Enable service at boot and start:
chkconfig mongod on
systemctl start mongod5) Verify port 27017 is listening:
ss -tunl | grep 270177. Install and Deploy Yapi
npm install -g yapi-cli --registry https://registry.npm.taobao.org
/opt/node-v9.8.0-linux-x64/bin/yapi serverFollow the command‑line prompts, then access the deployment page in a browser at http://{IP}:{PORT} (default port 3000). Provide company name, deployment path, admin email, and other required information.
8. Common Errors and Fixes
If “Cannot find module 'fs‑extra'” appears, run: npm install --save fs-extra If “Cannot find module 'nodemailer'” appears, run: npm install nodemailer --save For MongoDB deprecation warning, add in /etc/my-yapi/vendors/server/utils/db.js line 19: mongoose.set('useUnifiedTopology', true); If “init.lock file already exists” error occurs, remove the lock file: rm -y init.lock If duplicate admin account error occurs, delete the admin user from the database:
mongo
use yapi;
db.user.remove({"username":"admin"});Then rerun the installation script:
node server/install.js9. Start Service and Access
Start the Yapi server:
cd /etc/my-yapi/vendors
node server/app.jsOpen the URL http://{IP}:{PORT} in a browser, log in with the admin credentials displayed in the console.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
