MENU

CentOS部署yapi

October 22, 2021 • linux相关

原生部署(有空再折腾docker)

nodejs + mongodb 开源api接口文档管理
官网仓库:https://github.com/YMFE/yapi
官方文档:https://hellosean1025.github.io/yapi
环境要求: nodejs(7.6+)、mongodb(2.6+)、git

1. 先行安装可视化部署工具 yapi-cli ,web会监听在 9090 端口上:

npm install -g yapi-cli --registry https://registry.npm.taobao.org
yapi server

可能会有一万个警告和错误(n lts 安装成node-14版本后失败):
node>=7.6

n 8.1
n

会安装 node-v8.1.4,然后 n 切换到 8.1.4 版本,再重复第一步。

2. 安装 mongodb-3.4

2.1 创建仓库文件

vim /etc/yum.repos.d/mongodb-org-3.4.repo

复制以下内容:

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

2.2 使用 yum 安装

yum install -y mongodb-org

2.3 安装完后按需要修改配置文件:

vim /etc/mongod.conf

2.4 开机启动服务

systemctl enable mongod
systemctl start mongod

2.5 查看日志

cat /var/log/mongodb/mongod.log

3. 浏览器访问 http://0.0.0.0:9090 开始安装真正的 yapi

最后 yapi 地址:http://0.0.0.0:3000
登录账号密码:

[email protected]
ymfe.org

4. 升级:

cd  {项目目录}
yapi ls //查看版本号列表
yapi update //升级到最新版本
yapi update -v v1.1.0 //升级到指定版本

5. nginx 本地转发 300080/443 绑定域名:

map $scheme $yapi_proxy_port {
    "http" "3000";
    "https" "3443";
    default "3000";
}
server
    {
        listen 80;
        server_name doc.abc.com;
        index index.html index.htm;

        location / {
            proxy_pass              $scheme://127.0.0.1:$yapi_proxy_port;
            proxy_redirect          ~^$scheme://127.0.0.1:$yapi_proxy_port(.*)    $scheme://$server_name$1;
            proxy_set_header        Host             $http_host;
            proxy_set_header        X-Real-IP        $host;
            proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }
Last Modified: November 19, 2021