天天看点

服务器端修改yapi-cli默认IP,Yapi开源接口管理平台部署

环境要求nodejs(7.6+)

mongodb(2.6+)

1、安装nodejs

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -

yum -y install nodejs

建议安装node8.X版本,最新10.X版本安装yapi会报错,有问题。

2、安装mongodb并启动mongo

cat > /etc/yum.repos.d/mongodb-org-3.6.repo<

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

gpgcheck=0

enabled=1

EOF

yum -y install mongodb-org

service mongod start

3、安装yapi

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

yapi server

4、浏览器输入http://服务器ip:9090(服务器安全组9090端口要开放)

服务器端修改yapi-cli默认IP,Yapi开源接口管理平台部署

如果是安装1.4可能最后会报错,可以忽略不管

5、启动yapi服务

①切换到部署目录下

cd /root/yapi

②启动服务

node vendors/server/app.js

③浏览器输入http://服务器ip:3000/login(注意:服务器安装组要开放3000端口)

服务器端修改yapi-cli默认IP,Yapi开源接口管理平台部署

登录用户名就是配置的管理员邮箱,密码默认是ymfe.org,登陆后可以自行修改。

6、supervisor管理nodejs进程,保持node后台进程挂起

#!/bin/bash

# supervisor

# author ctocode-zwj

yum install python-setuptools -y

easy_install supervisor

mkdir /etc/supervisor

echo_supervisord_conf > /etc/supervisor/supervisord.conf

cat > /etc/supervisor/supervisord.conf<

[include]

files = conf.d/*.conf

EOF

mkdir -p /etc/supervisor/conf.d/

cat > /etc/supervisor/conf.d/YApiGhost.conf<

[program: YApiGhost]

command=node vendors/server/app.js ; # 运行程序的命令

directory=/root/my-yapi ; #命令执行的目录

autorestart=true ; # 程序意外退出是否自动重启

stderr_logfile=/var/log/YApiGhost.err.log ; # 错误日志文件

stdout_logfile=/var/log/YApiGhost.out.log ; # 输出日志文件

environment=ASPNETCORE_ENVIRONMENT=Production ; # 进程环境变量

user=root ; # 进程执行的用户身份

stopsignal=INT

[supervisord]

EOF

supervisord -c /etc/supervisor/supervisord.conf

cat > /usr/lib/systemd/system/supervisord.service<

[Unit]

Description=Supervisor daemon

[Service]

Type=forking

ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

ExecStop=/usr/bin/supervisorctl shutdown

ExecReload=/usr/bin/supervisorctl reload

KillMode=process

Restart=on-failure

RestartSec=42s

[Install]

WantedBy=multi-user.target

EOF

# 开机启动

systemctl enable supervisord

github示例:

- END -