time 20191204
author Venki
ps 内网部署
回到顶部
# 在location /添加
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
回到顶部
# 部署nodejs尽可能选择偶数版本,因为偶数版本官方有较长的维护时间,故这次选择8.x
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs
node -v
npm -v
回到顶部
touch /etc/yum.repos.d/mongodb-org.repo
vim /etc/yum.repos.d/mongodb-org.repo
# 添加如下内容
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
yum install -y mongodb-org
service mongod start
chkconfig mongod on
vim /etc/mongod.conf
注释 bindIp: 127.0.0.1
#bindIp: 127.0.0.1
service mongod restart
回到顶部
npm install -g yapi-cli --registry https://registry.npm.taobao.org
yapi server
mkdir yapi
cd yapi
# 或者下载 zip 包解压到 vendors 目录
git clone https://github.com/YMFE/yapi.git vendors
# 或者(clone 整个仓库大概 140+ M,可以通过 `git clone --depth=1 https://github.com/YMFE/yapi.git vendors` 命令减少,大概 10+ M)
# 我用的是这个小的包,大包下载太慢
git clone --depth=1 https://github.com/YMFE/yapi.git vendors
# 复制完成后请修改相关配置
cp vendors/config_example.json ./config.json
{
# 访问端口号
"port": "52015",
# yapi管理员初始化登录账号 密码默认ymfe.org
"adminAccount": "[email protected]",
# mongodb 数据库配置
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "venki",
"pass": "1q2w3e4r5t@!",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}
cd vendors
npm install --production --registry https://registry.npm.taobao.org
# 安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
npm run install-server
# 此步骤可能报错,意识就是
SCRAM-SHA-1 authentication failed for test1 on yapi from client 127.0.0.1 ; UserNotFound: Could not find user test1@yapi
# 原因就是:针对是3.0.3以前版本已经ok,如果是3.0.3,mongodb加入了SCRAM-SHA-1校验方式,需要第三方工具配合进行验证
# 解决方法 ,下面的配置信息要根据config.json进行配置
use yapi
db.dropUser("venki")
db.createUser({user:'venki',pwd:'1q2w3e4r5t@!',roles:[{role:'dbOwner',db:'yapi'}]})
# 启动服务器后,请访问 127.0.0.1:{config.json配置的端口},初次运行会有个编译的过程,请耐心等候
node server/app.js
# yapi日志文件位置
/usr/local/src/yapi/log
# mongodb日志文件位置
/var/log/mongodb
回到顶部
yapi server
回到顶部
# nginx配置如下
server {
server_name my.gl.yapi.com; # 请修改为你的域名
client_max_body_size 250m;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_redirect off;
proxy_pass http://127.0.0.1:52015/;
}
# Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
# WARNING: If you are using relative urls do remove the block below
# See config/application.rb under "Relative url support" for the list of
# other files that need to be changed for relative url support
location ~ ^/(assets)/ {
expires max;
add_header Cache-Control public;
}
error_page 502 /502.html;
}
# 重启nginx
service nginx restart
回到顶部
cd /etc/supervisor/supervisord.conf.d
vi yapi.conf
# 添加如下内容
[program:yapi]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/node /usr/local/src/yapi/vendors server/app.js
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/usr/local/src/yapi/log/node_server.log # 日志记录
# 重新载入
supervisorctl update
# 查看进程
supervisorctl status
> yapi:yapi_00 RUNNING pid 21581, uptime 0:02:55
回到顶部
回到顶部