Logging In to the Server

Log in to the server using a terminal such as GitBash or Xshell or CMD

SSH username@IP addressCopy the code

If the server is updated for the first time, the following programs are basically installed using the Yum source:

yum update -y
Copy the code

Yum command

Yum install package yum install package yum install package yum install package yum install package yum install package yum install package yum install package yum install package yum install package yum install package yum install package Yum info // list all packages that can be installed or updated Yum search package yum search package yum search package yum search package yum search package Detailed information search to match the specific characters of package / / 4 remove programs yum remove | erase package / / delete the package package yum deplist package / / viewer / / 5 package depends on situation Yum clean packages yum clean headers yum clean headers yum clean oldheaders yum clean oldheaders clear the oldheaders in the cache directory yum clean, yum clean all // (= yum clean packages; Yum clean oldheaders) clears packages and oldheaders in the cache directoryCopy the code

Git installed

Install Git on the server. The way to upload the source code to the server can use the traditional SCP or FTP way, but here the use of Git flow to manage, in the server to perform Git operations;

2.1. Check whether Git is installed

The RPM - qa | grep git or git - version or yum info gitCopy the code

If it has been installed, uninstall it. Run the RPM -e –nodeps git or RPM -e git command to uninstall git

2.2 install Git

yum install git

Type y and press Enter

To userpm -qa|grep gitTo orgit versionCheck to see if Git is installed.

2.3 clone the remote project to the server

The Node installation

Choose one of the following methods to deploy the Node.js environment.

3.1. Install using binary files

The installation package used for this deployment process is a compiled binary file. After decompression, node and NPM already exist in the bin folder. You do not need to compile again. Complete the following operations to deploy the Node.js environment using binary files: Download the Node.js installation package

Wget nodejs.org/dist/v6.9.5…

Unzip the files

The tar XVF node - v6.9.5 - Linux - x64. Tar. XzCopy the code

By creating soft links, you can directly use 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/npmCopy the code

View the node and NPM versions

node -v
npm -v
Copy the code

At this point, the Node.js environment is installed. The software is installed in the /root/node-v6.9.5-linux-x64/ directory by default

To install the software in another directory, for example, /opt/node/, perform the following operations:

