Easy Mock server deployment tutorial and project demo

1. Environmental Description

  • CentOS 7.6
  • Node 14.13.0, the image source is taobao
  • MongoDB 4.2.10
  • Redis 5.0.5

Centos 7 installs Redis
Centos 7 installs MongoDB (lazy version) .

2. Download and run Easy-Mock

1. Create a project storage directory

mkdir -p /data/node

2. Download the project and install dependencies (PS: because easy-mock has stopped maintenance and has some bugs, I have forked and repaired some bugs)

# 进入目录
cd /data/node
# 克隆本人 fork 修复的项目
git clone [email protected]:qiuziGirl/easy-mock.git
# 克隆官方项目
git clone [email protected]:easy-mock/easy-mock.git

3. Installation dependencies

# 进入目录
cd easy-mock
# 安装依赖
yarn

4. Configure server security group rules and open port 7300

5. Run the project

If the connected MongoDB and Redis belong to this server, the configuration file config/default.jsondoes not need to modified (unless the port or other configuration needs to be changed)

# 因接下来以 yarn start 方式启动,需提前构建
yarn build
# 以生产环境方式启动
yarn start


6. Access test through server domain name plus port

3. Build and deploy Easy-Mock

1. Build the project and package static resources

yarn build

2. Install PM2 globally

yarn global add pm2

3. Start with PM2

NODE_ENV=production pm2 start app.js

4. Regarding the specific tutorial of PM2 , the common commands are listed below, please refer to the official website for details

pm2 start app.js

pm2 stop     <app_name|namespace|id|'all'|json_conf>
pm2 restart  <app_name|namespace|id|'all'|json_conf>
pm2 delete   <app_name|namespace|id|'all'|json_conf>

4. Configure domain name (Nginx) for Easy-Mock project

1. Edit the nginx.conf configuration file and add the server item

 server {
    
    
    listen 80;  # 监听 80 端口
    server_name mock.qiuzi.fun; # 你的域名
    root /data/node/easy-mock;  # 映射项目路径
    
    location / {
    
    
      proxy_pass http://127.0.0.1:7300; # 代理至项目实际运行地址
    }
}

2. After successfully restarting Nginx, enter the corresponding URL in the browser to verify

service nginx restart

or

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

If port 80 is occupied, end the process with kill [id].

# 查看端口使用
netstat -lntp;

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      4351/mysqld
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      3078/memcached
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      2957/redis-server 1
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9096/nginx: master
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      2942/pure-ftpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3027/sshd
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      9096/nginx: master
tcp        0      0 127.0.0.1:7773          0.0.0.0:*               LISTEN      28167/node
tcp6       0      0 127.0.0.1:8006          :::*                    LISTEN      3865/java
tcp6       0      0 :::8080                 :::*                    LISTEN      3865/java
tcp6       0      0 :::21                   :::*                    LISTEN      2942/pure-ftpd
tcp6       0      0 :::7001                 :::*                    LISTEN      28160/node

# 结束 80 端口进程
kill 9096;

Restart Nginx again, browser verification

3. If you need to configure SSL, please move to read my article

5. Use the demo with the project

1. Create a new project mock service on Easy-Mock 2. Add 3. After adding a prefix , open the project verificationforward/data

vue.config.js

/mock

Guess you like

Origin blog.csdn.net/qq_41548644/article/details/117855661