CentOS7 install YApi

Preface

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
v8.17.0
[[email protected] my-yapi]# npm -v
6.13.4

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:
[ngodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
  • Install MongoDB
yum install -y mongodb-org
  • View installation path
[[email protected] my-yapi]# rpm -ql mongodb-org-server
/etc/mongod.conf # 配置文件
/lib/systemd/system/mongod.service
/usr/bin/mongod
/usr/share/doc/mongodb-org-server-4.0.24
/usr/share/doc/mongodb-org-server-4.0.24/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server-4.0.24/MPL-2
/usr/share/doc/mongodb-org-server-4.0.24/README
/usr/share/doc/mongodb-org-server-4.0.24/THIRD-PARTY-NOTICES
/usr/share/man/man1/mongod.1
/var/lib/mongo
/var/log/mongodb
/var/log/mongodb/mongod.log
/var/run/mongodb
  • 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
在浏览器打开 http://0.0.0.0:9090 访问。非本地服务器,请将 0.0.0.0 替换成指定的域名或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}