Dig friendly habits ^-^ favorites + likes + comments
Tmi will digress
Not long ago, I worked hard to open source the mobile e-commerce project ddBuy based on Vue family bucket. Up to now, the project has 13,000 +star. Since open source, I have kept updating and iterating. Can you have it in English to ddBuy, wake up early in the morning, touch the dog head, said to do we do, is not an international, is expected to support international in the next version, you see rural love push international, we can not be left behind is not, international integration, facing the future… .
Server setup easy-mock
Back to the subject, how to build your own easy-mock on your own server? Easy Mock’s GitHub website and its post bar show you why I build it myself. Easy Mock’s GitHub website is so confusing that it can’t be used properly.
The good news is that the source code has been open source for a long time, but the bad news is that you have to build it yourself. It’s called Easy-Mock, but it’s not Easy at all. Programmers love it out of the box Hand to hand teach you, teach not, you beat me..
The preparatory work
-
1. A server (say the recent nuggets on a lot of selling server spam, can be miserably.. Ha ha ha, recommend you to ali cloud official website legal way to buy ha ~)
-
2. Domain name (personally feel dispensable, because the need for domain name record, more trouble)
-
Follow this tutorial step by step
There are no servers available to view this local setup easy-mock
Open to
1. Use SSH to connect to your server
SSH root@ Your server address
When you see the picture below, congratulations, you have successfully connected to the server, ali BABA’s arms are open to you ~~
2. Install the node
Check the version of Node on your server. If node is larger than v8. X, it is highly recommended to uninstall node 8.x, Node 8.x, Node 8.x because I have been in this shipit for a long time…
/ / download the node
cd /usr/local/src
Wget HTTP: / / https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-x64.tar.xz
# # decompression
The tar xf node - v8.9.0 - Linux - x64. Tar. Xz
cd /usr/local
# # renamed
SRC/mv node - v8.9.0 - Linux - x64 node
Add node to path
vi ~/.bashrc
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
source ~/.bashrc
The installation is successful
Node -v // The node version is displayed after the installation is successful
Copy the code
3. Install the mongo
cd /usr/local/src
The curl - O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
Tar - ZXVF mongo - Linux - x86_64-3.0.6. TGZ
cd /usr/local
SRC/mv mongo - Linux - x86_64-3.0.6 mongo
## path
vi ~/.bashrc
export MONGO_HOME=/usr/local/mongodb
export PATH=$MONGO_HOME/bin:$PATH
source ~/.bashrc
Copy the code
After downloading, create the configuration file and start the service:
Create a data directory
mkdir /data
mkdir /data/mongo
Create a configuration file
vi /data/mongo/mongodb.cnf
Copy the code
The content of the configuration file is as follows:
## /data/mongo/mongodb.cnf
dbpath=/data/mongo/
logpath=/data/mongo/mongo.log
logappend=true
fork=true
port=27017
journal=true
Copy the code
Start the MongoDB service by reading the configuration file:
## Start Mongo in config file mode
mongod -f /data/mongo/mongodb.cnf
Mongod -f /data/mongo/mongodb.cnf &
Copy the code
4. Install Redis
cd /usr/local/src
Wget HTTP: / / http://download.redis.io/releases/redis-2.8.17.tar.gz
The tar XZF redis - 2.8.17. Tar. Gz
cdRedis - 2.8.17
make
Copy the code
After Make, the compiled Redis service program redis-server and the client program redis-cli will be displayed in the redis-2.8.17 directory. The two programs are located in the installation directory SRC.
Start the Redis service: CD src. /redis-server &
5. Easy deployment – the Mock
To create a new directory without Libra, we’ll put our application in /usr/libra:
cd /usr/libra
git clone https://github.com/easy-mock/easy-mock.git
# install dependencies
cd easy-mock && npm install
Copy the code
Modify the easy-mock configuration file:
Modify the default.js file in the config folder under the easy-mock folder and replace all localhosts with your own server address.
Configure server security group rules and enable port 7300
Operation Easy to Mock
# # to run
[[email protected] easy to mock]# npm run dev
> easy-mock@1.6. 0 dev /usr/libra/easy-mock
> nodemon --ignore views/ --ignore public/ app
[nodemon] 1.1411.
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
server started at http:/ / 0.0.0.0:7300
Copy the code
With the deployment above, you can access your IP: port 7300 to access Easy Mock’s page.
When you close the console and access it again, you hang up.
The reason is that closing the console will shut down the Node process by default, so it will be awkward to access it.
The ultimate big recruit
Guard the Node process with PM2 and keep it always online.
Install pm2 # #
npm install -g pm2
## Build is required to run with PM2
npm run build
NODE_ENV=production pm2 start app.js
Copy the code
In just three lines of code, you can close the console and not access it
Finally, if your server node version is higher than 8.x, there will be a really inexplicable error oh, do not believe you have a try, I gave you the error code, when the time comes to make a mistake, don’t hit me ha ha ha ~
High Alert: Easy Mock installation failure due to high version of Node!!
Error: listen EADDRINUSE 0.0. 0. 0:7300
at Server.setupListenHandle [as _listen2] (net.js:1334:14)
at listenInCluster (net.js:1382:12)
at doListen (net.js:1508:7)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1361:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
[nodemon] app crashed - waiting for file changes before starting...
Copy the code
Make a friend 👭
Okay, ladies and gentlemen, the above is the entire content of this article, a magnificently, one thousand words, pure manual, teaching by holding thank you very much for digging the friends can see here, if this article is to write a little something, think of “James” I have two down son, to a great 👍 to comment, I will be very, very happy the dalai, hard, Open source is not easy, you have the support and recognition, is the biggest power I continue to output, gentleman respect without loss, and people are respectful and polite, within four corners of the world, all brothers also, can scan the two-dimensional code below and I make friends!
James | article “original”
🎉 Open source e-commerce project :ddBuy
Finally, I am participating in the nuggets annual essay: if you can have a little bit of inspiration after reading the article, please help me to point a praise ha!
The nuggets essay
If there are any mistakes in this blog, please comment, thank you very much! Blue Jack