Easy Mock 是一个可视化,并且能快速生成模拟数据的持久化服务。
GitHub地址:https://github.com/easy-mock/easy-mock
中文介绍文档:https://github.com/easy-mock/easy-mock/blob/dev/README.zh-CN.md
一、部署
1. 传统部署
建议使用docker部署,传统部署坑太多了
参考:https://coder.itclan.cn/fontend/tools/local-deploy-easy-mock/#%E5%89%8D%E8%A8%80
1.1 安装Redis
# 下载源码包
version='6.0.9'
wget https://download.redis.io/releases/redis-${version}.tar.gz
# 安装依赖
yum install gcc gcc-c++ make -y
yum install centos-release-scl -y
yum install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils -y
# 启用gcc9
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
# 解压源码包
tar xf redis-${version}.tar.gz
# 编译安装
cd redis-${version}
make -j 2
make PREFIX=/usr/local/redis install
# 修改系统参数
echo net.core.somaxconn=511 >> /etc/sysctl.conf
echo vm.overcommit_memory=1 >> /etc/sysctl.conf
sysctl -p
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# 添加配置文件
mkdir /usr/local/redis/conf
cat > /usr/local/redis/conf/redis.conf << EOF
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
EOF
# 启动redis
mkdir /usr/local/redis/logs
nohup /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf >> /usr/local/redis/logs/redis.log 2>&1 &
1.2 安装MongoDB
# 下载二进制包
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.3.tgz
# 解压
tar -xf mongodb-linux-x86_64-rhel70-5.0.3.tgz
mv mongodb-linux-x86_64-rhel70-5.0.3 /usr/local/mongodb
# 新建数据目录、日志目录和配置文件目录
mkdir /usr/local/mongodb/{data,logs,conf}
# 添加配置文件
cat > /usr/local/mongodb/conf/mongo.conf << EOF
port=27017
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/logs/mongod.log
pidfilepath=/usr/local/mongodb/mongod.pid
logappend=true
fork=true
journal=true
bind_ip=localhost
EOF
# 启动MongoDB
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongo.conf
1.3 部署easy-mock
需要先安装git和nodejs
注意:要在Redis和MongoDB已经启动的条件下部署easy-mock
- 从GitHub拉取easy-mock
git clone https://github.com/easy-mock/easy-mock.git
cd easy-mock && npm install
- 修改配置文件 easy-mock/config/default.json
{
"port": 7300,
// 将此处的"host": "0.0.0.0"修改为localhost
"host": "localhost",
"pageSize": 30,
"proxy": false,
"db": "mongodb://localhost/easy-mock",
"unsplashClientId": "",
"redis": {
"keyPrefix": "[Easy Mock]",
"port": 6379,
"host": "localhost",
"password": "",
"db": 0
},
"blackList": {
"projects": [],
"ips": []
},
"rateLimit": {
"max": 1000,
"duration": 1000
},
"jwt": {
"expire": "14 days",
"secret": "shared-secret"
},
"upload": {
"types": [".jpg", ".jpeg", ".png", ".gif", ".json", ".yml", ".yaml"],
"size": 5242880,
"dir": "../public/upload",
"expire": {
"types": [".json", ".yml", ".yaml"],
"day": -1
}
},
"ldap": {
"server": "",
"bindDN": "",
"password": "",
"filter": {
"base": "",
"attributeName": ""
}
},
"fe": {
"copyright": "",
"storageNamespace": "easy-mock_",
"timeout": 25000,
"publicPath": "/dist/"
}
}
启动easy-mock
npm run dev
2. Docker部署Easy Mock
官方GitHub仓库:https://github.com/easy-mock/easy-mock-docker
参考:https://juejin.cn/post/7081459518642585613
需要先安装好docker和docker-compose
创建docker-compose.yml
version: '3'
services:
mongodb:
image: mongo:3.4.1
volumes:
# /apps/easy-mock/data/db 是数据库文件存放地址,根据需要修改为本地地址
- '/apps/easy-mock/data/db:/data/db'
networks:
- easy-mock
restart: always
redis:
image: redis:4.0.6
command: redis-server --appendonly yes
volumes:
# /apps/easy-mock/data/redis 是 redis 数据文件存放地址,根据需要修改为本地地址
- '/apps/easy-mock/data/redis:/data'
networks:
- easy-mock
restart: always
web:
image: easymock/easymock:1.6.0
# easy-mock 官方给出的文件,这里是 npm start,这里修改为 npm run dev
command: /bin/bash -c "npm run dev"
ports:
- 7300:7300
volumes:
# 日志地址,根据需要修改为本地地址
- '/apps/easy-mock/logs:/home/easy-mock/easy-mock/logs'
networks:
- easy-mock
restart: always
networks:
easy-mock:
启动
docker-compose up -d
访问ip:7300
二、使用Easy Mock
可用的在线的easymock页面:https://mock.mengxuegu.com/login
[email protected]/[email protected]
1. 登录注册
略