Easy Mock是一个高效数据模拟解决方案,本地部署需要安装Mongodb, Redis, Node.js等组件的最新版本,下面是具体的方法:
mongodb:
# 编辑文件
vim /etc/yum.repos.d/mongodb-org-3.6.repo
# 添加以下内容
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
yum install -y mongodb-org
# 启动
systemctl start mongod.service
# 停止
systemctl stop mongod.service
# 重启
systemctl restart mongod.service
Redis:
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum –enablerepo=remi install redis
service redis start
或者
systemctl start redis
node.js:
curl -sL https://rpm.nodesource.com/setup_9.x | bash –
sudo方式执行如果最后一步有错误,找到下面这一行, sudo方式执行一次
+ rpm -i –nosignature –force ‘/tmp/……..’
然后:
yum install -y nodejs
安装EasyMock
$ git clone https://github.com/easy-mock/easy-mock.git
$ cd easy-mock && npm install
配置文件路径是:config/default.json,可根据需要修改内容
$ npm run build
$ npm install pm2 -g — 安装pm2作为守护进程
$ NODE_ENV=production pm2 start app.js –启动守护进程
如果用Apache/Nginx作为web服务器,可以做一个代理,下面是一个Apache的例子:
<VirtualHost *:80>
ServerName mock.mydomain.com
ServerSignature Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Location />
Order deny,allow
Allow from all
Require all granted
ProxyPassReverse http://127.0.0.1:7300
ProxyPassReverse http://mock.mydomain.com/
</Location>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:7300%{REQUEST_URI} [P,QSA,NE]
DocumentRoot /data/dummy
</VirtualHost>