安装YMFE/yapi API管理服务器(Ubuntu20)

GitHub - YMFE/yapi: YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台. Contribute to YMFE/yapi development by creating an account on GitHub.https://github.com/YMFE/yapi根据文档介绍,先安装nodejs(7.6+)和mongodb(2.6+)

-----------------------------------------

安装nodejs  

Node.jsNode.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.https://nodejs.org/zh-cn/

官方手顺

通过包管理器安装 Node.js | Node.jsNode.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.https://nodejs.org/zh-cn/download/package-manager/

推荐使用方法1进行安装
方法1:

Node.js v16.x:

# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
apt-get install -y nodejs

方法一 使用了NodeSource提供的二进制包进行安装,NodeSource提供了常用的Linux系统(Ubuntu,CentOS,RedHat,Debian等)安装Node的二进制包,具体简介可以访问Linux通过二进制包安装nodejs
方法2:
在nodejs官方网站download页面中选择需要使用的版本,可以选择LTS或current,选择对应系统右键复制链接地址

安装YMFE/yapi API管理服务器(Ubuntu20)_第1张图片
如果需要下载历史版本可以选择download页面底部PreviousReleases,也可以直接访问http://nodejs.org/dist/或https://nodejs.org/download/release/


当然你也可以使用淘宝npm镜像下载对应的node版本下载地址
下载nodejs压缩文件
wget https://nodejs.org/dist/v8.1.0/node-v8.1.0-linux-x64.tar.xz

解压
tar -xvf node-v8.1.0-linux-x64.tar.xz

切换并查看当前node所在路径
cd node-v8.1.0-linux-x64/bin
pwd

查看node版本
./node -v

将node和npm设置为全局
sudo ln /home/ubuntu/node-v8.1.0-linux-x64/bin/node /usr/local/bin/node
sudo ln /home/ubuntu/node-v8.1.0-linux-x64/bin/npm /usr/local/bin/npm
pwd

方法三:
也可以使用ubuntu自带apt-get安装,安装后使用node -v查看版本

sudo apt-get install nodejs-legacy nodejs
sudo apt-get install npm

安装完成
推荐使用方法一,直接安装在系统环境/usr/bin目录下,之后使用npm -g安装其他插件也会安装到/usr/lib/node_modules’(需要使用sudo权限)‘。
如果使用方法二,将nodejs路径链接到/usr/local/bin目录下,则每次npm -g安装插件都会安装在nodejs原路径下的node_modules(比如/home/ubuntu/node-v8.1.0-linux-x64/lib/node_modules),每次代码中引用插件也需要到此目录下去找
 

---------------------------------

安装mongodb

MongoDB: The Developer Data Platform | MongoDB | MongoDBGet your ideas to market faster with a developer data platform built on the leading modern database. MongoDB makes working with data easy.https://www.mongodb.com/Install MongoDB Community Edition on Ubuntu — MongoDB Manualhttps://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/

导入包管理系统使用的公钥

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

如果命令执行结果没有显示OK,则执行此命令在把上一句重新执行:

sudo apt-get install gnupg

注册mongodb源

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

更新源

sudo apt-get update

安装最新版本

sudo apt-get install -y mongodb-org

可选的。尽管您可以指定任何可用的 MongoDB 版本, apt-get但当有更新的版本可用时将升级包。为防止意外升级,您可以将软件包固定在当前安装的版本:

echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
 

安装指定版本

sudo apt-get install -y mongodb-org=6.0.0 mongodb-org-database=6.0.0 mongodb-org-server=6.0.0 mongodb-mongosh=6.0.0 mongodb-org-mongos=6.0.0 mongodb-org-tools=6.0.0

重新加载配置,并启动mongodb

sudo systemctl daemon-reload
sudo
systemctl start mongod

sudo systemctl status mongod

sudo systemctl enable mongod

MongoDB 数据库和日志文件

/var/log/mongodb
/var/lib/mongodb
 

修改配置,开放27017端口 ,以及开发外网链接

sudo vim /etc/mongod.conf

------------------------------------------------

安装yapi

/usr/lib/node_modules/yapi-cli/

使用我们提供的 yapi-cli 工具,部署 YApi 平台是非常容易的。执行 yapi server 启动可视化部署程序,输入相应的配置和点击开始部署,就能完成整个网站的部署。部署完成之后,可按照提示信息,执行 node/{网站路径/server/app.js} 启动服务器。在浏览器打开指定url, 点击登录输入您刚才设置的管理员邮箱,默认密码为 ymfe.org 登录系统(默认密码可在个人中心修改)。

npm install -g yapi-cli --registry https://registry.npm.taobao.org
sudo npm install --location=global yapi-cli --registry https://registry.npm.taobao.org
sudo yapi server 

-----------------------------

~$ npm install -g yapi-cli --registry https://registry.npm.taobao.org
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.15.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.15.1
npm notice Run npm install -g [email protected] to update!
npm notice
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/lib/node_modules/yapi-cli
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/yapi-cli'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/yapi-cli'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/lib/node_modules/yapi-cli'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/songtao/.npm/_logs/2022-07-29T05_13_05_399Z-debug-0.log
 

----------------------------------------

~$ npm install -g [email protected]
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/npm
npm ERR! dest /usr/lib/node_modules/.npm-qUIFSsiV
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'
npm ERR!  [Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/lib/node_modules/npm',
npm ERR!   dest: '/usr/lib/node_modules/.npm-qUIFSsiV'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/songtao/.npm/_logs/2022-07-29T05_14_21_279Z-debug-0.log
 

--------------------------------------

~$ sudo npm install --location=global [email protected]

changed 14 packages, and audited 202 packages in 5s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
-----------------------------------------

sudo npm install --location=global yapi-cli --registry https://registry.npm.taobao.org

npm WARN deprecated [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
npm WARN deprecated [email protected]: Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details
-----

~$ grep axios -r /usr/lib/node_modules/yapi-cli/ |grep 0.16.2
/usr/lib/node_modules/yapi-cli/node_modules/axios/dist/axios.min.js:/* axios v0.16.2 | (c) 2017 by Matt Zabriskie */
/usr/lib/node_modules/yapi-cli/node_modules/axios/dist/axios.js:/* axios v0.16.2 | (c) 2017 by Matt Zabriskie */
/usr/lib/node_modules/yapi-cli/src/commands/server/axios.js:/* axios v0.16.2 | (c) 2017 by Matt Zabriskie */
/usr/lib/node_modules/yapi-cli/package.json:    "axios": "^0.16.2",
-------

sudo vim.tiny /usr/lib/node_modules/yapi-cli/package.json

sudo yapi server 

--------------------------------------------

nodejs16安装失败

YApi手动部署:

安装-手动

mkdir yapi 
cd yapi 
git clone https://github.com/YMFE/yapi.git vendors 
cp vendors/config_example.json ./config.json // ⚠️  复制完成后把内容修改为 config.json
cd vendors 
rm package-lock.json // ⚠️ 一定要删除 package-lock.json 
npm install --production --registry https://registry.npm.taobao.org 
npm run install-server 
node server/app.js 

config.json 参考

{
  "port": "3000",
  "adminAccount": "[email protected]",
  "timeout":120000,
  "db": {
    "servername": "127.0.0.1",
    "DATABASE": "yapi",
    "port": 27017
  },
  "mail": {
    "enable": false,
    "host": "smtp.163.com",
    "port": 465,
    "from": "***@163.com",
    "auth": {
      "user": "***@163.com",
      "pass": "*****"
    }
  }
}
 

你可能感兴趣的:(yapi,nodejs)