CentOS7 install YApi


Environmental requirements

  • nodejs (7.6+)
  • mongodb (2.6+)
  • git

Ready to work

  • Clear yum command cache
sudo yum clean all
  • Uninstall low version nodejs
yum remove nodejs npm -y

Install nodejs

  • Get resources, install high version nodejs
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
  • installation
sudo yum install -y nodejs
  • Verification version
[[email protected] my-yapi]# node -v
[[email protected] my-yapi]# npm -v

Install Git

yum install -y git

Install mongodb4.0

  • Configure MongoDB's yum source, vi /etc/yum.repos.d/mongodb-org-4.0.repoand add the following:
name=MongoDB Repository
  • Install MongoDB
yum install -y mongodb-org
  • View installation path
[[email protected] my-yapi]# rpm -ql mongodb-org-server
/etc/mongod.conf # 配置文件
  • Note: The official tutorial mentioned that selinux will have a negative impact on mongodb, so choose to disable it. vim /etc/selinux/configWill be SELINUX=enforcingchanged toSELINUX=disabled
  • mongodb service management
# 设置开机启动 
systemctl enable mongod

# 启动mongodb
systemctl start mongod

# 查看服务状态
systemctl status mongod

YApi installation

  • Execute the installation command
npm install -g yapi-cli --registry https://registry.npm.taobao.org
  • Initialize YApi, execute the yapi servercommand, and follow the prompts
[[email protected] ~]# yapi server
在浏览器打开 访问。非本地服务器,请将 替换成指定的域名或ip
Insert picture description here

Insert picture description here

Insert picture description here

Put the YApi service in the background

  • Solution: When the shell window is closed, the service is also closed.
  • Install pm2
npm install -g pm2 --registry=https://registry.npm.taobao.org
  • Start in the background, close
# 例如:yapi是安装在/usr/local/yapi/

# 启动执行: 
pm2 start /usr/local/yapi/vendors/server/app.js

# 关闭执行: 
pm2 stop /usr/local/yapi/vendors/server/app.js

YApi upgrade

The upgrade of YApi is very easy, and will not affect the user's data, only the vendors directory will be updated

# 更新到最新版本
yapi update
# 升级到指定的版本
yapi update -v {Version}