Centos8 installation and deployment node + mongodb (record)

  • Node installation

1. Upgrade CentOS to Yum (recommended)

Execute: Yum - y update command

2. Create a new software installation directory (it can also be installed under root by default)

Execute: CD / root create a new touch node server and enter CD node server

3. Download the node package to the installation directory

Execution: WGet http://nodejs.org/dist/node-latest.tar.gz (download latest)
(recommended, stable version)

4. Unzip and download the node package to the installation directory

Execution: tar xvf node-v6.9.5-linux-x64 tar.xz

5. Enter the node installation directory

Perform: node - V view

6. To create a soft link, you can directly use the node and NPM commands in any directory

ln -s /root/node-v6.9.5-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v6.9.5-linux-x64/bin/npm /usr/local/bin/npm

Build test project after this node installation

  • Build tests

1. Create a new test file under the root directory

touch app.js

2. Open app.js Document writing in code

vim app.js
Press key disk I to enter editing mode

const http = require('http');
Const hostname =' '; // note that is better not to be written here
const port = 3000;
const server = http.createServer((req, res) => { 
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World\n');

server.listen(port, hostname, () => { 
    console.log(`Server running at http://${hostname}:${port}/`);

Press ESC: WQ to save and exit
Execute node app.js  Start node service
Query whether netstat - tpln is started to check the running port

Note: since the port is 3000, you need to add security components in Alibaba cloud. For details, please refer to the rules for adding security components

3. Input in the browser of the local machineHttp: // < ECS instance public IP address >: port numberThe access items are as follows
Centos8 installation and deployment node + mongodb (record)
This rough Alibaba cloud node installation is complete

4. If you need to listen to whether the node service is running and installing PM2 to guard (you can also choose nginx to guard)

npm install -g pm2

pm2 start app.js

It’s OK to see that it’s almost as long as the figure below
Centos8 installation and deployment node + mongodb (record)

For PM2, please refer to PM2, the deployment mode of nodejs

  • Mongodb installation

1. Create the yum source file

sudo vim /etc/yum.repos.d/mongodb-org-3.4.repo

2. Add the following

name=MongoDB Repository  

3. Install mongodb

Execute sudo Yum -y install mongodb-org 
View the installation directory where is mongod
mongod: /usr/bin/mongod

View profile
vim /etc/mongod.conf

Press I to enter editing mode and modify bindip address according to your own needs. You can listen to or intranet address. If you need to bind multiple IPS  

ESC: WQ enter save exit

4. Start mongodb

#Start mongodb
sudo systemctl start mongod.service

#Stop mongodb
sudo systemctl stop mongod.service

#Query mongodb status:
systemctl status mongod.service

Note: you can set it to startup

sudo systemctl enable mongod.service

If you need to configure a firewall or Alibaba cloud server security component to access or modify ports under different servers, the default value is 27017. For example, you can modify it in / etc/ mongod.conf Lower modify port

This installation is complete

5. Start Mongo shell

Execute Mongo
view the database
> show dbs
admin  0.000GB
local  0.000GB
Create database
use User

Recommended Today

How to solve Chinese garbled code when jQuery Ajax returns JSON

Using jQuery Ajax call to return JSON, Chinese garbled problem JS code is as follows: $.ajax({ url: ‘/test/testAction.do?method=test’, type: ‘POST’, dataType: ‘json’, timeout: 5000, async: false, error: function(){ Alert (‘failed to get data! ‘); }, success: function(json){ jsObject = eval(json); } }); return jsObject; JS code <span style=”font-size: x-small;”>$.ajax({ url: ‘/test/testAction.do?method=test’, type: ‘POST’, dataType: ‘json’, […]