Mkdir -p /opt/node/ mv /root/node-v6.9.5-linux-x64/* /opt/node/ rm -f /usr/local/bin/node rm -f /usr/local/bin/npm ln -s  /opt/node/bin/node /usr/local/bin/node ln -s /opt/node/bin/npm /usr/local/bin/npmCopy the code

3.2. Manage multiple versions using NVM (yum install)

The Node Version Manager (NVM) is the Version management software of Node.js, enabling you to switch between different versions of Node.js easily. It is suitable for long-term node developers or those who need to quickly update node versions or switch node versions

Complete the following steps to install multiple Node.js versions using NVM:

Use git to clone the source code to your local ~/. NVM directory and check for the latest version

yum install git

git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
Copy the code

Activate the NVM

echo ". ~/.nvm/nvm.sh" >> /etc/profile
source /etc/profile
Copy the code

List all versions of Node.js

nvm list-remote
Copy the code

Install multiple versions of Node.js

NVM install v14.0.0 -g NVM install v14.10.0 -gCopy the code

Run NVM ls to view the installed node.js version. The current version is V7.4.0. The result is as follows

[root@iZXXXXZ .nvm]# nvm ls
      v6.9.5
->    v7.4.0
      system
stable -> 7.4 (-> v7.4.0) (default)
unstable -> 6.9 (-> v6.9.5) (default)
Copy the code

Run NVM use v7.4.0 to switch node.js to v7.4.0. The result is as follows.

[root@iZXXXXZ .nvm]# nvm use v7.4.0
Now using node v7.4.0
Copy the code

Nginx deployment

Server installation;

Sudo yum install -y nginx Nginx -t service nginx start service nginx stop service nginx restart # config: Nginx. conf installation directory # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid Log file in var/log/nginxCopy the code

Pm2 installation

Installation in the project, CD into the project;

npm i pm2 -g
Copy the code

Start the project

Pm2 start app // The actual execution file is index.js under app projectCopy the code

Pm2 common commands:

Pm2 start app.js --watch I 2 // Make the most use of resources according to the number of CPU cores on the machine pm2 start app -i Max // Check running processes pm2 ls // Stop pm2 stop app pm2 stop all // Restart pm2 restart appCopy the code

We can also create a process.yml configuration file in the project

apps:
  - script : app.js
    intance : 2
    watch : true
    env : 
      NODE_ENV : production
Copy the code

Then perform

pm2 start process.yml
Copy the code

Mongo installation

Installation within the project; Install using Yum source;

Configure the system yum source

D /mongodb-org-4.4.repo Add the following information:

[mongo - org - 4.4] name = directing a Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck = 1 enabled = 1 Baseurl gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc name # name # for download path gpkcheck = 1 # said to calibrate the RPM package downloaded from the source; Enable =1 # enables the source. Gpgkey # GPG validationCopy the code

MongoDB configuration address:

Docs.mongodb.com/manual/tuto…

Save and exit: :wq Exit do not save :wq!Copy the code

Install the mongo

sudo yum install -y mongodb-org
Copy the code

validation

rpm -qa |grep mongodb

rpm -ql mongodb-org-server
Copy the code

The running results are shown as follows:

Start MongoDB (common commands)

// start MongoDB sudo service mongod start or systemctl start mongod Mongod restart # restart mongo / / close the mongo sudo service mongod stop # close the firewall / / uninstall mongo sudo yum erase $(RPM - qa | grep -r /var/log/mongodb -r /var/lib/mongo -r /var/lib/mongo -r /var/log/mongodb -r /var/lib/mongoCopy the code

Remotely connect to Mongodb

Change the default binding IP address 127.0.0.1 to allow only local connections, so change the binding IP address to bindIp:0.0.0.0 and exit the save mode. 1.

// network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.Copy the code

Restart the mongo

sudo service mongod restart 
Copy the code

Open external ports and disable the firewall

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
Copy the code

The remote connection

// Start the MongoDB service. The following information is the public IP address of the server + default port 27017 mongo 10.128.218.14:27017Copy the code

1.0 Create a user and set the account, password, and permission

Admin > use admin switched to db admin > db.createUser({user:"root", PWD :"123456", roles:["root"] }) Successfully added user: { "user" : "root", "roles" : > use test switched to DB test > db.createUser({user:"admin", PWD :"123456", roles:["readWrite", "dbAdmin"] }) Successfully added user: { "user" : "root", "roles" : [ "root" ] }Copy the code

2.0 Modify the mongodb. Conf file to enable authentication

vi /etc/mongod.conf

security:
  authorization: "enabled"   # disable or enabled
Copy the code

3.0 restart the mongo

sudo service mongod restart 
Copy the code

4.0 User Authentication

> use admin switched to db admin > db.auth("root", "123456") 1 // Authorization succeeded // Other common commands db.updateUser(user, DropUser ('test') # delete user dbCopy the code

5.0 Remote Connection

/ / terminal connected mongo 10.128.218.14:27017 / database -u username -p password / / mongoose mode connection (project) Mongoose. Connect (' mongo: / / admin: 123456 @10.128.218.14:27017 / test? options... ', {useNewUrlParser: true}); Username: password @ domain name or server public IP address: port/database name? Configuration itemsCopy the code

MongoDB:

1.0 Administrator Open CMD.

2.0 Access the local MongoDB installation directory CD C:\Program Files\MongoDB\Server\4.4

3.0 Run the net start mongodb command

Other commands

1. The port is occupied: Check the port occupation command. According to the error message, I check port 4000 here:

lsof -i:4000
Copy the code

Kill the current process

kill 2805
Copy the code

In the implementation

npm run dev
Copy the code

Ok!! Check the memory usage of each program on the server

du -h --max-depth=1
Copy the code

Linux shell script

Write the service to run the script, directly run on the server, the following is the running instructions, the script content is not shown here, you can supplement the relevant knowledge of Xshell script.

Sh // Start the service script. Sh // Start the service script. Netstat -nltp // Current server port status;Copy the code