# CentOS 7 MongoDB和Yapi部署日志

草稿状态

# MongoDB

# 官网

https://www.mongodb.com/
https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.2/x86_64/RPMS/

# 下载

wget https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.6-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.2/x86_64/RPMS/mongodb-org-shell-4.2.6-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.2/x86_64/RPMS/mongodb-org-tools-4.2.6-1.el7.x86_64.rpm

# 安装

yum localinstall mongodb-org-server-4.2.6-1.el7.x86_64.rpm
yum localinstall mongodb-org-shell-4.2.6-1.el7.x86_64.rpm
yum localinstall mongodb-org-tools-4.2.6-1.el7.x86_64.rpm

# 启动

syetemctl status mongod
syetemctl start mongod
syetemctl restart mongod
syetemctl stop mongod

# MongoDB 配置文件

按需求修改,默认是只能本地连接且无密码

vim /etc/mongod.conf

# 备份数据

# mongodump -h dbhost -d dbname -u username --authenticationDatabase authDB -p password -o dbdirectory
# -d:需要备份的数据库实例
# -o:备份的数据存放位置
mongodump -d yapi -o /home/apps/
mongodump -d yapi -u yapi --authenticationDatabase yapi -p yapi123 -o /home/mongodump/

# 恢复数据

# mongorestore -h dbhost -d dbname -u username --authenticationDatabase authDB -p password --dir backupdirectory
# --drop:执行恢复前先删除当前全部数据,慎用
# --dir:指定备份文件的目录
mongorestore -d yapi --drop --dir /home/apps/yapi
mongorestore -d yapi -u yapi --authenticationDatabase yapi -p yapi123 --drop --dir /home/mongodump/yapi

# Yapi

https://github.com/YMFE/yapi
https://hellosean1025.github.io/yapi/

# 安装和启动

mkdir yapi
cd yapi
git clone https://github.com/YMFE/yapi.git vendors //或者下载 zip 包解压到 vendors 目录
cp vendors/config_example.json ./config.json //复制完成后请修改相关配置
cd vendors
npm install --production --registry https://registry.npm.taobao.org
npm run install-server //安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
node server/app.js //启动服务器后,请访问 127.0.0.1:{config.json配置的端口},初次运行会有个编译的过程,请耐心等候
# 用PM2管理服务
npm install pm2 -g
pm2 start "vendors/server/app.js" --name yapi